简体   繁体   English

如何在不使用JWT的情况下从访问令牌中获取用户数据

[英]How to get user data from the access token without JWT

I am getting Access token from the Azure AD Login. 我正在从Azure AD登录中获取访问令牌。 But i don't want to use JWT dll for extract data from the Access Token. 但是我不想使用JWT dll从访问令牌中提取数据。 So i need a alternative solution for this. 所以我需要一个替代解决方案。 This is my Sample code in JWT 这是我在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; 使用的dll:使用System.IdentityModel.Tokens.Jwt; I don't want this dll for extract data. 我不希望该dll提取数据。 I need another solution without using dll. 我需要不使用dll的另一种解决方案。

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) 无论如何,JWT只是3个以64为基数的编码字符串,以'。'串联在一起(假定其已签名但未加密)。

So: 所以:

var split = jwt.Split('.')
var token = Convert.FromBase64String(split([1]))

the middle bit is the token in json, use newtonsoft to read it 中间位是json中的令牌,请使用newtonsoft进行读取

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM