question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

redirect_uri with # has wrong redirect

See original GitHub issue

Describe the bug

When request endpoint /auth/realms/realm-name/protocol/openid-connect/auth with # on url, the redirect merge querystring and hash params. Nowadays is common SPA applications use # on URL to make hash-based routing

Impact

The only safe way to use keycloak-js is to initialize before any router behavior.

  • It impossible to use bundle size on keycloak stuff
  • create an instance of keycloak in pages that are not necessarily needed.

Version

15.0.2

Expected behavior

Redirect with query string, and hash independently

curl 'https://keycloak-url/auth/realms/realm-name/protocol/openid-connect/auth?client_id=clientId&redirect_uri=https%3A%2F%2Fapplication-url%2F%23%2Finternal%2Furl&state=secret-state&response_mode=fragment&response_type=code&scope=openid&nonce=secret-nonce&prompt=none' -H 'cookie: cookies' -i

HTTP/2 302 
date: Mon, 29 Nov 2021 19:47:43 GMT
content-length: 0
location: https://application-url/#/internal/url?state=secret-state&session_state=secret-session&code=secret-code

Actual behavior

Redirect with query string, and hash merged independently

> curl 'https://keycloak-url/auth/realms/realm-name/protocol/openid-connect/auth?client_id=clientId&redirect_uri=https%3A%2F%2Fapplication-url%2F%23%2Finternal%2Furl&state=secret-state&response_mode=fragment&response_type=code&scope=openid&nonce=secret-nonce&prompt=none' -H 'cookie: cookies' -i

HTTP/2 302 
date: Mon, 29 Nov 2021 19:47:43 GMT
content-length: 0
location: https://application-url/#/internal/url&state=secret-state&session_state=secret-session&code=secret-code

How to Reproduce?

Request auth/realms/realm-name/protocol/openid-connect/auth with valid params, example with mocked params:

curl 'https://keycloak-url/auth/realms/realm-name/protocol/openid-connect/auth?client_id=clientId&redirect_uri=https%3A%2F%2Fapplication-url%2F%23%2Finternal%2Furl&state=secret-state&response_mode=fragment&response_type=code&scope=openid&nonce=secret-nonce&prompt=none' -H 'cookie: cookies' -i

Anything else?

More about hash router: https://krasimirtsonev.com/blog/article/deep-dive-into-client-side-routing-navigo-pushstate-hash

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:7
  • Comments:7

github_iconTop GitHub Comments

2reactions
Heromythcommented, Apr 26, 2022

The problem solved when adding client new address into keycloak admin clients page. Anyone can refer to link.

It’s just that your problem is solved. It also works with the Valid Redirect URI field set to *.

This bug is still there. It’s a different bug.

1reaction
Heromythcommented, Feb 24, 2022

We are using Keycloak 16.1.0. Suffering from this bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

redirect uri returns wrong uri - Microsoft Q&A - Microsoft Learn
I have configured 2 redirect uri for 2 different environments ... I can see that the location header in devtools has the wrong...
Read more >
Google OAuth 2 authorization - Error: redirect_uri_mismatch
The redirect URI (where the response is returned to) has to be registered in the APIs console, and the error is indicating that...
Read more >
Redirect_uri seems to be wrong - Auth0 Community
Hi, Please see the application I have setup in " Salesforce OpenId Connect 2" app for authenticating users login from salesforce application ...
Read more >
Invalid redirect uri but redirect uri are configured in client
Hi! I'm configuring a client for SSO in Google Workspace using Keycloak as IDP. Everything is working fine with the exception of logout....
Read more >
The 'redirect_uri' parameter must be a Login redirect URI in ...
This error is returned because the value of ${redirect_uri} used in authorize request is not registered in the Open ID client in Okta,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found