Identity Server 4.Net Core 2.0:多种身份验证类型
问题描述:
这是关键吗?Identity Server 4.Net Core 2.0:多种身份验证类型
Multiple authenticaiton schemes in asp.net core 2.0
我想有多种类型的身份验证在我.netcore项目。
答
是的,这是可能的。
您需要确保在ConfigureServices中正确设置了认证方案。
services.AddAuthentication()
.AddCookie("MyCookieAuthenticationScheme", options => {
})
.AddAnotherHandler("AnotherName", options => { });
然后为每个控制器/动作,你将需要指定符合条件的计划
例子:
[Authorize(AuthenticationSchemes = "Scheme1")]
public IActionResult Test1() { }
[Authorize(AuthenticationSchemes = "Scheme2")]
public IActionResult Test2() { }
[Authorize(AuthenticationSchemes = "Scheme1,Scheme2")]
public IActionResult Test3() { }
如果需要,您还可以创建自己的验证处理程序。
祝你好运, Seb