Skip to content

IdentityApiEndpointRouteBuilderExtensions should not create the ConfirmationLink #60195

Open
@JJong-nl

Description

The IdentityApiEndpointRouteBuilderExtensions should never create a ConfirmationLink but must be dealing with codes only.

When we see the implementation of IEmailSender<TUser>
We see SendConfirmationLinkAsync, SendPasswordResetCodeAsync and SendPasswordResetLinkAsync

Here the SendPasswordResetLinkAsync and the SendConfirmationLinkAsync should be removed and a SendConfirmationCodeAsync should be added.

The SendPasswordResetCodeAsync is used in the ApiEndpoint but SendPasswordResetLinkAsync is never used in the Api.
Only in the UI implementation.

When we want to generate a link instead of using the code, we should generating the link inside the IEmailSender<TUser> implementation.

So only SendConfirmationCodeAsync and SendPasswordResetCodeAsync sould be sufficient in the IEmailSender<TUser> interface

IdentityApiEndpointRouteBuilderExtensions.cs

var code = await userManager.GeneratePasswordResetTokenAsync(user);
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
await emailSender.SendPasswordResetCodeAsync(user, resetRequest.Email, HtmlEncoder.Default.Encode(code));

ForgotPassword.cshtml.cs

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.SendPasswordResetLinkAsync(user, Input.Email, HtmlEncoder.Default.Encode(callbackUrl));

The ForgotPassword.cshtml.cs should also be using the SendPasswordResetCodeAsync inside the implementation of the emailsender we sould generate the callbackUrl.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.area-identityIncludes: Identity and providers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions