Dotnetcore3 angular template Password reset not working
Hello there!
I'm working with the new dotnetcore3 angular template, using IdentityServer4 and EFCore code first. Almost everything is working exactly as I'd expect it to, except for stuff that's token-based. Email Confirmation and Password Reset tokens both return InvalidToken whenever I try to validate them.
Here are what I assume are the relevant parts of my code:
In Startup.cs:
services.AddIdentity<ApplicationUser, IdentityRole>(options => {
options.Tokens.PasswordResetTokenProvider = TokenOptions.DefaultEmailProvider;
options.Tokens.EmailConfirmationTokenProvider = TokenOptions.DefaultEmailProvider;
})
.AddDefaultTokenProviders()
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddIdentityServer(options =>
{
options.UserInteraction.LoginUrl = "/auth/login";
options.UserInteraction.LogoutUrl = "/auth/logout";
})
//.AddDeveloperSigningCredential()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
services.AddAuthentication()
// .AddGoogle(options =>
// {
// IConfigurationSection googleAuthNSection = Configuration.GetSection("Authentication:Google");
// options.ClientId = googleAuthNSection["ClientId"];
// options.ClientSecret = googleAuthNSection["ClientSecret"];
// })
.AddIdentityServerJwt();
ForgotPassword:
public async Task<IActionResult> OnPostAsync()
{
if (ModelState.IsValid)
{
var user = await _userManager.FindByEmailAsync(Input.Email);
if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
{
// Don't reveal that the user does not exist or is not confirmed
// For more information on how to enable account confirmation and password reset please
// visit https://go.microsoft.com/fwlink/?LinkID=532713
var code = await _userManager.GeneratePasswordResetTokenAsync(user);
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
var callbackUrl = Url.Page(
"/Account/ResetPassword",
pageHandler: null,
values: new { area = "Identity", code },
protocol: Request.Scheme);
await _emailSender.SendEmailAsync(
Input.Email,
"Reset Password",
$"Please reset your password by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
}
return RedirectToPage("./ForgotPasswordConfirmation");
}
ResetPassword:
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
var user = await _userManager.FindByEmailAsync(Input.Email);
if (user == null)
{
// Don't reveal that the user does not exist
return RedirectToPage("./ResetPasswordConfirmation");
}
var result = await _userManager.ResetPasswordAsync(user, Input.Code, Input.Password);
if (result.Succeeded)
{
return RedirectToPage("./ResetPasswordConfirmation");
}
foreach (var error in result.Errors)
{
ModelState.AddModelError(string.Empty, error.Description);
}
return Page();
}
Not sure if it's relevant but I'm using a Developer certificate on my local machine and a self-signed certificate on my server, and it's not working in either place
This seems to be related to Microsoft's IdentityServer integration. Please open an issue on their issuer tracker instead. @javiercn @blowdart
https://github.com/aspnet/aspnetcore/issues
Thanks for the info!
On Fri, Dec 13, 2019 at 1:29 PM Dominick Baier [email protected] wrote:
This seems to be related to Microsoft's IdentityServer integration. Please open an issue on their issuer tracker instead. @javiercn https://github.com/javiercn @blowdart https://github.com/blowdart
https://github.com/aspnet/aspnetcore/issues
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/IdentityServer/IdentityServer4/issues/3909?email_source=notifications&email_token=AB6CT2PW2X4W4QY27H7SWQ3QYPIBZA5CNFSM4J2NDTFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEG225BY#issuecomment-565554823, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6CT2PKJOJ5ZQSGSKHTY5LQYPIBZANCNFSM4J2NDTFA .
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.