0

I am trying to implement email confirmation/verification feature for my identity server users. In my case i have 2 apps, one is for Web API to add Identity server users and another is for a web app to provide the login to the users.

I have followed this document and able to generate the token for user email confirmation. Here i am forming a URL for identity web app and attaching the token, email as query parameters.

var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);
var confirmationLink = Url.Action(nameof(ConfirmEmail), "Account", new { token, email = user.Email }, Request.Scheme);
var message = new Message(new string[] { user.Email }, "Confirmation email link", confirmationLink, null);
await _emailSender.SendEmailAsync(message);

Using the above code generated the URL similar to this.

https://identitywebapp/Account/ConfirmEmail?token=CfDJ8MnpbdKNEB1Orar2rO6jqk3aK1mqnU9i%2BbAkMbV7Bpu91NhOGVCv8ad4x8pFw8tzRPrixaJNJPMsQVXhBxywNdZvCsN0PiqXZJxem45JblNQEy4gaMVDeFgu8wlGIBtXwi&email=admtest3@mailinator.com

Below is my ConfirmEmail method implementation.

[HttpGet]
public async Task<IActionResult> ConfirmEmail(string token, string email)
{
    var user = await _userManager.FindByEmailAsync(email);
    if (user == null)
        return View("Error");
    var result = await _userManager.ConfirmEmailAsync(user, token);
    return View(result.Succeeded ? nameof(ConfirmEmail) : "Error");
}

I am getting the "Invalid Token" issue when calling the _userManager.ConfirmEmailAsync(user, token);

James Z
  • 12,209
  • 10
  • 24
  • 44
Aditya
  • 1
  • 2

0 Answers0