Skip to content

Keycloak redirect URI matcher

Test whether a redirect URI matches a client’s Valid redirect URIs the way Keycloak checks it, including the trailing * wildcard.

Runs in your browser. Nothing you paste is sent to us.

Client and request

Try an example

One per line, as in the client’s settings. Sample entries are filled in.

The client’s Root URL. Entries that start with / are joined to it as written.

Used for entries that start with / when the Root URL is empty.

Result

Match: Keycloak accepts this redirect_uri
Matched by https://app.example.com/callback. Exactly equal, character for character.
compared as
https://app.example.com/callback
wildcards
allowed
https://app.example.com/callback
match exactExactly equal, character for character.
https://app.example.com/admin/*
no match wildcardDoes not start with https://app.example.com/admin/.
/silent-check-sso.html
no match exactResolved to https://app.example.com/silent-check-sso.html. Not equal. An exact entry must match every character, including the query.
http://localhost/*
no match wildcardDoes not start with http://localhost/.
Web origins are a different setting
In Web origins, + means “the origins of the valid redirect URIs” and * allows every origin. They control CORS for browser calls, not where Keycloak may redirect.
Limits of this check
This models Keycloak 26.x’s rules: exact match, a * only at the end, query and fragment ignored for wildcards, wildcards off for user info or parent-folder paths, and the loopback port rule. It does not model every percent-encoding case or client policies. Test the final setup in your realm.

How to use it

  1. Enter the redirect_uri your app sends.
  2. Paste the client’s Valid redirect URIs, one per line, and its Root URL.
  3. Read the verdict and the result for each entry.
  4. Use the examples to see how queries, dot segments and loopback ports behave.

What to know

Keycloak compares the redirect_uri as plain text against each entry. An entry is matched exactly unless it ends with *, which matches anything that starts with the part before it. A * anywhere else, such as in the host, is a plain character.

For a wildcard entry the query and fragment of the redirect_uri are ignored. Wildcards are off when the redirect_uri has user info or a parent-folder step such as .. or %2e%2e, so such URIs only match exact entries.

Entries that start with / are joined to the client’s Root URL. For http://localhost and http://127.0.0.1, Keycloak also tries the URI without its port, so native apps can listen on any port.

This tool models those rules for Keycloak 26.x; it does not run Keycloak’s code. Check the final setup in your realm.

What a redirect URI is

In the authorization code flow, the user signs in at the authorization server, and the server sends the browser back to the app with a code. The address it sends the browser to is the redirect URI. The app names it in the redirect_uri parameter of the authorization request.

The code in that redirect is valuable. Together with the client’s credentials or PKCE verifier, it buys tokens. So the server must never send it to an address the client did not register. RFC 6749 section 3.1.2 defines the redirection endpoint and requires the server to check the requested URI against the registered ones.

In Keycloak, the registered list is the client’s Valid redirect URIs setting. Every authorization request is checked against it before any sign-in page is shown.

Why strict matching matters

Loose matching is one of the oldest ways to steal authorization codes. If a server accepts any URI that starts with https://app.example.com, an attacker can try https://app.example.com.attacker.example/ or an open redirect on the real site, and the code lands somewhere it can be read.

RFC 9700, the OAuth security best current practice, says servers must compare redirect URIs by exact string matching. The one exception it allows is the port number of a localhost redirect URI for native apps. Wildcards are a convenience that goes against this, which is why it is worth knowing exactly how your server treats them.

How Keycloak matches a redirect URI

Keycloak checks the redirect_uri from the request against each entry in Valid redirect URIs. The rules below describe Keycloak 26.x as we understand them. They are what the matcher models.

Exact entries

An entry without a trailing * must equal the redirect URI character for character. That includes the scheme, the host’s spelling and case, the port, the path, a trailing slash and the query string. https://app.example.com/callback does not match https://app.example.com/callback?next=/home.

A trailing wildcard

An entry that ends in * matches any redirect URI that starts with the text before the *. For this comparison Keycloak ignores the query and fragment of the redirect URI. If the text before the * ends in a slash, the URI without that slash also matches, so https://app.example.com/admin/* accepts https://app.example.com/admin.

An entry that contains a ? is not treated as a wildcard. Its * is then a plain character.

A star anywhere else

Only a * at the very end is a wildcard. A star in the host, such as https://*.example.com/callback, is a plain character and matches only that literal text. Keycloak has no subdomain wildcards.

When wildcards are switched off

If the redirect URI has user info (a name before the host, followed by an at sign) or a path with a parent-folder step such as .. or its encoded form %2e%2e, Keycloak does not apply wildcard entries to it. Such a URI can then match only an exact entry. This closes a path-traversal trick that turned an allowed prefix into a way out of it.

Relative entries and the root URL

An entry that starts with / is joined to the client’s Root URL, as written. With Root URL https://app.example.com, the entry /silent-check-sso.html becomes https://app.example.com/silent-check-sso.html. With no Root URL, Keycloak uses the origin of its own server URL.

Loopback ports

For redirect URIs that start with http://localhost or http://127.0.0.1, Keycloak also tries the URI with its port removed. A native app can then listen on any free port, as RFC 8252 recommends, while the client registers http://127.0.0.1/callback.

An example

Here is a sample client, made up for this page, and how five redirect URIs fare against it.

