Auth0 Home Blog Docs

ASPNET Core WEB API access custom claim

claims
webapi
dotnet-core

#1

Hey,

Let’s say I’m adding a custom claim in a rule that goes something like this.

context.idToken[namespace + ‘UserId’] = result[0].UserId;

How do I then access this claims value in my DOT NET CORE Web API?

Cheers


#2

:wave: @ryrygibbs were you able to access the claims in the end? I believe we can handle custom claim that you added to the token (via your Rule), by configuring the ConfigureServices method in the Startup.cs

OnTokenValidated = context =>
                    {
                        ClaimsIdentity identity = context.Principal.Identity as ClaimsIdentity;

                        var userRoles = identity.FindAll("YOUR_NAMESPACE_FOR_THE_CLAIM"); 
...
                   }
...