【问题标题】:How to use email OTP instead of authenticator TOTP in identityserver4+AspNetCode.Identity如何在 identityserver4+AspNetCode.Identity 中使用电子邮件 OTP 而不是身份验证器 TOTP
【发布时间】:2022-01-08 21:53:28
【问题描述】:

我发布此内容是为了让其他人遇到同样的问题,因为我找不到任何在线文档。

问题:

使用https://github.com/skoruba/IdentityServer4.Admin(IdentityServer4,使用Microsoft.AspnetCore.Identity进行身份验证),如何更改默认的Authenticator TOTP,改用基于电子邮件的OTP?

【问题讨论】:

    标签: asp.net-identity identityserver4


    【解决方案1】:
    1. 在 AccountController 中找到以下行:

      return RedirectToAction(nameof(LoginWith2fa), new { model.ReturnUrl, RememberMe = model.RememberLogin });

    2. 添加之前:

      var code = await _userManager.GenerateTwoFactorTokenAsync(user, "Email");

      _emailSender.SendEmailAsync(user.Email, "TwoFactor code", htmlEmail);

    3. 找线:

      var 结果 = await _signInManager.TwoFactorAuthenticatorSignInAsync(authenticatorCode, model.RememberMe, model.RememberMachine);

    4. 替换为:

      var result = await _signInManager.TwoFactorSignInAsync("Email", authenticationatorCode, model.RememberMe, model.RememberMachine);

    我希望它可以为某人省去一些麻烦。

    【讨论】:

      猜你喜欢
      • 2016-07-28
      • 1970-01-01
      • 2021-09-05
      • 1970-01-01
      • 1970-01-01
      • 2016-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多