asp.net - Asp Core 2.0 和 Identity Server v3,受众验证失败

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

给定:

  • IdentityServer v3
  • 使用 aspcore 2.0 的客户端 Web 应用程序

场景:

将 aspcore 1.1 与 Identity Server v3 结合使用时,我需要设置 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: Unable to validate audience. validationParameters.ValidAudience is null or whitespace and validationParameters.ValidAudiences is null.

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

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

我是否缺少 aspcore api 的某些内容,或者是否有任何提示如何修复此差距?

最佳答案

您还可以使用 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
            });

关于asp.net - Asp Core 2.0 和 Identity Server v3,受众验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46037526/

相关文章:

c# - 将 mm/dd/yyyy 转换为 JsonDate 格式

c# - 如何在 ASP.NET Core 中以编程方式检查用户是否处于某个角色?

c# - ASP.NET Core - 在 Visual Studio 2015 中通过 Docker 调试时出现问题

javascript - 日期变量没有方法 addDays

c# - 值来自 C# 到 Javascript 的形式

asp.net - 如何将编辑按钮移动到 DetailsView 的顶部?

IdentityServer3-自定义登录和注册屏幕

vue.js - 如何修复 block 加载失败?

Sitecore 9 联合身份验证与 IdentityServer3,无限循环

owin - IdentityServer4 和 Web API .NET 4.6.2