How to customize the default timeout for 2fa token generated by default email provider in asp.net core identity framework

Rohit Mahindrakar 0 Reputation points
2023-12-20T21:38:56.23+00:00

I am using asp.net core identity framework in my application, and the default email provider for 2fa token generation. The documentation here - https://learn.microsoft.com/en-us/aspnet/identity/overview/features-api/two-factor-authentication-using-sms-and-email-with-aspnet-identity#enabling-2fa, says that the default timeout is 6 mins for the token. But when testing I noticed its coming out to be 5 mins. Also, I don't see any clear documentation around customizing this timeout setting. We are trying to update the timeout value to 15 mins. I tried to follow the steps mentioned here - https://learn.microsoft.com/en-us/answers/questions/842342/extend-the-2fa-token-expiration-in-asp-net-core, but that did not work. I keep getting an error - "'Scheme already exists: Identity.Application'". Please advise. Thank you in advance.

Developer technologies | ASP.NET | ASP.NET Core
Microsoft Security | Microsoft Identity Manager
{count} votes

1 answer

Sort by: Most helpful
  1. SurferOnWww 5,261 Reputation points
    2023-12-21T01:33:03.3166667+00:00

    I suggest that you use the MFA TOTP (Time-based One-time Password Algorithm) for the ASP.NET Core as described in the following Microsoft document:

    Multi-factor authentication in ASP.NET Core

    "MFA using TOTP is supported by default when using ASP.NET Core Identity."

    Although the default does not include QR Code generation it can be added according to the following Microsoft document:

    Enable QR code generation for TOTP authenticator apps in ASP.NET Core

    The result is shown blow:

    image

    The first document shown in your question is for .NET Framework version ASP.NET Identity. Use of e-mail and SMS for 2FA is no longer supported in the project template for the ASP.NET Core App.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.