In case anyone else makes the same mistake that I did. I tried to make a function like the one below and sure enough the error "No IUserTokenProvider is registered." was gone. However as soon as I tried to use the link generated from "callbackUrl" I got the error "Invalid token." In order for it to work you need to get the HttpContext UserManager. If you are using a standard ASP.NET MVC 5 application with individual user accounts you can do it like below..
Code that works:
public ActionResult Index()
{
//Code to create ResetPassword URL
var userManager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
var user = userManager.FindByName("useremail@gmail.com");
string code = userManager.GeneratePasswordResetToken(user.Id);
var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
return View();
}
First try that does not work, No IUserTokenProvider is registered.
is gone but the URL created gets Invalid token.
.
public ActionResult NotWorkingCode()
{
//DOES NOT WORK - When used the error "Invalid token." will always trigger.
var provider = new DpapiDataProtectionProvider("ApplicationName");
var userManager = new ApplicationUserManager(new UserStore<ApplicationUser>(new ApplicationDbContext()));
userManager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(provider.Create("ASP.NET Identity"));
var user = userManager.FindByName("useremail@gmail.com");
string code = userManager.GeneratePasswordResetToken(user.Id);
var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
//DOES NOT WORK - When used the error "Invalid token." will always trigger.
return View();
}