【问题标题】:Identity Server 4 .Net Core 2.0: Multiple authentication typeIdentity Server 4 .Net Core 2.0:多种身份验证类型
【发布时间】:2018-03-29 21:09:04
【问题描述】:

这是正确的吗?

Multiple authenticaiton schemes in asp.net core 2.0

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

【问题讨论】:

    标签: oauth asp.net-core identityserver4


    【解决方案1】:

    是的,这是可能的。

    您需要确保在 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() { }
    

    如果需要,您还可以创建自己的身份验证处理程序。

    祝你好运, 赛博

    【讨论】:

      猜你喜欢
      • 2017-06-26
      • 2021-10-18
      • 2018-03-23
      • 2019-08-17
      • 2019-08-04
      • 1970-01-01
      • 2017-09-11
      • 2019-04-18
      • 1970-01-01
      相关资源
      最近更新 更多