根据MSDN
本地登录和社交登录都会检查2FA是否已启用。如果启用了2FA,则SignInManager登录方法将返回SignInStatus.RequiresVerification,并且用户将被重定向到SendCode操作方法,在该方法中,用户必须输入代码才能按顺序完成日志。 如果用户在用户本地cookie上设置了RememberMe,则SignInManager将返回SignInStatus.Success,并且他们不必通过2FA。
我确实希望用户能够使用应用程序的“记住我”功能,但我无法弄清楚如何让cookie放弃此设置,以便SignInStatus返回RequiresVerifacation。我实际上甚至不确定cookie是否导致它。我所知道的是我已启用TFA,在AspUsers表中我可以看到TwoFactorEnabled设置为true但状态始终返回为Success。
这是控制器,我没有得到我想要的东西
[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Login");
}
// Sign in the user with this external login provider if the user already has a login
var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: false);
var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false });
case SignInStatus.Failure:
default:
// If the user does not have an account, then prompt the user to create an account
ViewBag.ReturnUrl = returnUrl;
ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email });
}
}
根据this MSDN page var结果应返回SignInStatus.RequiresVerification,但是当从OAuth登录或从常规登录返回时返回Success。用户在AspUsers表中将其TwoFactorEnabled设置为true结果是根据文档进行检查。