如何解决除了默认方案
我的应用程序中有2种身份验证方法。 1对AD进行身份验证,1对常规登录。两种身份验证方法都使用Cookie。
AD身份验证是默认方案,为此,我使用CookieAuthenticationDefaults.AuthenticationScheme。 第二种cookie身份验证方案我称为externalLoginScheme。
services.AddAuthentication(options=> {
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie("externalLoginScheme")
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme,options =>
{
...
})
.AddOpenIdConnect(options =>
{
...
})
每当我尝试对我的名为externalLoginScheme的方案进行signinasync()时,它都不会进行身份验证。
public async Task<IActionResult> Login()
{
var identity = new ClaimsIdentity("externalLoginScheme",ClaimTypes.Name,ClaimTypes.Role);
identity.AddClaim(new Claim(ClaimTypes.Name,"superAdmin"));
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier,"superAdmin"));
identity.AddClaim(new Claim(ClaimTypes.Role,"User"));
var principal = new ClaimsPrincipal(identity);
var authProperties = new AuthenticationProperties{
AllowRefresh = true,ExpiresUtc = DateTimeOffset.Now.AddDays(1),IsPersistent = true,};
await HttpContext.SignInAsync(
"externalLoginScheme",new ClaimsPrincipal(principal),authProperties
);
return RedirectToAction("");
}
IsAuthenticated始终为假。
public async Task<IActionResult> Index()
{
var test = this.HttpContext.User.Identity.IsAuthenticated;
return View();
}
但是,如果我将我的externalLoginScheme设置为默认方案,则验证有效。
services.AddAuthentication(options=> {
options.DefaultScheme = "externalLoginScheme";
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie("externalLoginScheme")
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme,options =>
{
...
})
.AddOpenIdConnect(options =>
{
...
})
如何在不使用身份验证方案作为默认方案的情况下使此sighninasync()工作?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。