Identity Server 4 .Net Core 2.0:多种身份验证类型

时间:2017-10-18 04:04:17

标签: oauth asp.net-core identityserver4

这是关键吗?

Multiple authenticaiton schemes in asp.net core 2.0

我想在.netcore项目中使用多种类型的身份验证。

1 个答案:

答案 0 :(得分:0)

是的,这是可能的。

您需要确保在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