【问题标题】:AspCore 2.0 and IdentityServer v3, Audience Validation FailsAsp Core 2.0 和 Identity Server v3,受众验证失败
【发布时间】:2018-02-12 17:16:30
【问题描述】:

鉴于:

  • IdentityServer v3
  • 带有 aspcore 2.0 的客户端 WebApp

场景:

在使用带有 Identity Server v3 的 aspcore 1.1 时,我需要设置 LegacyAudienceValidation = true(请参阅 .net core Client doesn't authenticate with IdentityServer v3 - Offset in Audience(

现在我迁移到 .net core 2.0。并按照guide 迁移身份还有其他选项,并且在核心 1.0 中

问题: 所以不再有 LegacyAudienceValidation 属性,结果我得到了观众验证错误。

Microsoft.IdentityModel.Tokens.SecurityTokenInvalidAudienceException: IDX10208:无法验证受众。 validationParameters.ValidAudience 为 null 或空格,并且 validationParameters.ValidAudiences 为空。

我的客户端配置代码如下所示

 services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
     .AddJwtBearer(options =>
         {
             options.Authority = Authority;

我是否遗漏了 aspcore api 的内容,或者是否有任何提示如何解决这个差距?

【问题讨论】:

  • 将您的受众设置为您的 API 名称。 options.Audience = "API 名称"

标签: asp.net asp.net-core identityserver3 asp.net-core-2.0 asp.net-authentication


【解决方案1】:

您也可以使用 IdentityServer4.AccessTokenValidation nuget 包,并设置 LegacyAudienceValidation

services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
            .AddIdentityServerAuthentication(options =>
            {
                options.Authority = "identityserver";
                options.ApiName = "yourapi";
                options.LegacyAudienceValidation = true;  // to make core 2.0 work with idsrv3
            });

【讨论】:

  • 我知道这已经晚了,但值得注意的是 IdentityServer4.AccessTokenValidation 包适用于连接到 IdSvr3 实例的客户端。
猜你喜欢
  • 2020-10-20
  • 2015-11-24
  • 2021-10-16
  • 1970-01-01
  • 1970-01-01
  • 2017-12-24
  • 2018-07-23
  • 2019-04-18
  • 2021-12-10
相关资源
最近更新 更多