嗨,我正在尝试使用nuget包System.IdentityModel.Tokens.Jwt 4.0.2.206221351版的C#框架4.6.1解码令牌,但是我无法使它正常工作。
对于5.4版,这是我使用的代码:
var token = "";
var key = Encoding.ASCII.GetBytes("Key");
var tokenHandler = new JwtSecurityTokenHandler();
var jwtToken = (JwtSecurityToken)tokenHandler.ReadToken(token);
if (jwtToken == null)
{
return null;
}
IdentityModelEventSource.ShowPII = true; // --> Error Here
var tokenParameters = new TokenValidationParameters()
{
RequireExpirationTime = false,
ValidateIssuer = false,
ValidateAudience = false,
IssuerSigningKey = new SymmetricSecurityKey(key), // --> Error Here
RequireSignedTokens = true
};
SecurityToken securityToken;
var principle = tokenHandler.ValidateToken(token, tokenParameters, out securityToken);
if (principle == null)
{
return null;
}
ClaimsIdentity identity = (ClaimsIdentity)principle.Identity;
错误:
CS0103当前上下文中不存在名称'IdentityModelEventSource'
CS0144无法创建抽象类或接口'SymmetricSecurityKey'的实例
我可能会缺少什么?是另一种方式吗?