【发布时间】:2020-11-05 20:53:00
【问题描述】:
由于未知原因,访问令牌中不存在“aud”声明(但它存在于 id 令牌中)。
将访问令牌发送到 API 后,我收到以下错误:
承载未通过身份验证。失败消息:IDX10214:Audience 验证失败。观众:“空”。不匹配: validationParameters.ValidAudience: 'productconfigurationapi' 或 validationParameters.ValidAudiences: 'null'。
我知道我可以关闭观众验证,然后一切正常,但我不明白为什么“aud”不是访问令牌的一部分。
这是我的 IS4 配置:
客户:
new Client
{
ClientId = "Spa",
AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true,
AlwaysSendClientClaims = true,
AlwaysIncludeUserClaimsInIdToken = true,
AccessTokenType = AccessTokenType.Jwt,
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"productconfigurationapi"
},
RequireConsent = false
}
api 资源:
new ApiResource("productconfigurationapi")
{
UserClaims =
{
JwtClaimTypes.Audience
}
}
API 范围:
return new List<ApiScope>
{
new ApiScope("productconfigurationapi")
};
下面是 IS4 在其宿主应用程序中的配置方式:
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddConfigurationStore(options =>
{
})
.AddOperationalStore(options =>
{
})
.AddAspNetIdentity<IdentityUser>()
.AddJwtBearerClientAuthentication();
【问题讨论】:
标签: identityserver4