Cooxkie Cooxkie - 8 months ago 594
C# Question

How to decode JWT Token?

I don't understand how this library works. Could you help me please ?

Here is my simple code :

public void TestJwtSecurityTokenHandler()
var stream =
var handler = new JwtSecurityTokenHandler();

var jsonToken = handler.ReadToken(stream);

This is error :

The string needs to be in compact JSON format, which is of the form: Base64UrlEncodedHeader.Base64UrlEndcodedPayload.OPTIONAL,Base64UrlEncodedSignature'.

If you copy stream in website, it works fine :)

Thanks in advance for your help !


I found solution, I just missed to Cast result as follow :

var tokenS = handler.ReadToken(tokenJwtReponse.access_token) as JwtSecurityToken;

After I can get Claims like :

 var jti = tokenS.Claims.First(claim => claim.Type == "jti").Value;