ASP.Net Identity 2,双因素安全码时间跨度

Man*_*rok 6 c# asp.net asp.net-identity-2

我们通过电子邮件使用2FA和ASP.Net Identity 2.这在大多数情况下工作正常,但在某些情况下,安全代码会延迟到用户电子邮件,安全代码的6分钟窗口会变得太短.

有没有办法调整2FA代码的这个时间窗口?

pys*_*o68 3

我认为你必须更改UserTokenProvider.

在您的实施中尝试以下操作UserManager<TApplicationUser>

public static ApplicationUserManager Create(
    IdentityFactoryOptions<ApplicationUserManager> options,
    IOwinContext context)
{
    /* ...create the user store... */ 
    var manager = new ApplicationUserManager(userStore);

    /* ...all the other config stuff... */

    var dataProtectionProvider = options.DataProtectionProvider;

    if (dataProtectionProvider != null)
    {
        var tokenProvider = new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"));

        // here's what you're looking for:
        tokenProvider.TokenLifespan = TimeSpan.FromMinutes(10);  

        manager.UserTokenProvider = tokenProvider;
    }

    return manager;
}
Run Code Online (Sandbox Code Playgroud)

  • 为此,您还必须更改 StartUp 文件中的两因素 cookie 超时,如下所示: UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(10)); (3认同)