title: ConfirmEmailAsync() method is not working
body: <p>I am having issue in confirming new user email. the Confirm email link works for first 20 minutes , but after 50 minutes the link expires. I have set the token expiration time to 24 hours. Please help me in resolving this issue. I am stuck on it for last 2 days:(.My code is as follows:
  I am setting the token lifetime in Create() method in ApplicationUserManager as following:</p>
  
  <pre><code>       var dataProtectionProvider = options.DataProtectionProvider;
  
          if (dataProtectionProvider != null)
          {
              userManager.UserTokenProvider = new DataProtectorTokenProvider&lt;ApplicationUser&gt;(dataProtectionProvider.Create("ASP.NET Identity"))
              {
                  TokenLifespan = _settings.ConfirmationAndResetTokenExpirationTimeSpan
              };
          }
  </code></pre>
  
  <p>And then In AccountsController, the Create method for new user is geiven below. The SendEmailAsync method consist of email subject, email body, generated password and the callback uri.</p>
  
  <pre><code>[Authorize(Roles = Roles.Bam.Name.Admin)]
      [HttpPost]
      [Route(Routes.Accounts.Template.Create, Name = Routes.Accounts.Name.Create)]
      public async Task&lt;IHttpActionResult&gt; Create(CreateUserBindingModel createUserBindingModel)
      {
          IHttpActionResult result;
  
  
              var memberNameExists = UserManager.Users.Any(x =&gt; x.MemberName.ToLower() == createUserBindingModel.MemberName.ToLower());
  
              if (!memberNameExists)
              {
                  var applicationUser = new ApplicationUser
                  {
                      UserName = createUserBindingModel.Email,
                      Email = createUserBindingModel.Email,
                      FirstName = createUserBindingModel.FirstName,
                      LastName = createUserBindingModel.LastName,
                      Company = createUserBindingModel.Company,
                      Location = createUserBindingModel.Location,
                      PhoneNumber = createUserBindingModel.PhoneNumber,
                      MemberName = createUserBindingModel.MemberName,
                      LastLoginDate = SqlDateTime.MinValue.Value,
                      CreateDate = DateTime.Now,
                      CreatedBy = User.Identity.GetUserId(),
                      UpdateDate = DateTime.Now,
                      UpdatedBy = User.Identity.GetUserId(),
                      TwoFactorEnabled = createUserBindingModel.TwoFactorEnabled,
                      SecurityResetRequired = true,
                      PasswordExpirationDate = DateTime.Now.AddDays(Convert.ToDouble(ConfigurationManager.AppSettings["PasswordExpirationDays"]))
                  };
  
                  if (!string.IsNullOrEmpty(createUserBindingModel.AvatarBase64))
                  {
                      var avatarBytes = Convert.FromBase64String(createUserBindingModel.AvatarBase64);
                      var resizedAvatarBytes = ImageResizer.ResizeImage(avatarBytes, _avatarWidth, _avatarHeight);
  
                      applicationUser.UserAvatar = new ApplicationUserAvatar
                      {
                          Avatar = resizedAvatarBytes
                      };
                  }
  
                  var generatedPassword = PasswordGenerator.GenerateStrongPassword(10, 10);
  
                  var identityResult = await UserManager.CreateAsync(applicationUser, generatedPassword);
  
                  if (identityResult.Succeeded)
                  {
                      await UserManager.AddToRolesAsync(applicationUser.Id, createUserBindingModel.Roles.ToArray());
  
                      var token = await UserManager.GenerateEmailConfirmationTokenAsync(applicationUser.Id);
                      var callbackUri = string.Format("{0}?userId={1}&amp;token={2}", createUserBindingModel.EmailConfirmationCallbackUri, applicationUser.Id, HttpUtility.UrlEncode(token));
  
                      await UserManager.SendEmailAsync(applicationUser.Id, Email.Confirmation.Subject, string.Format(Email.Confirmation.Body, string.Format("{0} {1}", applicationUser.FirstName, applicationUser.LastName), callbackUri, generatedPassword, _settings.AccessTokenExpirationTimeSpan.TotalHours));
  
                      var userUrl = new Uri(Url.Link(Routes.Accounts.Name.Get, new { id = applicationUser.Id }));
                      var roles = await UserManager.GetRolesAsync(applicationUser.Id);
                      var contract = _accountsMapper.ToContract(applicationUser, roles);
  
                      result = Created(userUrl, contract);
                  }
                  else
                  {
                     result = GetErrorResult(identityResult);
                  }
              }
              else
              {
                  ModelState.AddModelError(string.Empty, "Member Name already exists!");
  
                  result = BadRequest(ModelState);
              }
          return result;
      }
  </code></pre>
  
  <p>Once the email is generated the UI has following JS angular code which gets executed and the provide the userid and token to service.
  Angular JS code:</p>
  
  <pre><code>angular.module('confirmEmailModule').factory('confirmEmailFactory', function ($http) {
  var factory = {};
  
  factory.confirmEmail = function(userId, token) {
  
      var encodedToken = encodeURIComponent(token);
      var uri = '/identity/api/accounts/confirmemail?userId=' + userId + '&amp;token=' + token;
  
      return $http.post(uri);
  }
  
  return factory;
  </code></pre>
  
  <p>});</p>
  
  <p>and the Service is :</p>
  
  <pre><code>[AllowAnonymous]
      [HttpPost]
      [Route(Routes.Accounts.Template.ConfirmEmail, Name = Routes.Accounts.Name.ConfirmEmail)]
      public async Task&lt;IHttpActionResult&gt; ConfirmEmail([FromUri] string userId, [FromUri] string token)
      {
          //var decodedToken = HttpUtility.UrlDecode(token);
          var identityResult = await UserManager.ConfirmEmailAsync(userId, token);
          var result = identityResult.Succeeded ? StatusCode(HttpStatusCode.NoContent) : GetErrorResult(identityResult);
  
          return result;
      }
  </code></pre>
  
  <p>Please advice.</p>