how to parse or decode jwt token in c#

beginer
beginer
156 Points
48 Posts

Is there any way to parse or decode the bearer token i.e. jwt access token in c#. I want to get all claims in the token.

I don't want to authenticate it but to get claims.

Views: 151
Total Answered: 1
Total Marked As Answer: 1
Posted On: 14-Aug-2020 05:52

Share:   fb twitter linkedin
Answers
sid
sid
46 Points
13 Posts
         

We can use JwtSecurityTokenHandler to parse jwt token:

Namespace: System.IdentityModel.Tokens

var stream ="jwt token";  
var handler = new JwtSecurityTokenHandler();
var token = handler.ReadToken(stream) as JwtSecurityToken;

Now we can get Claims as:

var role = token.Claims.First(claim => claim.Type == "role").Value;
Posted On: 14-Aug-2020 06:18
 Log In to Chat