我有一个使用 IdentityServer3 来发布 token 的身份服务器。
我正在创建一个 asp.net core 2.0 api 客户端。
如何在 ASP.Net Core 2.0 api 应用程序中验证 Identityserver3 发出的 token ?
我尝试安装 Identityserver3.AccessTokenValidation.AspNetCore,但收到错误说它与核心不兼容。
任何人都可以帮助我如何做到这一点?
谢谢
最佳答案
与 .Net Core 2
您可以使用 IdentityServer4.AccessTokenValidation
要验证 IdentityServer3 token ,只需确保在 ConfigureServices
中添加这一行方法
options.LegacyAudienceValidation = true;
ConfigureServices
应该是这样的:public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore(options =>
{
// IS3 does not include the api name/audience - hence the extra scope check
options.Filters.Add(new AuthorizeFilter(ScopePolicy.Create("api")));
})
.AddAuthorization();
services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
.AddIdentityServerAuthentication(options =>
{
options.Authority = "http://localhost:5002";
options.RequireHttpsMetadata = false;
options.ApiName = "api";
options.ApiSecret = "secret";
// this is only needed because IS3 does not include the API name in the JWT audience list
// so we disable UseIdentityServerAuthentication JWT audience check and rely upon
// scope validation to ensure we're only accepting tokens for the right API
options.LegacyAudienceValidation = true;
});
}
有关更多信息,您可以引用此 link
关于identityserver3 - 如何在 asp.net core 2.0 web api 中使用 identityserver3 来验证来自 Identityserver3 服务器的 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47891185/