【问题标题】:Authorize Attribute to handle valid user in Docker授权属性在 Docker 中处理有效用户
【发布时间】:2021-09-30 15:12:09
【问题描述】:

我正在 Linux 容器中的 Docker 中运行我的 .net core 5 应用程序,即 Authentication ServerAPI GatewayAPI GateWay 中的控制器类包含一个[Authorize] 属性来验证用户。尽管用户是有效的(例如注册和登录成功),API Gate 无法允许用户访问 API。这是我日志中抱怨的一部分:

Failed to validate the token.Microsoft.IdentityModel.Tokens.SecurityTokenSignatureKeyNotFoundException: IDX10501: Signature validation failed. Unable to match key:
kid: '6B7ACC520305BFDB4F7252DAEB2177CC091FAAE1'.
Exceptions caught:''.

我说得对吗,是因为身份服务 4 生成的 cookie 吗? idsrv.session.netcore related cookies 共享失败。

这是因为根据我的观察,当我的微服务在 IIS 中运行时。当用户成功登录时,身份验证服务器将生成两个提到的 cookie。并且提到的 cookie 在其他微服务之间“共享”,部分原因是它们位于相同的 localhost 但端口号不同。

当我的应用程序迁移到 Docker 时; Authentication Server 能够生成相关的 cookie,其余的 contains 获取 cookie 失败。

结果,我猜,这就是 API Gateway 无法授权有效用户的结果。

因此,我想知道我对授权的理解是否正确以及我应该如何解决有效用户的问题。

【问题讨论】:

标签: docker .net-core asp.net-identity identityserver4


【解决方案1】:

https://stackoverflow.com/a/58877655/3312570 错误代码IDX10501 指向不正确的不记名令牌中间件。

尝试添加 cookie。使用下面的代码。我的猜测,它不会有帮助。

services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-12
    • 1970-01-01
    • 1970-01-01
    • 2011-10-24
    • 2019-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多