api.accessToken.setCustomClaim() in a post-login Action. However, in an anonymous sessions context, there is no login, and therefore no post-login Action execution. This removes the opportunity to add custom claims to the access token the usual way, leaving APIs that expect those claims unable to read them.
To solve this, Auth0 provides claims mapping, which is a direct translation between an anonymous session’s metadata and the access tokens issued for it. For example, given a session that contains:
language value from every new anonymous access token it creates and include it as a custom claim called lang.
Configure claims mapping
To configure claims mapping for anonymous sessions, you can use the Auth0 Dashboard or the Management API.- Auth0 Dashboard
- Management API
- Navigate to Dashboard > Applications > APIs, and select the API you want to configure the claims for.
-
Select the Claim Mapping tab.
-
Under Add a claim, enter a claim Name (for example,
lang) and an Expression referencing a value underanonymous_session.metadata.*(for example,anonymous_session.metadata.language), then select Add. - To edit an existing claim, select the pencil icon next to it. To delete one, select the trash can icon.
Next steps
Anonymous Sessions Use Cases
Learn about anonymous sessions use cases.