How to get custom claims included in JWT
See original GitHub issueI 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:
- Created a year ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
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.