.net 核心客户端未使用 IdentityServer v3 进行身份验证 - 观众中的偏移量
.net core Client doesn't authenticate with IdentityServer v3 - Offset in Audience
给定:
IdentityServer v3
JavaSCript 客户端
Asp 核心 Api 客户端
JavaScript 客户端通过身份服务器进行身份验证,并使用不记名令牌向 api
发出请求
api 配置为使用资源所有者工作流
问题:
现在我得到:
Audiences: 'http://localhost/identity/resources'. Did not match:
validationParameters.ValidAudience: 'MyApi' or
validationParameters.ValidAudiences: 'null'
显然 Audiance 不匹配。
我错过了什么?
配置
Api身份服务器中的客户端:
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
给定:
IdentityServer v3 JavaSCript 客户端 Asp 核心 Api 客户端
JavaScript 客户端通过身份服务器进行身份验证,并使用不记名令牌向 api
发出请求api 配置为使用资源所有者工作流
问题: 现在我得到:
Audiences: 'http://localhost/identity/resources'. Did not match: validationParameters.ValidAudience: 'MyApi' or validationParameters.ValidAudiences: 'null'
显然 Audiance 不匹配。 我错过了什么?
配置
Api身份服务器中的客户端:
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