Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GenerateEmailConfirmationTokenAsync default expiration timespan

What is default expiration timespan of GenerateEmailConfirmationTokenAsync? and what kind of errors should I get from ConfirmEmailAsync?

For ConfirmEmailAsync got Invalid token error. is there any other errors?

Once I confirm email and again I access same token then it is again confirming email. So up to what time span it will re-confirm Email and when it will show Invalid Token message?

For generate email:

     string code = await userManager.GenerateEmailConfirmationTokenAsync(userId);

For confirm email:

    var userManager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
    var result = await userManager.ConfirmEmailAsync(userId, code);

    if (result.Succeeded)
    {
       return RedirectToAction("Index", "Home");
    }
like image 499
Sincha Avatar asked Mar 07 '18 11:03

Sincha


1 Answers

Default timespan is one day but you can specify your timespan for the email expiration. After expiration, you will get "Invalid Token" error. You can change the code in the Create method(App_Start\IdentityConfig.cs file) for custom expiration timespan.

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

Source: https://learn.microsoft.com/en-us/aspnet/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity

like image 96
Neeraj Mehta Avatar answered Oct 17 '22 06:10

Neeraj Mehta