Auth0 Home Blog Docs

How to add custom claim to token issued via Authorization Code Flow

I have a rule which hits my database and adds a custom claim for ‘https://mycompany.com/user_uid’ set to the user’s uid. When I authenticate via SSO (ADFS), and then verify the token, it does not include the custom claim.

I need to get the user_uid from the access token in order for our api servers to be able to properly identify users.

I can get the access token from …/oauth/token endpoint. How do I insert a custom claim into this token?

Thank you!

1 Like

Solved it!

Inside my rule, I was doing:

context.idToken[namespace + 'user_uid'] = <some uid>

To fix it, simply:

context.idToken[namespace + 'user_uid'] = <some uid>
context.accessToken[namespace + 'user_uid'] = <some uid>
1 Like

Fantastic! Thanks for sharing the solution for it @k-koehler!

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