question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get custom claims included in JWT

See original GitHub issue

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",
    ...
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
meyerscoltoncommented, Jul 14, 2022

@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.

1reaction
dantheothercommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON Web Token Claims - Auth0
You can define your own custom claims which you control and you can add them to a token using Actions. Here are some...
Read more >
JWT How to add custom claims and decode claims
Another way to get claims will be something similar. var prinicpal = (ClaimsPrincipal)Thread.CurrentPrincipal; var email = prinicpal.Claims.
Read more >
Add and Validate Custom Claims in JWT - Apps Developer Blog
Custom claims are custom key-value pairs that you can add to the body of JWT. It can be a user Role or a...
Read more >
How to add custom claims to Jwt Token in OpenIdConnect
How to add custom claims to Jwt Token in OpenIdConnect · OnTokenValidated = async ctx => · { · //Get user's immutable object...
Read more >
Best Practices for Implementing Claims Succesfully | Curity
Once the custom claims issuing is complete, the main API endpoints will receive a useful JWT access token. On every request, the API...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found