ASP.Net Core 3.1-Microsoft登录身份验证和本地SQL身份验证-多种身份验证方案

时间:2020-02-18 07:59:26

标签: c# .net asp.net-core

我有一个网站,我需要在该网站上构建一个登录页面,该页面具有供用户登录的选项,

1. Microsoft Sign-in  (A button which leads to  https://login.microsoftonline.com/common, the user logs-in and comes back to my website)

 2. Locally registered SQL users (A button which leads to user id and password login, this will be local SQL users, cookie authentication ) 

我已在Startup.cs中使用以下身份验证策略来使用双重身份验证

.AddAuthentication().AddPolicyScheme("Dual Authentication", "Cookie or Azure AD", options =>
{
   options.ForwardDefaultSelector = context =>
{
  var authHeader = context.Request.Headers["Authorization"].FirstOrDefault();
    if (authHeader?.StartsWith("Bearer") == true)
    {
     return CookieAuthenticationDefaults.AuthenticationScheme;
    }
     return AzureADDefaults.AuthenticationScheme;
  };
}

但是以这种方式,每次都会执行此检查。

是否有更好的方法可以在3.1中实现相同的双重身份验证?

0 个答案:

没有答案