invalid Token on reset password with ASP.NET, when multiple instances running

2/20/2020

I'm using Web API and Asp.net Identity to perform user related Operations. Trying to Reset the Password With token Generated from GeneratePasswordResetTokenAsync method, but I'm getting the error "Invalid Token" Note: Using Kubernetes and having Multiple Instances(pods) of the application, I'm facing this error. However, when running locally, it works fine.

private static UserManager<IdentityUser> _userManager;

public async Task<IActionResult> ForgotPassword(string email)
{
  var user = await _userManager.FindByEmailAsync(email);
  var resetToken = await _userManager.GeneratePasswordResetTokenAsync(user);
  result = await SendForgotPasswordLinkEmail(email, resetToken);
  if (result)
    return Ok(result);
  else
    return BadRequest(result);
}
public async Task<IActionResult> ResetPassword(model)//model contains all neccessary values
{
  var user = await _userManager.FindByEmailAsync(model.Email);
  var check =await_userManager.ResetPasswordAsync(user,model.ResetPasswordToken,model.Password);               
}
-- Balaji Arun
asp.net
asp.net-identity
asp.net-web-api2
c#
kubernetes

1 Answer

3/16/2020
// try this code
public IdentityResult ChangePassword(string email,string password)
{
        var user = UserManager.FindByName(email); 
        var token = UserManager.GeneratePasswordResetToken(user.Id);
        return UserManager.ResetPassword(user.Id, token, password);
}
-- Sunny Jangid
Source: StackOverflow