Skip to content

Change EmailConfirmationToken expired time #42

Open
@jariba19

Description

@jariba19

Hi, i'm trying to change the expiration time of the EmailConfirmationToken that is generated with the GenerateEmailConfirmationTokenAsync method.

To do that, i added the next code in startup.cs class:

private const string EmailConfirmationTokenProviderName = "ConfirmEmail";

public void ConfigureServices(IServiceCollection services)
{
...

services.Configure<IdentityOptions>(options =>
{
    options.Tokens.EmailConfirmationTokenProvider = EmailConfirmationTokenProviderName;
});

services.Configure<ConfirmEmailDataProtectionTokenProviderOptions>(options =>
{
    options.TokenLifespan = TimeSpan.FromDays(1);
});

services.AddIdentity<ApplicationUser, IdentityRole>(
    item =>
    {
        ...
        item.Tokens.EmailConfirmationTokenProvider = EmailConfirmationTokenProviderName;
        item.Tokens.PasswordResetTokenProvider = EmailConfirmationTokenProviderName;
    })
    .AddEntityFrameworkStores<ApplicationDbContext>()
    .AddDefaultTokenProviders()
    .AddTokenProvider<ConfirmEmailDataProtectorTokenProvider<ApplicationUser>>(EmailConfirmationTokenProviderName);
...

}
public class ConfirmEmailDataProtectionTokenProviderOptions : DataProtectionTokenProviderOptions { }

public class ConfirmEmailDataProtectorTokenProvider : DataProtectorTokenProvider where TUser : class
{
public ConfirmEmailDataProtectorTokenProvider(IDataProtectionProvider dataProtectionProvider, IOptions options, ILogger logger) : base(dataProtectionProvider, options, logger)
{
}
}
The project is in Core 3.1, when i set options.TokenLifespan = TimeSpan.FromMinutes(5) for example, it works perfectly but when i set 24 hours or one day in TokenLifespan, the token expire in one hour more or less. The same problem occurs with PasswordResetToken.

Can't exceed a max time? How could I solve the problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions