【问题标题】:Signature validation failed. No security keys were provided to validate the signature签名验证失败。没有提供安全密钥来验证签名
【发布时间】:2019-10-04 10:53:31
【问题描述】:

我配置了 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.Tokens.Jwt.JwtSecurityTokenHandler.ValidateSignature(字符串令牌,TokenValidationParameters 验证参数) 在 System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateToken(字符串令牌,TokenValidationParameters 验证参数,SecurityToken 和验证令牌) 在 Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync() Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler:信息:BearerIdentityServerAuthenticationJwt 未通过身份验证。失败消息:IDX10500:签名验证失败。没有提供用于验证签名的安全密钥。

谁能帮我解决这个问题?

【问题讨论】:

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


    【解决方案1】:

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

    为了解决这个问题,请将其替换为有效变量或使用替代来源。

    【讨论】:

      猜你喜欢
      • 2020-06-23
      • 2018-09-10
      • 2021-12-17
      • 2018-03-15
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 2017-12-31
      • 2020-07-15
      相关资源
      最近更新 更多