背景:
我一直在使用Identity-Sample
微软团队提供的项目here http://www.asp.net/identity/overview/features-api/two-factor-authentication-using-sms-and-email-with-aspnet-identity#SMS:
我已经集成了Identity-Sample
项目和预发布 nuget 打包到现有项目中,该项目之前使用的是 Identity 的最新稳定版本。
Problem:
尝试 2FA 时,在Account/SendCode
方法,有一个调用GetVerifiedUserIdAsync()
,这是Microsoft.AspNet.Identity.Owin.SignInManager
班级。 (参见完整代码在这里 https://github.com/hylander0/MasterKeyAuthentication/blob/master/MasterKey/Identity/SignInHelper.cs#L59)
GetVerifiedUserIdAsync()
返回 null(即它无法找到经过验证的用户,即使我已经使用 1 个因素登录。)我相信它没有找到正确的cookie。
当我运行Identity-Sample
应用程序,我的浏览器显示_RequestVerificationToken
AND TwoFactorCookie
一切正常。
当我运行自己的应用程序时,我的浏览器仅显示_RequestVerificationToken
饼干和我得到null
.
问题:(如果是 cookie 的问题)
我怎样才能让我的应用程序正确设置 cookieSignInManager.PasswordSignInAsync(...)
方法被调用(内部Account/Login
)?
在 Startup.Auth 类中注册 cookie
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
在登录页面发布操作中,如果您使用新的 SigninManager.PasswordSigninAsync,如果用户启用了 2 FA,它将设置间歇性 cookie,并返回 SignInStatus.RequiresVerification。然后您可以使用 SigninManager.GetVerifiedUserAsync 应该返回用户 ID
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)