使用SMS的ASP.NET Core 2.0 Identity 2FA,在具有多个架构的TwoFactorSignInAsync()之后未通过身份验证

时间:2018-09-26 08:29:18

标签: c# asp.net-core-mvc asp.net-core-2.0 asp.net-core-identity asp.net-authentication

我有一个ASP.NET Core 2.0解决方案,并且我从版本1.1复制了SMS 2FA的功能。一切顺利,我收到了带有代码的短信,并验证了代码和_signInManager.TwoFactorSignInAsync的结果。成功= true。

但是,我在启动中定义了2个架构。普通用户和管理员用户。管理员用户已启用2FA,普通用户未启用。

  services.ConfigureApplicationCookie(options =>
            {
                options.LoginPath = "/Account/LogIn";                  
                options.ExpireTimeSpan = TimeSpan.FromMinutes(5);
                options.Cookie.SecurePolicy = CookieSecurePolicy.Always;


            });


 services.AddAuthentication(options =>
            {
                options.DefaultScheme = 
 CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            }).AddCookie("User", options =>
                   {
                       options.LoginPath = "/Account/LogIn";
                       options.AccessDeniedPath = "/Account/AccessDenied";
                   })
                   .AddCookie("Admin", options =>
                   {
                       options.LoginPath = "/Admin/Login";
                       options.AccessDeniedPath = "/Admin/AccessDenied";
                   });

然后在AdminController上我有这个:[Authorize(AuthenticationSchemes = "Admin")]

流程如下:

  • 重定向到正确的登录页面
  • 用户名+密码登录成功
  • 成功后,我将重定向到SMS代码验证
  • 验证就是成功
  • 重定向到管理控制器的索引页面,会将我带回登录页面,而不是未经身份验证。

有什么想法我做错了吗?

0 个答案:

没有答案