Valid redirect URIs (sample)
https://app.example.com/callback
https://app.example.com/admin/*
/silent-check-sso.html
http://localhost/*
redirect_uriResultWhy
https://app.example.com/callbackMatchEqual to the first entry.
https://app.example.com/admin/reports?tab=1MatchStarts with the wildcard prefix; the query is ignored.
https://app.example.com/callback?next=/homeNo matchAn exact entry must include the query.
http://localhost:8123/cbMatchThe loopback port is ignored, then the wildcard applies.
https://app.example.com/admin/%2e%2e/privateNo matchEncoded .. turns wildcards off.

What this tool does

The matcher takes a redirect URI, a list of valid redirect URIs, the client’s Root URL and your Keycloak server URL. It applies the rules above and shows:

  • An overall verdict: whether Keycloak would accept the URI, and which entry matched.
  • The URI as compared, after dot segments such as /a/../ are removed.
  • Whether wildcards are allowed for this URI, and if not, why.
  • The port-less form it tried for a loopback address.
  • A row per entry: match or no match, exact or wildcard, and the reason.
  • Warnings for a lone *, a * in the middle of an entry, plain http outside localhost, a fragment, or capital letters in the host.

Example buttons fill in common cases, so you can see how queries, dot segments, encoded dots and loopback ports behave.

Limits of the check

The matcher models Keycloak 26.x’s rules; it does not run Keycloak’s code. It does not model every percent-encoding case, the order in which Keycloak tries entries, or client policies that add their own conditions. Use it to understand and debug, then test the final setup in your realm.

How to use the matcher

  1. Copy the redirect_uri your app sends. The authorization URL inspector can pull it out of a full authorization URL.
  2. Paste it into the first field.
  3. Copy the client’s Valid redirect URIs from the Keycloak admin console and paste them, one per line.
  4. Fill in the client’s Root URL if any entry starts with /.
  5. Read the verdict, then the row for each entry to see why it did or did not match.

Setting up redirect URIs by app type

Web apps with a back end

Register the exact callback URL for each environment, such as production and staging. One app rarely needs a wildcard; if routing sends users back to different pages, keep one callback and store the return path in your session.

Single-page apps

Register the exact callback and, if you use silent checks, the silent check page. Remember that Web origins is a separate setting: it controls which origins may call Keycloak from the browser, not where Keycloak may redirect.

Mobile apps

Use a claimed https link or a private URI scheme such as com.example.app:/callback, and register it exactly. A private scheme can be claimed by another app on the same device, so pair it with PKCE.

Desktop apps and command-line tools

Listen on a loopback address with a free port and register http://127.0.0.1/callback or http://localhost/callback. Keycloak ignores the port for these, so the app does not need a fixed one.

Errors you will see

Invalid parameter: redirect_uri

Keycloak shows this on an error page when no entry matches. It does not redirect, because it cannot trust the URI. Compare the two values character by character: a trailing slash, http versus https, a port, or a query string are the usual causes.

invalid_grant at the token endpoint

The redirect_uri in the token request must be identical to the one in the authorization request. If they differ, the code exchange fails even though sign-in worked.

Invalid redirect uri on logout

Logout uses post_logout_redirect_uri, checked against Valid post logout redirect URIs. A + there means the same list as Valid redirect URIs. See the logout URL builder.

Web origins are a different setting

Keycloak clients also have Web origins. It decides which browser origins may call Keycloak’s endpoints with CORS, for example a single-page app calling the token endpoint. In Web origins, + means the origins of the valid redirect URIs, and * allows every origin.

A + or * in Web origins has no effect on redirects. A redirect URI that fails the match stays rejected whatever Web origins says.

Security practices

  • Prefer exact entries. Every wildcard widens where a code can be sent.
  • Never use a lone * in production. It lets the client send codes anywhere.
  • If you need a wildcard, keep the prefix as long as possible and end it in a path, such as https://app.example.com/auth/*, not https://app.example.com*.
  • Use https everywhere except loopback addresses.
  • Do not put a fragment in a redirect URI; RFC 6749 does not allow it.
  • Use PKCE, so a code that leaks cannot be redeemed without the verifier.
  • Remove entries for environments and apps you no longer run.
Questions

Frequently asked questions

Why does Keycloak say Invalid parameter: redirect_uri?

The redirect_uri in the request does not match any of the client’s Valid redirect URIs. Matching is exact unless an entry ends in *. Check trailing slashes, the scheme, the port and any query string.

Can I use a wildcard for subdomains in Keycloak?

No. Only a * at the end of an entry is a wildcard. https://*.example.com/callback matches only that literal text. Add each host as its own entry.

Does a Keycloak wildcard redirect URI include query strings?

For a wildcard entry, Keycloak ignores the query and fragment of the redirect URI and compares the rest with the prefix. For an exact entry, the query must match too.

Is a lone * safe as a valid redirect URI?

No. It accepts any redirect URI, so a crafted link can send authorization codes to an attacker. Use full URIs, and short wildcards only during local development.

What do + and * mean in Keycloak Web origins?

Web origins controls CORS, not redirects. + allows the origins of the client’s valid redirect URIs. * allows every origin.

How do I register a redirect URI for a desktop app with a random port?

Register http://127.0.0.1/callback or http://localhost/callback. For these loopback addresses Keycloak also tries the URI without its port, so any port matches.

Why does my redirect URI match in the tool but fail in Keycloak?

The tool models Keycloak’s rules but does not run its code. Percent-encoding edge cases and client policies are not modeled. Also check that you pasted the list from the right client in the right realm.

Is the redirect_uri match case-sensitive?

Yes. Keycloak compares the strings as they are, so the case of the host and path must match the entry. Write hosts in lower case in both places.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.