AsifulNobel / AspNetCoreIssue27088

Workaround for ASP.NET [Issue 27088]: Configure email OTP lifetime with custom providers in this .NET 8 solution.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Workaround for ASP.NET Issue 27088

This repository provides a workaround for ASP.NET Issue 27088 where the token provider is not yet configurable. The workaround introduces custom providers to enable developers to configure the email OTP (One-Time Password) lifetime. The default lifetime in ASP.NET is 9 minutes.

Usage

  1. Add the classes in the CustomTotpTokenProviders directory to your Auth project.
  2. Locate the place in your project where builder.Services.AddIdentity is defined (usually in Startup.cs or an extension class).
  3. After finding the location, add the following code after identityBuilder.AddDefaultTokenProviders().
.AddTokenProvider(TokenOptions.DefaultEmailProvider, typeof(CustomEmailTokenProvider<>).MakeGenericType(identityBuilder.UserType))

Import the namespace where CustomEmailTokenProvider is located.

To use the token provider, configure the email token lifetime by adding the following code (before using the provider):

services.AddSingleton(new CustomEmailTokenProviderOptions
{
    TokenLifespanInSeconds = 120
});

This can be added in Startup.cs or wherever you are configuring dependencies. The provider options have been configured as singleton arbitrarily.

Unit Tests

Unit tests for the email token provider can be found in the CustomTotpTokenProviders.Tests project.

Note

The solution was built with .NET 8.

About

Workaround for ASP.NET [Issue 27088]: Configure email OTP lifetime with custom providers in this .NET 8 solution.

License:MIT License


Languages

Language:C# 100.0%