Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get custom claims included in JWT #446

Closed
meyerscolton opened this issue Jul 11, 2022 · 5 comments
Closed

How to get custom claims included in JWT #446

meyerscolton opened this issue Jul 11, 2022 · 5 comments
Labels
question Further information is requested

Comments

@meyerscolton
Copy link

I am getting a JWT token that includes a custom field in the payload called name. When I view the results of useAuth(), stored in a variable called auth, I can see the user object which contains the profile object where I would expect the name to be, except the name field is not there. When I decrypt the token stored in auth I can see the name field just fine. Am I supposed to access the name using a different method other than auth.user.profile.name?

An example of how the payload is setup is

{
    "name": "John Doe",
    ...
}
@dantheother
Copy link

dantheother commented Jul 12, 2022

Name is a "well known" oidc claim according to https://github.com/authts/oidc-client-ts/blob/707435fe6c226a3f8a861873a7c27eaa492faa04/src/Claims.ts#L39 - I wonder if that is interfering with things?

Our solution includes a custom tenantGid claim in the identity token (and also the access token) and we're able to retrieve it using (yes, the as any is nasty, extending the UserProfile object officially is on my TODO list)

const tenants = (user?.profile as any)?.tenantGid;

So I know that this library (probably actually oidc-client-ts) can retrieve custom claims from the identity token and put them on the user profile object.

@pamapa pamapa added the question Further information is requested label Jul 14, 2022
@meyerscolton
Copy link
Author

@dantheother thank you for the response. I had been checking the access token this entire time which contained the field, but when I checked the id token I noticed it was missing.

@djohnsonkc
Copy link

Hi, have there been any updates recently that might address auth.user.profile.name not being present even when name is present in the access_token? Thanks!

@dantheother
Copy link

@djohnsonkc profile is populated from the identity token, not the access token. Identity token is for use on the client, access token is for use on the server.

@djohnsonkc
Copy link

Would the user's name be available now somewhere other than in auth.user.profile.name? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants