blog: Keycloak "Invalid parameter: redirect_uri" — every cause and fix - #356
Draft
xgp wants to merge 2 commits into
Draft
blog: Keycloak "Invalid parameter: redirect_uri" — every cause and fix#356xgp wants to merge 2 commits into
xgp wants to merge 2 commits into
Conversation
Queue item A1, first of the error-message troubleshooting cluster. Someone pastes an error string into a search engine at 2am; this is the page that should be waiting for them. Written against a live Keycloak 26.7.3. Every row of every matching table was produced by probing the authorization endpoint, not read off a spec: - Exact registrations reject a trailing slash, a different case, or any query string. - The `*` wildcard is a substring wildcard, not a path wildcard: `/cb*` matches `/cbXYZ` and `/cb/deep`, and `/a/*` matches `/a` itself. - Trailing slashes are significant in both directions: `http://host:3000` and `http://host:3000/` are different registrations and neither matches the other. - Keycloak rejects any redirect_uri containing a `?` regardless of the registered pattern — we tried `/*`, `/cb*` and `/cb?*` and all three refuse. Apps sending their own callback query parameters need to move that data into `state`. Also documents the server-side log line (error="invalid_redirect_uri" with the exact rejected URI), which is the fastest path to a diagnosis and is not mentioned in the error page the user sees. Includes a curl one-liner that checks a redirect URI without a browser, which is how the tables were generated.
Deploying phasetwo-docs with
|
| Latest commit: |
6338a24
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://3e671114.phasetwo-docs.pages.dev |
| Branch Preview URL: | https://content-2026-w1-redirect-uri.phasetwo-docs.pages.dev |
Moves the publication date forward to Wednesday 2 September.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Keycloak "Invalid parameter: redirect_uri" — Every Cause and Fix
Queue item A1, first of the error-message troubleshooting cluster. The pattern: someone pastes a literal error string into a search engine at 2am, in a moment of acute pain. These posts are short, hard to get wrong, and convert unusually well because the reader is actively broken.
Everything here was tested, not read off a spec
Written against a live Keycloak 26.7.3. Every row of every table was produced by probing the authorization endpoint against clients registered with different patterns. Findings that are genuinely non-obvious:
1.
*is a substring wildcard, not a path wildcard./cb*matches/cbXYZand/cb/deep— it crosses the/boundary. And/a/*matches bare/a.2. Trailing slashes are significant in both directions.
http://host:3000andhttp://host:3000/are different registrations, and neither matches the other. If you don't know which form your library sends, register both.3. Keycloak rejects any
redirect_uricontaining a?— regardless of what you registered.http://localhost:3000/*.../cb?tenant=acmehttp://localhost:3000/cb*.../cb?tenant=acmehttp://localhost:3000/cb?*.../cb?tenant=acmeWe tried to register our way around it and could not. Apps that put their own parameters on the callback URL — a tenant hint, a "return to this page" pointer — have to move that data into
state. The post shows how, and explains thatstateis the correct mechanism anyway since it also carries CSRF protection.4. The server log names the rejected URI; the error page deliberately doesn't.
The browser can't be shown this without turning the login endpoint into an open redirector. Grepping for
invalid_redirect_uriresolves most cases in seconds, and almost nobody knows the line exists. This is the single most useful thing in the post.Also included
curlone-liner that tests a redirect URI without a browser — exactly how the tables were generated. Turns a click-and-reload loop into a one-second check.kcadm.sh/ Terraform snippets so URIs stop drifting between environments.Verification
pnpm buildpassesNote
The closing CTA originally linked to
/tutorials/, which ships in #355. Removed here so the link checker passes on this branch — worth adding once #355 merges.