首页 > Web开发 > 详细

asp.net core 中的认证方式(Authentication Scheme)

时间:2020-07-05 09:05:22      阅读:188      评论:0      收藏:0      [点我收藏+]

https://docs.microsoft.com/en-us/aspnet/core/security/authorization/limitingidentitybyscheme?view=aspnetcore-3.1

在 SPA 中有时候会同时使用多种认证方式。比如,使用基于 cookie 的认证方式来登录,并且对 javascript 请求使用 jwt bearer 认证。也可能有多个认证 handler. 比如用2个 cookie handlers. 1个包含基本的 identity, 而另一个用于启用了多因素认证的情况。

注册方式为在 Startup 的 ConfigureServices() 中,使用 services.AddAuthentication() 方法。

用 Authorize attribute 标注可以选择使用哪种 scheme.

也可以将 authentication scheme 注册到 policy 里面,然后在 Authorize attribute 中注明选择哪个 policy.

可以 override 默认的 authorization policy, 通过 services.AddAuthorization() 方法。
如果 override 了,那么在 controller 上就可以简单的使用 [Authorize] 来标注接受来自带有任一个 authentication scheme 颁发的 token 的请求。

asp.net core 中的认证方式(Authentication Scheme)

原文:https://www.cnblogs.com/new-start/p/13237500.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!