# Saving custom claims to app\_metadata

**URL:** <https://community.auth0.com/t/saving-custom-claims-to-app-metadata/81066>\
**Category:** Get Help\
**Tags:** app\_metadata, actions, rules, oidc, login\
**Created:** [April 4, 2022, 2:16pm UTC](https://community.auth0.com/t/saving-custom-claims-to-app-metadata/81066 "2022-04-04T14:16:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![borja.roux](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/borja.roux/32/33355_2.png) [@borja.roux](https://community.auth0.com/u/borja.roux)\
**Post date:** [April 4, 2022, 2:16pm UTC](https://community.auth0.com/t/saving-custom-claims-to-app-metadata/81066/1 "2022-04-04T14:16:56Z")

</div>

I have created an enterprise connection to allow users to authenticate on a third-party OIDC IDP. This IDP generates identity tokens with custom claims. I need to store those claims in the user’s app\_metadata at each login. It should be easy, shouldn’t it?

My first option was to enable automated synchronization. According to [this](https://auth0.com/docs/manage-users/user-accounts/user-profiles/configure-connection-sync-with-auth0) document, the automated synchronization can only be done on " user profile attributes", not on app\_metadata attributes.

My second option was to create an action to update the app\_metadata, but in an action I cannot access the idToken information coming from the third party Identity Provider in either the [event](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow/event-object) or [API](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow/api-object) objects. I have tried `api.idToken["https://namespace/claim"]`, but this returns null. I assume this is because this object is to set custom claims, not to get them.

My third option was to create a rule to retrieve the custom claims from the third-party IDP identity token, and store them in the app\_metadata. I thought this should be possible based on [this](https://community.auth0.com/t/how-can-i-access-custom-user-properties-in-my-custom-action/75540/10) reply (which talks about a similar use case for third-party SAML assertions). In this case I am unable to find any suitable attribute to get the information in the third-party identity token neither in the [user](https://auth0.com/docs/customize/rules/user-object-in-rules) object, nor in the [context](https://auth0.com/docs/customize/rules/context-object) one. The references to context.idToken[“[https://namespace/claim](https://namespace/claim)”] return null.

It is difficult for me to accept there is no way to store information from custom identity token claims into app\_metadata when the user logs in.

What am I missing?

---

<div class="post-metadata">

**Author:** ![borja.roux](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/borja.roux/32/33355_2.png) [@borja.roux](https://community.auth0.com/u/borja.roux)\
**Post date:** [April 4, 2022, 5:15pm UTC](https://community.auth0.com/t/saving-custom-claims-to-app-metadata/81066/2 "2022-04-04T17:15:57Z")

</div>

I have found a big mistake in my question, a confirmation, and a solution.

The big mistake is stating the information from the third-party IDP is not saved. It is saved in the user profile (out of the metadata fields). It can be seen in the “Identity Provider Attributes” section of the user details, as well as in the “Raw JSON” section.

I have been able to confirm that this information cannot be retrieved via actions via `event.user.["https://namespace/claim"]`

It can however be used in rules via `user.["https://namespace/claim"]`

The solution is to use rules instead of actions (in this case, while actions do not enable this functionality).

PS: in case you find it strange that the IDP claims are stored replacing dots with colons (just like me), check [this thread](https://community.auth0.com/t/namespaced-claim-replaces-period-with-colon/59773/2).

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 4, 2022, 7:09pm UTC](https://community.auth0.com/t/saving-custom-claims-to-app-metadata/81066/3 "2022-04-04T19:09:38Z")

</div>

Thanks for providing an update!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [November 4, 2022, 2:40pm UTC](https://community.auth0.com/t/saving-custom-claims-to-app-metadata/81066/4 "2022-11-04T14:40:19Z")

</div>


