Reputation:
I am getting Access token from the Azure AD Login. But i don't want to use JWT dll for extract data from the Access Token. So i need a alternative solution for this. This is my Sample code in JWT
var handler = new JwtSecurityTokenHandler();
JwtSecurityToken tokenS = handler.ReadToken(data.AccessToken) as JwtSecurityToken;
var claims = tokenS.Claims;
var username = claims.FirstOrDefault(s => s.Type == "email").Value;
used dlls: using System.IdentityModel.Tokens.Jwt; I don't want this dll for extract data. I need another solution without using dll.
Upvotes: 0
Views: 827
Reputation: 50210
I will not ask why you dont want to use the library you have for the exact purpose its intended for. Anyway a JWT is just 3 base 64 encoded strings concatenated with '.', (assuming its signed but not encrypted)
So:
var split = jwt.Split('.')
var token = Convert.FromBase64String(split([1]))
the middle bit is the token in json, use newtonsoft to read it
Upvotes: 1