© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•16mo ago
Alan G Rutter

JWT, ClaimIdentity and ClaimPrincipal

Hi everyone,
I have a service that creates a JWT using the JsonWebTokenHandler. When I create my claims, I am using
var claims = new List<Claim>
        {
            new(JwtRegisteredClaimNames.Name, userId),
            new("role", userRole)
        };
var claims = new List<Claim>
        {
            new(JwtRegisteredClaimNames.Name, userId),
            new("role", userRole)
        };

I add these to create a ClaimsIdentity and set the authenticationType to a string, set nameType and roleType as per the above. I am now trying to handle the refresh token which requires me to get a ClaimsPrincipal. I validate the token using JsonWebTokenHandler and use the result to instantiate a ClaimsPrincipal using the token Claims. When I inspect the ClaimsPrincipal, the AuthenticationType is set to AuthenticationType.Federated and the two claims contain the long XML schema names. In my JWTBearer options, I have set MapInboundClaims to false.

If I simply use ClaimTypes.Name and ClaimTypes.Role, the claims end up in the token with the long schema names also instead of the short name even though MapInboundClaims is set to false.

Can someone explain how to get a ClaimsPrincipal using the correct authentication type and short claim names.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ jwt audience and issuer
C#CC# / help
3y ago
Jwt
C#CC# / help
10mo ago
Cookies and JWT for Authentication
C#CC# / help
11mo ago
Difference "Login/Register" and JWT Authentication?
C#CC# / help
3y ago