11

背景:

我一直在这里Identity-Sample使用微软团队提供的项目:

我已将Identity-Sample项目和预发布 nuget 包集成到现有项目中,该项目以前使用最新稳定版本的 Identity。

问题:

尝试 2FA 时,在Account/SendCode方法内部会调用GetVerifiedUserIdAsync() ,这是Microsoft.AspNet.Identity.Owin.SignInManager 类的一部分。(在这里查看完整代码

GetVerifiedUserIdAsync()正在返回 null(即,即使我使用 1 个因素登录,它也找不到经过验证的用户。)我相信它没有找到正确的 cookie。

当我运行该Identity-Sample应用程序时,我的浏览器显示_RequestVerificationTokenAND TwoFactorCookie& 一切正常。

当我运行自己的应用程序时,我的浏览器只显示_RequestVerificationTokencookie 并且我得到了null.

问题:(如果 cookie 是问题)

SignInManager.PasswordSignInAsync(...)当调用方法时(内部) ,如何让我的应用程序正确设置 cookie Account/Login

4

1 回答 1

18

在 Startup.Auth 类中注册 cookie

app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

在登录页面发布操作中,如果您使用新的 SigninManager.PasswordSigninAsync,如果对用户启用 2 FA,它将设置间歇性 cookie 并返回 SignInStatus.RequiresVerification。然后您可以使用 SigninManager.GetVerifiedUserAsync 应该返回用户 ID

于 2014-07-08T23:58:16.003 回答