Hello,
I am developing an extension to customize the “reset-credentials” flow, which is initiated when a user selects the “forgot password” option on the login page.
Specifically, I want the extension to send a verification email instead of a password reset email when the user’s email is unverified. In other words, I don’t want the user to be able to reset his password and login to the application until he is not verified.
Can you help me achieve this ?
I have already extended org.keycloak.authentication.authenticators.resetcred.ResetCredentialEmail
and successfully blocked the sending of the reset password email:
public class CustomResetCredentialEmail extends org.keycloak.authentication.authenticators.resetcred.ResetCredentialEmail {
private static final Logger logger = Logger.getLogger(CustomResetCredentialEmail.class);
@Override
public void authenticate(AuthenticationFlowContext context) {
UserModel user = context.getUser();
logger.info("SemResetCredentialEmail.authenticate() >>> " + toString(user));
if (user != null && !user.isEmailVerified()) {
context.getEvent().user(user)
.detail(Details.USERNAME, user.getUsername())
.error("email_not_verified"); // Send a custom event to track the error
// For security reasons we don't want to show the error message to the user, just continue the flow
context.forkWithSuccessMessage(new FormMessage(Messages.EMAIL_SENT));
return;
}
super.authenticate(context);
}
}
However, I am unsure how to trigger the sending of the verification email using the Java APIs.
Any assistance would be greatly appreciated!
Thanks!