Skip to content

Identity provider should not be hidden from login page when the a user goes back from the reset credentials page - #33254

Closed
vilmosnagy wants to merge 3 commits into
keycloak:mainfrom
vilmosnagy:issue_33204
Closed

Identity provider should not be hidden from login page when the a user goes back from the reset credentials page#33254
vilmosnagy wants to merge 3 commits into
keycloak:mainfrom
vilmosnagy:issue_33204

Conversation

@vilmosnagy

@vilmosnagy vilmosnagy commented Sep 24, 2024

Copy link
Copy Markdown
Contributor

Closes #33204.

Breaks only one test, RegisterTest::testRegisterShouldFailBeforeUserCreationWhenUserIsInContext, which was added in #23064 (issue #21514) - that test covers basically the same bug (also reported by me). In the previous bug the steps to reproduce was:

  • go to reset credentials, and pick a valid username
  • then go back, and try to register -> the fix was to check and raise an error during the registration if the user was set in the ResetCredentialChooseUser

The current issue (#33204) I'm having in short is:

  • go to reset credentials, and pick a valid username
  • then go back to the login page -> the social logins, which doesn't linked to the picked account, will be hidden from the login. You don't even need to pass the authentication to find out what social sites the user has linked to their account.

My current fix checks whether a user has been set in the context during an attempted (and cancelled) reset credential flow - and if it has been set, then we clear them from the context when loading the login page.

If I modify the failing test (also written by me), would you be willing to merge this? Probably I need to:

  • modify the failing test
  • add a new, slightly modified RegisterTest::testRegisterShouldFailBeforeUserCreationWhenUserIsInContext one where the login page is skipped entirely

cc @ahus1 @sguilhen @mposolda who was involved in the test which fails currently.

@vilmosnagy
vilmosnagy requested review from a team as code owners September 24, 2024 20:48
@jonkoops jonkoops changed the title fix #33204 - Identity provider should not be hidden from login page when the a user goes back from the reset credentials page Identity provider should not be hidden from login page when the a user goes back from the reset credentials page Sep 24, 2024
@jonkoops

Copy link
Copy Markdown
Contributor

Thanks for the PR! FYI if you want to link an issue you can use a keyword to do so. We try to avoid mentioning the issue in the title. I went ahead and edited the issue description to link it up.

@keycloak-github-bot keycloak-github-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot

Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.webauthn.registration.PolicyJsInjectionTest#relyingPartyId

Keycloak CI - WebAuthn IT (chrome)

java.lang.AssertionError: Expected RegisterPage but was Sign in to test (https://localhost:8543/auth/realms/test/protocol/openid-connect/auth?response_type=code&client_id=test-app&redirect_uri=https%3A%2F%2Flocalhost%3A8543%2Fauth%2Frealms%2Fmaster%2Fapp%2Fauth&state=a195fd75-3463-4ce5-a0e3-70c72425c0f4&scope=openid)
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.keycloak.testsuite.pages.AbstractPage.assertCurrent(AbstractPage.java:47)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
...

Report flaky test

@sguilhen

sguilhen commented Sep 30, 2024

Copy link
Copy Markdown
Contributor

@vilmosnagy I haven't had the time to look into your PR yet, but the test failures seem to be related - actually only one test seems to be failing - a registration test.

EDIT: sorry, didn't read your description properly - I agree with your proposal to fix the test as described.

@vilmosnagy
vilmosnagy force-pushed the issue_33204 branch 2 times, most recently from 1cd5ec9 to 50b425a Compare October 6, 2024 14:39
@vilmosnagy

Copy link
Copy Markdown
Contributor Author

@sguilhen thanks for your feedback, I've pushed the changes I described. As far as I see the failing tests are not connected to this PR (they seem to be js & db related, while I only touched registration-flow related code).

Could you please move forward with the review? Thanks

@sguilhen

sguilhen commented Oct 6, 2024

Copy link
Copy Markdown
Contributor

@ahus1 Could you please re-run the CI for this PR? Failures don´t seem related to the changes

@vilmosnagy

Copy link
Copy Markdown
Contributor Author

@sguilhen @ahus1 thanks for the retry. If I see correctly, currently only one test fails in the admin ui e2e tests. Am I correctly assuming that it has nothing to do with my modifications? What's your opinion on this?

Thanks,
Vilmos

@sguilhen

sguilhen commented Oct 7, 2024

Copy link
Copy Markdown
Contributor

@vilmosnagy @ahus1 Yeah, this test has been failing in other PRs, but IIRC it was fixed last week (see #33440). Have you rebased your branch recently?

@ahus1

ahus1 commented Oct 7, 2024

Copy link
Copy Markdown
Member

Rebased just now, let's see what the tests report.

@vilmosnagy

Copy link
Copy Markdown
Contributor Author

@sguilhen as far as I remember I've rebased it during the weekend. But it fails even after @ahus1 's rebase as well :'(

@sguilhen

sguilhen commented Oct 7, 2024

Copy link
Copy Markdown
Contributor

@edewit I thought this duplicate group test was disabled last week, but it seems it is still happening like in this PR. Any ideas what we could do?

@edewit
edewit requested a review from a team as a code owner October 8, 2024 07:48
@vilmosnagy

Copy link
Copy Markdown
Contributor Author

Is that possible that the failing test03SpnegoLoginWithCorrectKerberosPrincipalRealm test is a flaky one? It was detected by the bot in previous issues with a very similar stacktrace & error: #32283 (comment)

Signed-off-by: Vilmos Nagy <vilmos.nagy@outlook.com>
Signed-off-by: Vilmos Nagy <vilmos.nagy@outlook.com>
…ehaviour

Signed-off-by: Vilmos Nagy <vilmos.nagy@outlook.com>

# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# Date:      Sun Oct 6 16:35:19 2024 +0200
#
# On branch issue_33204
# Changes to be committed:
#	modified:   testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/forms/RegisterTest.java
#
@sguilhen

sguilhen commented Oct 8, 2024

Copy link
Copy Markdown
Contributor

Is that possible that the failing test03SpnegoLoginWithCorrectKerberosPrincipalRealm test is a flaky one? It was detected by the bot in previous issues with a very similar stacktrace & error: #32283 (comment)

Yeah, it is likely a flaky one that needs to be looked into

@mposolda mposolda self-assigned this Oct 8, 2024

@mposolda mposolda 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.

@vilmosnagy Thanks for the PR! I think that the change in the test RegisterTest.testRegisterShouldFailBeforeUserCreationWhenUserIsInContext is OK IMO.

However I have one more scenario I would like to discuss, when user opens link from the email after click "Back". In details:

  1. User clicks "Forget password" on the login screen
  2. User chooses the username john (Now john useris set in the authenticationSession) and there is email sent to the email address of john
  3. Now user click "Back" and login screen is displayed
  4. Now user goes to his email and clicks on the link from the email from step (2). Now what happens?

It seems to me that before this PR, user is verified and he is able to reset his password and then he is authenticated.

But can you check what happen after your changes?

I did not check, but I think that after your changes, the user is not verified as he is not anymore in the context of authenticationSession. IMO this change is fine if there is some sensible page displayed to the user like Action expired. Please continue here with the link where user can restart his login and continue from the start. But what is not OK is some unexpected error page like NullPointerException (I did not tried, but I have some suspicion that NPE can happen in AbstractActionTokenHandler.verifyEmail due the user cleared from auth session, but maybe I am wrong :-)


private void clearUserIfComingFromResetPassword(AuthenticationFlowContext context) {
if ("true".equals(context.getAuthenticationSession().getAuthNote(RESET_CREDENTIAL_USER_CHOSEN))) {
context.clearUser();

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.

IMO it will be good to clear the RESET_CREDENTIAL_USER_CHOSEN note as well. Otherwise, during next invocation of this method, the user will be cleared again, which is not feasible.

An alternative and more generic approach might be to move this from UsernamePasswordForm somewhere to the upper layer (AuthenticationProcessor or DefaultAuthenticationFlow) and reset whole authenticationSession (something like AuthenticationPRocessor.resetFlow) when it is detected that flow was changed from reset-credentials back to the browser . However I am not sure if it is easily and reliably possible to detect this?

@vilmosnagy

vilmosnagy commented Oct 10, 2024

Copy link
Copy Markdown
Contributor Author

Hi @mposolda,

Thanks for your review.

But can you check what happens after your changes?

You're probably right—my changes might break the forgot password flow if the user navigates back to the login page before clicking on the email link.

One question, though: do we need to show an action expired page in this case? For example, if I start the password reset flow on one device (e.g., mobile) and click the reset password link on another (e.g., desktop), the reset is allowed in the new session. The only difference is:

  • If the user opens the link in the original session, they are redirected back to the app in a logged-in state.
  • If the user opens the link in a new session, an informational page is displayed with a prompt to return to the base URL of the client.

Would this approach be feasible for you? Just theorizing here, but maybe something like:

  1. The user clicks "Forgot password" on the login screen.
  2. The user enters the username john (now john is set in the authentication session), and an email is sent to john's email address.
  3. The user clicks "Back," and the login screen is displayed.
  4. The user clicks the link in the email from step 2.
  5. John is allowed to set the new password and is redirected to client.baseUrl upon success - the same way they'd be redirected if they'd opened the link in a new browser session.

Either way: I see your points here, and I'll need a couple of days to write a few more tests. I'll get back to you once those are done.

Thanks again,
Vilmos

@mposolda

Copy link
Copy Markdown
Contributor

@vilmosnagy Yes, I think you are right. It will be better user experience if the user is authenticated similarly like in the current Keycloak main instead of displaying Action expired page.

The only thing is, in the described scenario, the user might not be anymore in the context of authenticationSession after your changes. So perhaps in that case, it may be OK to add user back to the authenticationSession based on the info from the actionToken? I can see that VerifyEmailActionToken has reference to the user, so hopefully it should be possible to restore the user in the authenticationSession.

Anyway, it will be good to add automated test for this scenario and make sure that it works as expected.

Thanks a lot for the discussion and for the additional work on handling those cases!

@mposolda

Copy link
Copy Markdown
Contributor

@vilmosnagy Any chance to continue on this PR?

@vilmosnagy

vilmosnagy commented Dec 19, 2024

Copy link
Copy Markdown
Contributor Author

Sorry for the disappearance @mposolda - a newborn just arrived to my household in the past few weeks, and I had a few things to finish at my workplace before that.

I'll try to finish this PR by the beginning of the new year - if I won't come back and push my changes to this PR by the 6th of January, then probably I won't be able to finish this in the next months.

@thomasdarimont

Copy link
Copy Markdown
Contributor

@vilmosnagy congratulations :)

@mposolda

Copy link
Copy Markdown
Contributor

@vilmosnagy Sure, take your time. Keeping this PR opened for now. Congratulations! :-)

@mposolda

Copy link
Copy Markdown
Contributor

Closing for now as PR is in the queue for very long time.
@vilmosnagy Feel free to re-open (or open new PR) once you have time. Anyone else is also welcome to eventually open the PR and continue with the work (in that case, please add the reference to this PR in the new PR).

@vilmosnagy

Copy link
Copy Markdown
Contributor Author

@mposolda reopened in #48814, and I addressed your thoughts from this review session.

vilmosnagy added a commit to vilmosnagy/keycloak that referenced this pull request May 12, 2026
- Clear the RESET_CREDENTIAL_USER_CHOSEN auth note after clearing the user,
  so subsequent login page renders do not redundantly clear again (feedback
  from @mposolda in keycloak#33254)
- Add ResetPasswordTest::resetPasswordEmailLinkWorksAfterNavigatingBackToLoginPage
  to verify that the password reset email link still works after the user
  navigates back to the login page, covering the scenario raised in the
  review discussion of keycloak#33254

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Vilmos Nagy <me@vnagy.eu>
vilmosnagy added a commit to vilmosnagy/keycloak that referenced this pull request May 29, 2026
- Clear the RESET_CREDENTIAL_USER_CHOSEN auth note after clearing the user,
  so subsequent login page renders do not redundantly clear again (feedback
  from @mposolda in keycloak#33254)
- Add ResetPasswordTest::resetPasswordEmailLinkWorksAfterNavigatingBackToLoginPage
  to verify that the password reset email link still works after the user
  navigates back to the login page, covering the scenario raised in the
  review discussion of keycloak#33254

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Vilmos Nagy <me@vnagy.eu>
vilmosnagy added a commit to vilmosnagy/keycloak that referenced this pull request Jun 3, 2026
- Clear the RESET_CREDENTIAL_USER_CHOSEN auth note after clearing the user,
  so subsequent login page renders do not redundantly clear again (feedback
  from @mposolda in keycloak#33254)
- Add ResetPasswordTest::resetPasswordEmailLinkWorksAfterNavigatingBackToLoginPage
  to verify that the password reset email link still works after the user
  navigates back to the login page, covering the scenario raised in the
  review discussion of keycloak#33254

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Vilmos Nagy <me@vnagy.eu>
vilmosnagy added a commit to vilmosnagy/keycloak that referenced this pull request Jun 10, 2026
- Clear the RESET_CREDENTIAL_USER_CHOSEN auth note after clearing the user,
  so subsequent login page renders do not redundantly clear again (feedback
  from @mposolda in keycloak#33254)
- Add ResetPasswordTest::resetPasswordEmailLinkWorksAfterNavigatingBackToLoginPage
  to verify that the password reset email link still works after the user
  navigates back to the login page, covering the scenario raised in the
  review discussion of keycloak#33254

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Vilmos Nagy <me@vnagy.eu>
vilmosnagy added a commit to vilmosnagy/keycloak that referenced this pull request Jun 16, 2026
- Clear the RESET_CREDENTIAL_USER_CHOSEN auth note after clearing the user,
  so subsequent login page renders do not redundantly clear again (feedback
  from @mposolda in keycloak#33254)
- Add ResetPasswordTest::resetPasswordEmailLinkWorksAfterNavigatingBackToLoginPage
  to verify that the password reset email link still works after the user
  navigates back to the login page, covering the scenario raised in the
  review discussion of keycloak#33254

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Vilmos Nagy <me@vnagy.eu>
rmartinc pushed a commit that referenced this pull request Jun 19, 2026
… user goes back from the reset credentials page (#48814)

* #33204 add the failing test

Signed-off-by: Vilmos Nagy <me@vnagy.eu>

* #33204 Migrated tests from the old testsuite to the new framework.

Signed-off-by: Vilmos Nagy <me@vnagy.eu>

* #33204 possible fix (?)

Signed-off-by: Vilmos Nagy <me@vnagy.eu>

* #33204 refactor the previous tests to work with the changed behaviour

Signed-off-by: Vilmos Nagy <me@vnagy.eu>

# Conflicts:
#	testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/forms/RegisterTest.java

* #33204 add test and address review feedback from #33254

- Clear the RESET_CREDENTIAL_USER_CHOSEN auth note after clearing the user,
  so subsequent login page renders do not redundantly clear again (feedback
  from @mposolda in #33254)
- Add ResetPasswordTest::resetPasswordEmailLinkWorksAfterNavigatingBackToLoginPage
  to verify that the password reset email link still works after the user
  navigates back to the login page, covering the scenario raised in the
  review discussion of #33254

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Vilmos Nagy <me@vnagy.eu>

* Remove the tests added for this PR from the old testsuite.

They were already rewritten to the new test framework with the same name.

Signed-off-by: Vilmos Nagy <me@vnagy.eu>

---------

Signed-off-by: Vilmos Nagy <me@vnagy.eu>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
sashyo pushed a commit to tide-foundation/keycloak-IGA that referenced this pull request Jul 20, 2026
… user goes back from the reset credentials page (keycloak#48814)

* keycloak#33204 add the failing test

Signed-off-by: Vilmos Nagy <me@vnagy.eu>

* keycloak#33204 Migrated tests from the old testsuite to the new framework.

Signed-off-by: Vilmos Nagy <me@vnagy.eu>

* keycloak#33204 possible fix (?)

Signed-off-by: Vilmos Nagy <me@vnagy.eu>

* keycloak#33204 refactor the previous tests to work with the changed behaviour

Signed-off-by: Vilmos Nagy <me@vnagy.eu>

# Conflicts:
#	testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/forms/RegisterTest.java

* keycloak#33204 add test and address review feedback from keycloak#33254

- Clear the RESET_CREDENTIAL_USER_CHOSEN auth note after clearing the user,
  so subsequent login page renders do not redundantly clear again (feedback
  from @mposolda in keycloak#33254)
- Add ResetPasswordTest::resetPasswordEmailLinkWorksAfterNavigatingBackToLoginPage
  to verify that the password reset email link still works after the user
  navigates back to the login page, covering the scenario raised in the
  review discussion of keycloak#33254

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Vilmos Nagy <me@vnagy.eu>

* Remove the tests added for this PR from the old testsuite.

They were already rewritten to the new test framework with the same name.

Signed-off-by: Vilmos Nagy <me@vnagy.eu>

---------

Signed-off-by: Vilmos Nagy <me@vnagy.eu>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

Identity Providers are missing from the login page if I request a reset password for an existing user

7 participants