Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read claims in SecurityToken C#

Tags:

c#

jwt

I have a access token from OAuth 2.0 which is encrypted using JwtSecurityTokenHandler.WriteToken(). After i decrypt it using JwtSecurityTokenHandler.ReadToken(), it returns me SecurityToken Object but i do not know how to loop and read the claim inside the decrypted token.

There is ways to read claim in JwtSecurityToken but unfortunately read token returns SecurityToken instead of JwtSecurityToken.

Hope someone could help.

like image 330
eulercode Avatar asked Dec 09 '15 10:12

eulercode


1 Answers

You should be able to cast it as a JwtSecurityToken:

var jwt = jwtSecurityTokenHandler.ReadToken(tokenString) as JwtSecurityToken;
like image 145
Alex Avatar answered Oct 09 '22 11:10

Alex