AspNetIdentity icon indicating copy to clipboard operation
AspNetIdentity copied to clipboard

Problem with change email confirmation after scaffolding

Open DotNetDublin opened this issue 5 years ago • 1 comments

Hi,

After I scaffolded ASP.NET Core Identity into my Blazor (Server) project I noticed that I was unable to change email address using the function presented on Account\Manage\Email.cshtml

The email confirmation would send as expected however when I clicked on the link the value of result.Succeeded on line 42 of Account\ConfirmEmailChange.cshtml.cs was always false.

code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
var result = await _userManager.ChangeEmailAsync(user, email, code);
if (!result.Succeeded)
{
	StatusMessage = "Error changing email.";
	return Page();
}

In noticed on Account\Manage\Email.cshtml.cs that within OnPostSendVerificationEmailAsync() after the token code was generated on line 129 using await _userManager.GenerateEmailConfirmationTokenAsync(user) that it was then encoded using code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));

This encoding is missing within OnPostChangeEmailAsync() after var code = await _userManager.GenerateChangeEmailTokenAsync(user, Input.NewEmail); on line 93.

When I add code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); to line 94 the issue is resolved and result.Succeeded returns true.

Thanks

DotNetDublin avatar Aug 10 '20 14:08 DotNetDublin

Yes. This is the same solution as what I did

tymur999 avatar Oct 08 '20 14:10 tymur999