签名验证失败。没有提供安全密钥来验证签名

时间:2019-05-17 06:31:11

标签: c# asp.net-core jwt identityserver4 asp.net-core-webapi

我配置了IdentityServer4,并尝试使用jwt令牌保护Web API。在这里,当我使用令牌调用api时,会得到

  

IDX10500:签名验证失败。没有提供用于验证签名的安全密钥。

Web API我已经按照以下方式注册了服务

services
.AddAuthentication("Bearer")
.AddIdentityServerAuthentication(options =>
{
    options.Authority = Environment.GetEnvironmentVariable("https://localhost:44394/");
    options.RequireHttpsMetadata = false;
    options.ApiName = "api1";
});

这是详细日志

  

Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler:信息:无法验证令牌。

     

Microsoft.IdentityModel.Tokens.SecurityTokenInvalidSignatureException:IDX10500:签名验证失败。没有提供安全密钥来验证签名。      在System.IdentityModel。令牌s。      在System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateToken(字符串令牌,TokenValidationParametersvalidationParameters,SecurityToken&validatedToken)      在Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()   Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler:信息:BearerIdentityServerAuthenticationJwt未通过身份验证。失败消息:IDX10500:签名验证失败。没有提供用于验证签名的安全密钥。

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

问题是您没有设置权限。调试时,您会看到Environment.GetEnvironmentVariable("https://localhost:44394/")实际上为空。

为了解决此问题,请使用有效变量替换它,或使用其他来源。

相关问题