Identityserver4 “失踪”;澳元;访问令牌中的声明
由于未知的原因,访问令牌中不存在“aud”声明(尽管它存在于id令牌中) 一旦将访问令牌发送到API,我会收到以下错误: 持票人未经身份验证。失败消息:IDX10214:观众 验证失败。观众:“空的”。不匹配: validationParameters.ValidAudience:“productconfigurationapi”或 validationParameters.Validudiences:“null” 我知道我可以关闭受众验证,然后一切正常,但我不明白为什么“aud”不是访问令牌的一部分 以下是我的IS4配置: 客户:Identityserver4 “失踪”;澳元;访问令牌中的声明,identityserver4,Identityserver4,由于未知的原因,访问令牌中不存在“aud”声明(尽管它存在于id令牌中) 一旦将访问令牌发送到API,我会收到以下错误: 持票人未经身份验证。失败消息:IDX10214:观众 验证失败。观众:“空的”。不匹配: validationParameters.ValidAudience:“productconfigurationapi”或 validationParameters.Validudiences:“null” 我知道我可以关闭受众验证,然后一切正常,但我不明白为什么“aud”不是访问令牌的
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")
};
返回新列表
{
新的ApiScope(“productconfigurationapi”)
};
以下是IS4在其主机应用程序中的配置方式:
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddConfigurationStore(options =>
{
})
.AddOperationalStore(options =>
{
})
.AddAspNetIdentity<IdentityUser>()
.AddJwtBearerClientAuthentication();
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddConfigurationStore(选项=>
{
})
.addStore(选项=>
{
})
.AddAsNetIdentity()
.AddJwtBearerClientAuthentication();
您应该通过设置Scopes属性将ApiScope绑定到ApiResource:
var api = new ApiResource("productconfigurationapi")
{
UserClaims =
{
JwtClaimTypes.Audience
},
Scopes = new List<string>
{
"productconfigurationapi"
},
};
var-api=新的ApiResource(“productconfigurationapi”)
{
用户声明=
{
JwtClaimTypes.观众
},
范围=新列表
{
“productconfigurationapi”
},
};
看起来像是添加了JwtClaimTypes。受众
UserClaim显式过度。为客户端和ApiResource分配一个作用域就足够了。是的,这不是必需的