如何解决为什么IdentityServer4 ApiResource无法与JwtBearerOption.Audience一起使用?
我在IdentityServer中具有此配置:
public static IEnumerable<ApiResource> ApiResources =>
new ApiResource[]
{
new ApiResource
{
Name = "MyApi"
}
};
以及ASP.NET Core Web API上的jwt配置:
services.AddAuthentication("Bearer")
.AddJwtBearer("Bearer",options =>
{
//identity server
options.Authority = "https://localhost:5001";
//access token recepient
options.Audience = "https://localhost:5001/resources";
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = true,ValidateLifetime = true,};
});
我期望Web API身份验证不会接受来自IdentityServer的令牌,因为Web API JwtBearerOption.Audience不等于“ MyApi”。但是在我的配置中,只有在将受众设置为“ https:// localhost:5001 / resources”的情况下,才对受众进行验证,并且如果将其设置为“ MyApi”,受众将无效。
IdentityServer4 documentation about related to my question.
解决方法
要使MyApi进入受众列表,您需要像在IdentityServer4(v4.0x)中那样定义ApiScope
有关更多详细信息,请参见此articles
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。