jwt - 承载未通过身份验证 : Signature validation failed

标签 jwt access-token identityserver4 thinktecture-ident-server

我正在使用 Identity Server 4 来保护由 angular 应用程序访问的 API(隐式流模式)。一切正常,但是在特定时期,访问 token 甚至在其到期之前突然变得无效。

配置:

这是身份服务器启动文件:

 var identityBuilder = services.AddIdentityServer().AddInMemoryStores().SetTemporarySigningCredential();

 identityBuilder.AddInMemoryScopes(identitySrvConfig.GetScopes());
 identityBuilder.AddInMemoryClients(identitySrvConfig.GetClients());

保护 API:
   app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
        {
            Authority = identityOptions.Authority,
            ScopeName = "userProfile_api",


            RequireHttpsMetadata = false
        });

调查:

问题是持票人未经过身份验证
Bearer was not authenticated. Failure message: IDX10501: Signature validation failed. Unable to match 'kid': 'e4f3534e5afd70ba74c245fe2e39c724', token

经过一些调查,似乎身份服务器正在生成导致签名验证失败的新 key 。

enter image description here

在日志中,我可以看到最后两个警告事件何时发生,然后我看到“存储库不包含可行的默认 key ”和“应将新 key 添加到环中”

问题

即使我使用临时签名 (SetTemporarySigningCredential) 并且我没有重新启动服务器,当 key 生命周期接近 3 个月时,为什么在任何时候都没有 key ?
Creating key {a2fffa4a-345b-4f3b-bae7-454d567a1aee} with creation date 2017-03-03 19:15:28Z, activation date 2017-03-03 19:15:28Z, and expiration date 2017-06-01 19:15:28Z. 

我该如何解决这个问题?

最佳答案

创建自签名证书并删除身份服务器上的临时签名解决了该问题。

var signingCertificate = new X509Certificate2("ReplaceByCertificatePath, "ReplaceByPasswordCertificate");
var identityBuilder = services.AddIdentityServer().AddInMemoryStores().SetSigningCredential(signingCertificate);

identityBuilder.AddInMemoryScopes(IdentitySrvConfig.GetScopes());
identityBuilder.AddInMemoryClients(IdentitySrvConfig.GetClients());

关于jwt - 承载未通过身份验证 : Signature validation failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42588203/

相关文章:

flask - 使用其危险签名注销或结束 session

c# - 我的 IUserClaimsPrincipalFactory 实现导致 IdentityServer4 上出现 StackOverflowException

flutter - Jwt Flutter认证流程

c# - DotNetOpenAuth2 中的单个 AuthZ/AuthN 端点

docker - Mercure Docker 由于忽略 docker-compose 中的 JWT_KEY 而导致 JWT 签名无效

bitbucket - 为什么个人访问 token 不适用于 Bitbucket REST API?

docker - ASP.NET Core Web API 客户端不信任 Identity Server 实例使用的自签名证书

oauth-2.0 - IdentityServer4 JWT 范围作为空格分隔的字符串而不是数组?

node.js - 从多页面应用程序进行身份验证后,如何在初始下载期间将 JWT token 加载到 React?

node.js - 如何使 passportjs google login oauth 与 JWT 一起工作,而不是通过序列化/反序列化方法创建 session ?