# Cannot Access Mapped SAML Properties inside Custom Action

**URL:** <https://community.auth0.com/t/cannot-access-mapped-saml-properties-inside-custom-action/63615>\
**Category:** Get Help\
**Tags:** auth0-flows, rules, saml\
**Created:** [May 31, 2021, 10:06pm UTC](https://community.auth0.com/t/cannot-access-mapped-saml-properties-inside-custom-action/63615 "2021-05-31T22:06:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidhouseknechtdev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/davidhouseknechtdev/32/12778_2.png) [@davidhouseknechtdev](https://community.auth0.com/u/davidhouseknechtdev)\
**Post date:** [May 31, 2021, 10:06pm UTC](https://community.auth0.com/t/cannot-access-mapped-saml-properties-inside-custom-action/63615/1 "2021-05-31T22:06:57Z")

</div>

Hello,

I have a SAML connection where Auth0 is the Service Provider for my application. I am trying out the new login flows but am running into a small problem that I’m not sure how to solve.

**What I am trying to do**  
On a successful login from the SAML IdP, I want to update a user’s `app_metadata` with the returned `roles` and `account`.

**What is Happening**  
I cannot seem to get the `roles` field off the user object from the SAML login

**My configuration**  
In my Enterprise SAML connection I have this mapping:

```json
{
  "role": [
    "http://schemas.auth0.com/app:role",
    "http://schemas.auth0.com/role"
  ]
}

```

This mapping works because I see `role` show up on my user when I view their raw JSON data in the dashboard. The property is a top level prop like so:

```json
{
    "role": "manager",
    "user_id": "samlp|{connection}|auth0|{id}",
    "app_metadata": {
        "account": "sso-incorporated"
    },
   // lots more fields
}

```

I then created this flow action to run after a successful login:

```plaintext
exports.onExecutePostLogin = async (event, api) => {
  if (event.user.email) {
   // custom function to determine the account name from email address
    const accountName = getAccountNameFromEmail(event.user.email);

    if (accountName) {
      // this works
      api.user.setAppMetadata("account", accountName);
      // this does not. Never saves anything (assuming `event.user['role']` is undefined)
      // I cannot figure out how to access the `role` on my user object from SAML reponse
      api.user.setAppMetadata("role", event.user['role']);
    }
  }
};

```

Is there any way I can access that property? I don’t mind putting my logic in the mapping rules either, but I don’t think it lets me map into `app_metadata` fields. I need the roles in the `app_metadata` because I search users based on that information.

Thanks!

---

<div class="post-metadata">

**Author:** ![sgo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgo/32/13789_2.png) [@sgo](https://community.auth0.com/u/sgo)\
**Post date:** [July 12, 2021, 3:09pm UTC](https://community.auth0.com/t/cannot-access-mapped-saml-properties-inside-custom-action/63615/3 "2021-07-12T15:09:18Z")

</div>

Hi @davidhouseknechtdev ,

Unfortunately I am not aware of a good way to do this within Actions alone currently.

App\_metadata is supposed to only be modified via Rules, Actions, Dashboard or the Management API and not tied to a particular connection, and so it can cause issues if set directly by an external IdP. ([Understand How Metadata Works in User Profiles](https://auth0.com/docs/users/metadata#manage-metadata))

What I would recommend is mapping the claims from your upstream IdP to a custom root profile entry that doesn’t overlap with an Auth0 profile attribute ([User Profile Structure](https://auth0.com/docs/users/user-profile-structure)).

Currently, Actions can only access the attributes that are listed for the relevant trigger’s Event object, e.g the Post Login triggers event object is detailed here:

- [Actions Triggers: post-login - Event Object](https://auth0.com/docs/actions/triggers/post-login/event-object)

Because of this, you would then need a Rule to copy this custom attribute into the user’s app\_metadata so it could be accessed by your Actions:

- [Manage Metadata with Rules](https://auth0.com/docs/users/metadata/manage-metadata-rules#update-metadata)

Sorry for the wait, I hope this is still useful

---

<div class="post-metadata">

**Author:** ![anouk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/anouk/32/12751_2.png) [@anouk](https://community.auth0.com/u/anouk)\
**Post date:** [October 15, 2021, 1:28pm UTC](https://community.auth0.com/t/cannot-access-mapped-saml-properties-inside-custom-action/63615/4 "2021-10-15T13:28:54Z")

</div>

Hello @sgo ,  
Thank you for your answer to David’s problem, I am having the same issue and am currently able to circumvent it using rules instead of actions.  
The problem is, we are receiving notifications from Auth0 advising us to migrate to Actions as Rules are becoming Legacy.  
Do you know if Auth0 is planning to make mapped SAML properties available in actions in the near future? Do we have to keep using rules for this problem only?

Thank you

---

<div class="post-metadata">

**Author:** ![sgo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgo/32/13789_2.png) [@sgo](https://community.auth0.com/u/sgo)\
**Post date:** [October 15, 2021, 2:49pm UTC](https://community.auth0.com/t/cannot-access-mapped-saml-properties-inside-custom-action/63615/5 "2021-10-15T14:49:20Z")

</div>

Hi @anouk, I have mentioned this internally in the past to our Engineering team and after a bit of digging I can see this has been added to the backlog. Unfortunately, I can’t provide any guarantees or ETAs at this time, but this _should_ be possible in Actions without needing Rules in the future.

But until then, or an alternative is provided, you would need to continue using Rules to read extra claims an upstream IdP may provide to your Auth0 tenant.

---

<div class="post-metadata">

**Author:** ![bschreiber](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/bschreiber/32/34341_2.png) [@bschreiber](https://community.auth0.com/u/bschreiber)\
**Post date:** [December 30, 2021, 6:16pm UTC](https://community.auth0.com/t/cannot-access-mapped-saml-properties-inside-custom-action/63615/6 "2021-12-30T18:16:34Z")

</div>

As a workaround, I found that if I load the User object from the Management API, rather than rely on the User object I receive within the Event parameter, I am able to see claims, such as groups, that were added from the SAML token. I hope this helps!

---

<div class="post-metadata">

**Author:** ![sgo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgo/32/13789_2.png) [@sgo](https://community.auth0.com/u/sgo)\
**Post date:** [January 5, 2022, 11:01am UTC](https://community.auth0.com/t/cannot-access-mapped-saml-properties-inside-custom-action/63615/7 "2022-01-05T11:01:07Z")

</div>

Thanks for pointing this out @bschreiber - yes you can fetch the full user object via the Management API too - however, a downside of this is the rate limits on the Management API are more restrictive, so wouldn’t scale well if it were to be called on every login for example.  
You could mitigate this by using conditional logic to only make the call for a first time login though.

> **[Management API Endpoint Rate Limits](https://auth0.com/docs/troubleshoot/customer-support/operational-policies/rate-limit-policy/management-api-endpoint-rate-limits)**
>
> Learn about Auth0's rate limit policy when working with Auth0 Management API endpoints.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 20, 2022, 11:01am UTC](https://community.auth0.com/t/cannot-access-mapped-saml-properties-inside-custom-action/63615/8 "2022-01-20T11:01:26Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
