gpt4 book ai didi

asp.net-core - .net core 客户端未使用 IdentityServer v3 进行身份验证 - 受众中的偏移

转载 作者:行者123 更新时间:2023-12-02 03:22:51 29 4
gpt4 key购买 nike

给定:

身份服务器 v3JavaScript 客户端Asp Core Api 客户端

JavaScript 客户端通过身份服务器进行身份验证,并向 api 发出带有不记名 token 的请求

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

问题:现在我得到:

Audiences: 'http://localhost/identity/resources'. Did not match: validationParameters.ValidAudience: 'MyApi' or validationParameters.ValidAudiences: 'null'

显然受众不匹配。我错过了什么?

配置

身份服务器中的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时,一切正常,但我不确定如何正确处理这个问题?

最佳答案

原因是身份验证行为发生了变化。 IdentityServer 3 不支持多个受众。 Identityserver 4 可以。因此,对于旧处理 LegacyAudienceValidation 必须设置为 true

关于asp.net-core - .net core 客户端未使用 IdentityServer v3 进行身份验证 - 受众中的偏移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42670034/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com