How to set validation email token expiration in asp.net core mvc

I'm trying to extend the lifespan of confirmation emails and reset passwords, but I can't seem to do it. I am currently using Asp.net core 1.0.1 if helpful.

Some advice or even better code would be much appreciated.

thank

+3


source to share


2 answers


Maybe this will help someone =)

Just do the following:



    public void ConfigureServices(IServiceCollection services)
    {
        // ...
        services.Configure<DataProtectionTokenProviderOptions>(options =>
        {
            options.TokenLifespan = TimeSpan.FromSeconds(1); // .FromDays(1) ...
        });
    }

      

This works for me.

+4


source


The next code change in the Create method (in the App_Start \ IdentityConfig.cs file) sets the tokens to expire after 3 hours.

if (dataProtectionProvider != null)
 {
    manager.UserTokenProvider =
       new DataProtectorTokenProvider<ApplicationUser>
          (dataProtectionProvider.Create("ASP.NET Identity"))
          {                    
             TokenLifespan = TimeSpan.FromHours(3)
          };
 }

      



Hope it helps.

0


source







All Articles