我正在跟踪异常。 我已经使用post方法使用服务主体获取令牌 消息=“ IDX10708:'System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler'无法读取此字符串
我正在使用““ https://login.microsoftonline.com/ {TenantId} / oauth2 / token”生成访问令牌,并尝试对此进行验证
SecurityToken securityToken;
JwtSecurityTokenHandler handler = new JwtSecurityTokenHandler();
IConfigurationManager<OpenIdConnectConfiguration> configurationManager =
new ConfigurationManager<OpenIdConnectConfiguration>(
$"https://login.microsoftonline.com/{tenantId}/.well-known/openid-configuration",
new OpenIdConnectConfigurationRetriever());
OpenIdConnectConfiguration openIdConfig = await configurationManager.GetConfigurationAsync(CancellationToken.None);
TokenValidationParameters validationParameters = new TokenValidationParameters()
{
ValidateLifetime = true,
IssuerSigningKeys = openIdConfig.SigningKeys,
ValidateIssuerSigningKey = true,
RequireSignedTokens = true
};
var userClaims = handler.ValidateToken(token, validationParameters, out securityToken);
return userClaims.Claims.Where(claim => claim.Type == "appid").FirstOrDefault().Value;
我在验证时遇到异常
答案 0 :(得分:0)
请尝试通过放置try / catch块来验证代码,并在调试器中查看声明值,例如uniquer_name等
您可以按照此线程进行更清晰的说明:-
When is JWTSecurityTokenHandler.ValidateToken() actually valid?
希望有帮助。