8000 Allow redirect URL to be different than app origin by jonkoops · Pull Request #230 · keycloak/keycloak-js · GitHub
[go: up one dir, main page]

Skip to content

Allow redirect URL to be different than app origin - #230

Merged
jonkoops merged 1 commit into
keycloak:mainfrom
jonkoops:redirect-auth
Dec 9, 2025
Merged

jonkoops merged 1 commit into
keycloak:mainfrom
jonkoops:redirect-auth

Conversation

@jonkoops
@jonkoops jonkoops commented Dec 4, 2025
Copy link
Copy Markdown
Contributor

This fixes a regression that was introduced by 82924d0, which has now been partially reverted, restoring the original behavior. A regression test has also been added to ensure correctness in the future.

Closes #189

Closes keycloak#189

Signed-off-by: Jon Koops <jonkoops@gmail.com>
@jonkoops
jonkoops commented Dec 4, 2025
Copy link
Copy Markdown
Contributor Author

@markusheiden @ikkentim Since this issue affects your applications, could you please test these changes, and leave a review for me?

Copilot AI 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.

Pull request overview

This PR fixes a regression introduced in commit 82924d0 that prevented redirect URLs from being on a different domain than the application origin. The fix restores the original behavior by renaming an internal variable to avoid confusion and correcting the hash fragment handling to preserve non-OAuth parameters.

  • Renames internal redirectUri property to newUrl to distinguish it from the configured redirect URI stored in OAuth state
  • Fixes hash fragment handling to preserve non-OAuth parameters instead of clearing them entirely
  • Adds comprehensive regression test with a simulated redirect service middleware

Reviewed changes

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

File Description
lib/keycloak.js Renames callback property from redirectUri to newUrl and fixes fragment mode to preserve non-OAuth params, making it consistent with query mode behavior
test/tests/login-with-redirect.spec.ts Adds regression test simulating authentication flow through an intermediate redirect service on a different domain
test/support/common.ts Adds REDIRECT_SERVICE_URL constant for the redirect service hostname used in tests
test/app/app.ts Implements middleware to simulate a redirect service that forwards OAuth callbacks back to the application origin

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/app/app.ts Resolved
@markusheiden
Copy link
Copy Markdown

@jonkoops Your fix works for me. Thanks for fixing!

@jonkoops
jonkoops commented Dec 8, 2025
Copy link
Copy Markdown
Contributor Author

@keycloak/core-clients could I get a review please?

8000
@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 @jonkoops! Just a suggestion to the test.


// After login, the user should be authenticated.
expect(await executor.initializeAdapter(initOptions)).toBe(true)
expect(await executor.isAuthenticated()).toBe(true)
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.

Maybe check that the final url is the app one:

Suggested change
expect(await executor.isAuthenticated()).toBe(true)
expect(await executor.isAuthenticated()).toBe(true)
expect(page.url()).toBe(new URL(appUrl.origin).toString())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Currently, navigation happens in the background implicitly. So there should be no need to do this. That said, I kind of want to refactor this, so that any navigation is handled explicitly. However, that is a topic separate from this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Logged an issue for it #232

@jonkoops
jonkoops merged commit 5910f54 into keycloak:main Dec 9, 2025
10 checks passed
@jonkoops
jonkoops deleted the redirect-auth branch December 9, 2025 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

replaceState fails since 26.2.1

4 participants

0