我面临以下情况:我有一个ASP.NET核心WebAPI (我正试图保护的API资源)与IdentityServer托管在同一台机器上,并且我的网络之外的客户端通过他们的公共地址(例如:https://myapi.com和https://myidentity.com)与他们进行通信。
我想知道是否可以将API设置为通过本地主机地址(例如: IdentityServer )与http://localhost:5000进行通信,而外部客户端则通过它们的公共地址进行通信?
我尝试修改IdentityServer Authority属性以使用localhost地址:
services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
.AddIdentityServerAuthentication(options =>
{
options.Authority = http://localhost:5000;
options.ApiName = apiName;
});
但是,当API试图验证它从客户端接收到的令牌时,我会得到以下错误:
Bearer error="invalid_token", error_description="The issuer 'https://myidentity.com' is invalid"
这是有意义的,因为令牌是由https://myidentity.com
发出的,我的API的权限设置为http://localhost:5000
。
有什么想法吗?
发布于 2020-04-17 05:42:07
可以将TokenValidationParameters
设置为添加有效的ValidIssuer
,两个令牌颁发者应同时工作:
services.AddAuthentication("Bearer")
.AddJwtBearer("Bearer", options =>
{
options.Authority = "http://localhost:5000";
options.RequireHttpsMetadata = false;
options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = "https://myidentity.com"
};
options.Audience = "api1";
});
https://stackoverflow.com/questions/61258054
复制相似问题