给定:
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
时,一切正常工作,但我不确定如何正确处理这个问题。