如何在ASP.NET Core 2.0 WebAPI中使用IdentityServer3来验证IdentityServer3服务器中的令牌

编程入门 行业动态 更新时间:2024-10-19 04:25:53
本文介绍了如何在ASP.NET Core 2.0 WebAPI中使用IdentityServer3来验证IdentityServer3服务器中的令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个使用IdentityServer3发行令牌的身份服务器.

I have a identityserver which is using IdentityServer3 to issue tokens.

我正在创建一个asp core 2.0 api客户端.

I am creating an asp core 2.0 api client.

如何在ASP.Net Core 2.0 API应用程序中验证Identityserver3发行的令牌?

How to validate the token issued by Identityserver3 in ASP.Net Core 2.0 api application?

我尝试安装Identityserver3.AccessTokenValidation.AspNetCore,但是收到错误消息说它与核心不兼容.

I tried to install Identityserver3.AccessTokenValidation.AspNetCore, but getting error saying it is not compatible with core.

有人可以帮我怎么做吗?

Can anyone help me how to do this?

谢谢

推荐答案

使用 .Net Core 2 ,您可以使用 IdentityServer4.AccessTokenValidation 来验证IdentityServer3令牌,只需确保在 ConfigureServices 方法

With .Net Core 2 you can use IdentityServer4.AccessTokenValidation to validate IdentityServer3 token , just make sure to add this line in ConfigureServices method

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 = "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; }); }

有关更多信息,您可以参考此链接

for more information you can refer to this link

更多推荐

如何在ASP.NET Core 2.0 WebAPI中使用IdentityServer3来验证IdentityServer3服务器中的令牌

本文发布于:2023-11-17 02:07:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608418.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:令牌   器中   如何在   NET   ASP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!