给定:
- 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/