Skip to content

Commit

Permalink
#86 Force valid response if the user/email is invalid (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
rtufisi authored Oct 14, 2024
1 parent b9bfa95 commit dcf61e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ public void action(AuthenticationFlowContext context) {
if (user == null
|| MagicLink.trimToNull(user.getEmail()) == null
|| !MagicLink.isValidEmail(user.getEmail())) {
context.getEvent().event(EventType.LOGIN_ERROR).error(Errors.INVALID_EMAIL);
Response challengeResponse =
challenge(context, getDefaultChallengeMessage(context), FIELD_USERNAME);
context.failureChallenge(AuthenticationFlowError.INVALID_USER, challengeResponse);
context.getEvent()
.detail(AbstractUsernameFormAuthenticator.ATTEMPTED_USERNAME, email)
.event(EventType.LOGIN_ERROR).error(Errors.INVALID_EMAIL);
context
.getAuthenticationSession()
.setAuthNote(AbstractUsernameFormAuthenticator.ATTEMPTED_USERNAME, email);
log.debugf("user attempted to login with username/email: %s", email);
context.forceChallenge(context.form().createForm("view-email.ftl"));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,14 @@ public void action(AuthenticationFlowContext context) {
if (user == null
|| MagicLink.trimToNull(user.getEmail()) == null
|| !MagicLink.isValidEmail(user.getEmail())) {
context.getEvent().event(EventType.LOGIN_ERROR).error(Errors.INVALID_EMAIL);
Response challengeResponse =
challenge(context, getDefaultChallengeMessage(context), FIELD_USERNAME);
context.failureChallenge(AuthenticationFlowError.INVALID_USER, challengeResponse);
context.getEvent()
.detail(AbstractUsernameFormAuthenticator.ATTEMPTED_USERNAME, email)
.event(EventType.LOGIN_ERROR).error(Errors.INVALID_EMAIL);
context
.getAuthenticationSession()
.setAuthNote(AbstractUsernameFormAuthenticator.ATTEMPTED_USERNAME, email);
log.debugf("user attempted to login with username/email: %s", email);
context.forceChallenge(context.form().createForm("view-email.ftl"));
return;
}

Expand Down

0 comments on commit dcf61e1

Please sign in to comment.