.NET Core客户端无法通过IdentityServer v3进行身份验证 - 受众中的偏移量

3

给定:

IdentityServer v3 JavaSCript 客户端 Asp Core Api 客户端

JavaScript 客户端通过身份验证器进行身份验证,并使用令牌向 API 发出请求

API 配置为使用资源所有者工作流程

问题: 现在我得到了以下错误信息:

受众:'http://localhost/identity/resources'。与以下内容不匹配: validationParameters.ValidAudience: 'MyApi' 或 validationParameters.ValidAudiences: 'null'

很明显,受众不匹配。 我错过了什么?

配置

Identity Server 中的 ApiClient:

 return new Client
            {
                Enabled = true,
                ClientId = "MyApi",
                ClientName = "The client for the Groupl Api",
                ClientSecrets = new List<Secret>
                {
                    new Secret("foo".Sha256())
                },
                Flow = Flows.ResourceOwner,
                AllowedScopes = ClientConstants.AllowedGrouplScopes()
            };

在连接身份服务器的 API 中:
 JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();


        var authority = config["identity:authority:url"];
        app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
        {
            Authority = authority,
            RequireHttpsMetadata = false,
            EnableCaching = false,

            ApiName = "myApi", //Correct that this is the client id?
            ApiSecret = "foo"
        });

这里是请求(Access_token已省略)

GET /api/values HTTP/1.1
Host: localhost:59364
Content-Type: application/json
Authorization: Bearer {access_token}

更新

当我设置LegacyAudienceValidation = true时,一切正常工作,但我不确定如何正确处理这个问题。

1个回答

2

原因在于身份验证行为发生了变化。IdentityServer 3不支持多个受众群体,但是Identityserver 4支持。因此,对于旧的处理方式,需要将 LegacyAudienceValidation 设置为 true


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接