Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change EmailConfirmationToken expired time #42

Open
jariba19 opened this issue Sep 1, 2021 · 0 comments
Open

Change EmailConfirmationToken expired time #42

jariba19 opened this issue Sep 1, 2021 · 0 comments

Comments

@jariba19
Copy link

jariba19 commented Sep 1, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant