Skip to content

fix: allows verify email working in incognito browser tab after Keycloak restart - #51089

Merged
rmartinc merged 1 commit into
keycloak:mainfrom
pchorus:feature/fix-verify-email
Jul 28, 2026
Merged

fix: allows verify email working in incognito browser tab after Keycloak restart#51089
rmartinc merged 1 commit into
keycloak:mainfrom
pchorus:feature/fix-verify-email

Conversation

@pchorus

@pchorus pchorus commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Avoid NullPointerException.

Closes #51088.

@pchorus
pchorus requested a review from a team as a code owner July 22, 2026 12:09
Copilot AI review requested due to automatic review settings July 22, 2026 12:09
@pchorus
pchorus force-pushed the feature/fix-verify-email branch from 1a8fcce to f84de65 Compare July 22, 2026 12:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Prevents email verification from failing after a Keycloak restart when the original authentication session no longer exists.

Changes:

  • Adds a null guard before removing the original root authentication session.

Copilot AI review requested due to automatic review settings July 22, 2026 12:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

services/src/main/java/org/keycloak/authentication/actiontoken/verifyemail/VerifyEmailActionTokenHandler.java:142

  • Please add a regression test for the missing-root-session path. The existing RequiredActionEmailVerificationTest.verifyEmailRegisterWithSecondBrowser keeps the original root authentication session alive, so it would not catch this NPE returning after a restart; the test should remove/expire that session before opening the email link in the second browser and assert successful verification.
            if (rootAuthSession != null) {
                session.authenticationSessions().removeRootAuthenticationSession(realm, rootAuthSession);
            }

@rmartinc rmartinc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @pchorus for the PR!

LGTM but please fix the imports (mvn spotless:apply) and add your email in the signoff signature (it seems that is required for the DCO check).

@rmartinc rmartinc self-assigned this Jul 27, 2026
Copilot AI review requested due to automatic review settings July 27, 2026 08:59
@pchorus
pchorus force-pushed the feature/fix-verify-email branch from a9ff644 to 1ec54bf Compare July 27, 2026 08:59
@pchorus

pchorus commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks a lot @pchorus for the PR!

LGTM but please fix the imports (mvn spotless:apply) and add your email in the signoff signature (it seems that is required for the DCO check).

Done.

@pchorus
pchorus force-pushed the feature/fix-verify-email branch from 1ec54bf to 40d88cf Compare July 27, 2026 09:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

…oak restart

closes keycloak#51088.
Signed-off-by: Pascal Chorus <pascal.chorus@moneymeets.com>
Copilot AI review requested due to automatic review settings July 27, 2026 15:45
@rmartinc
rmartinc force-pushed the feature/fix-verify-email branch from 40d88cf to 1766437 Compare July 27, 2026 15:45
@rmartinc

Copy link
Copy Markdown
Contributor

@pchorus I have rebased your branch to take the fix for #51191. Let's see if the tests are OK now.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

* in-memory authentication sessions that happens when Keycloak is restarted.
*/
private void removeRootAuthenticationSession() {
String encodedAuthSessionId = driver.driver().manage().getCookieNamed(CookieType.AUTH_SESSION_ID.getName()).getValue();
Comment on lines +414 to +415
MimeMessage message = mailServer.getReceivedMessages()[0];
String link = MailUtils.getPasswordResetEmailLink(message);
Comment on lines +140 to +142
if (rootAuthSession != null) {
session.authenticationSessions().removeRootAuthenticationSession(realm, rootAuthSession);
}

@rmartinc rmartinc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pchorus for the changes!

@rmartinc
rmartinc merged commit ce44984 into keycloak:main Jul 28, 2026
96 of 99 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Verify email not working in incognito browser tab after Keycloak restart

3 participants