【问题标题】:Securing API using Identity Server 3 with token created by identity server 4使用身份服务器 3 和身份服务器 4 创建的令牌保护 API
【发布时间】:2020-10-08 17:30:18
【问题描述】:

我正在使用 Identity Server 4 来验证客户端并生成令牌。该网站是在 Angular 中使用 .Net 核心创建的,但已经开发的 API 仍然在不支持 Identity Server 4 的 .NET 框架 4.7.1 中。

所以为了保护 API,我为 API 配置了支持 .NET 框架 4.7.1 的 Identity Server 3,但问题是它没有验证 Identity Server 4 生成的令牌。

app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                Authority = "http://localhost:5000",
                AuthenticationType = "Bearer",
                RequiredScopes = new[] { "api_to_be_protected" }
            });

有什么方法可以验证令牌并保护 API 免受未经授权的未知客户端的影响,并验证 Identity Server 4 创建的令牌

【问题讨论】:

    标签: c# identityserver4 identityserver3


    【解决方案1】:

    在您的身份服务器上,您应该将 EmitLegacyResourceAudienceClaim 选项设置为 true

    var identityServerBuilder = services.AddIdentityServer(opt =>
                {
                    opt.EmitLegacyResourceAudienceClaim = true;
                });
    

    可以在此处找到有关此属性的更多信息:https://identityserver4.readthedocs.io/en/latest/reference/options.html

    我还发现 nuget 包 IdentityServer3.Contrib.AccessTokenValidation 有一个最近更新以支持 IDSrv 4,我建议您使用它而不是 IdentityServer3.AccessTokenValidation

    【讨论】:

      猜你喜欢
      • 2017-04-07
      • 1970-01-01
      • 1970-01-01
      • 2020-11-17
      • 2017-07-26
      • 2021-10-01
      • 1970-01-01
      • 2021-06-23
      • 1970-01-01
      相关资源
      最近更新 更多