【发布时间】:2020-12-07 07:48:09
【问题描述】:
我在 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”,则受众将失效
【问题讨论】:
标签: c# asp.net-core-webapi identityserver4