Skip to content

Keycloak web origins and CORS helper

Work out which browser origins a Keycloak client allows for CORS, from its redirect URIs and web origins, and check one origin against them.

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

Client settings

Used for relative redirect URIs. Made-up values are filled in.

+ adds the origin of every redirect URI; * allows all.

Allowed origins

Origins Keycloak allows for CORS
https://app.example.com
https://staging.example.com:8443
https://admin.example.com
From redirect URIs (+)
https://app.example.com, https://staging.example.com:8443
com.example.app:/oauth2redirect is not an http(s) address (for example an app scheme), so it adds no origin.

What the browser sends in the Origin header, such as https://app.example.com.

Allowed
https://staging.example.com:8443 gets CORS headers from the token, UserInfo and other endpoints.

3 origins

Web origins also fill the allowed-origins claim in access tokens, which some adapters check. The port is part of the origin: https://app.example.com and https://app.example.com:443 are written differently, so match what the browser sends.

How to use it

  1. Enter the client’s root URL, redirect URIs and web origins.
  2. Read the list of origins Keycloak allows.
  3. Type the origin your browser sends and see whether it passes.

What to know

Web origins decide which websites may call Keycloak’s token and UserInfo endpoints from a browser. Keycloak answers those origins with CORS headers and lists them in the allowed-origins claim of access tokens.

The value + adds the origin of every valid redirect URI, so you list each site once. * allows every origin and is rarely what you want.

An origin is the scheme, host and port only, with no path or trailing slash. https://app.example.com/ with a slash is not an origin.

What web origins are

Browsers do not let a page on one site read responses from another site unless that other site says it may. This rule is the same-origin policy, and the permission is called CORS, for cross-origin resource sharing.

A single-page app on https://app.example.com that signs users in with Keycloak on https://auth.example.com is exactly that case. After the redirect back, the app calls Keycloak’s token endpoint from JavaScript to exchange the code for tokens. The browser only hands over the answer if Keycloak replies with CORS headers that name the app’s origin.

Web origins are the client setting that decides which origins get those headers. If the app’s origin is missing, sign-in fails right after the redirect, with a CORS error in the browser console and nothing useful on the screen.

What counts as an origin

An origin is a scheme, a host and a port, and nothing more. No path, no query, no trailing slash.

ValueIs it an origin?
https://app.example.comYes
https://app.example.com:8443Yes, a different origin from the one above
http://localhost:3000Yes, for local development
https://app.example.com/No, the trailing slash is a path
https://app.example.com/callbackNo, it has a path
app.example.comNo, it has no scheme

The port matters. Browsers leave out the default port when they send the Origin header, so https://app.example.com is what arrives, never https://app.example.com:443. Write origins the way the browser sends them.

How Keycloak 26 handles web origins

Each OpenID Connect client has a list of web origins. Keycloak uses it in two places.

  • CORS headers: when a browser calls endpoints such as the token or UserInfo endpoint, Keycloak answers with Access-Control-Allow-Origin only if the request’s origin is allowed for the client.
  • The allowed-origins claim in access tokens: Keycloak lists the client’s allowed origins there. Some adapters and APIs read it to apply the same rule on their side.

Two special values save typing and mistakes.

EntryMeaning
+Allow the origin of every valid redirect URI of the client
*Allow every origin
An originAllow exactly that scheme, host and port
A client in a realm import
{
  "clientId": "web-app",
  "publicClient": true,
  "redirectUris": ["https://app.example.com/*"],
  "webOrigins": ["+"]
}

With +, the client above allows https://app.example.com, taken from its redirect URI. Add another redirect URI on a new host and that origin is allowed too.

Where CORS shows up in a browser sign-in

Not every step of a sign-in is a cross-origin call. Knowing which ones are helps you read errors.

  1. The app sends the user to the authorization endpoint. This is a full page navigation, so CORS does not apply. Errors here are about the client id or the redirect URI.
  2. The user signs in on Keycloak’s own pages. Still no CORS: the page and Keycloak share an origin.
  3. Keycloak redirects back to the app with a code. Again a navigation, so no CORS.
  4. The app’s JavaScript posts the code to the token endpoint. This is a cross-origin request, and it needs the app’s origin in web origins.
  5. Later calls from JavaScript, such as refreshing tokens or reading UserInfo, need the same permission.

So if sign-in fails only after the redirect back to the app, web origins are the first thing to check.

What this tool does

You paste a client’s root URL, valid redirect URIs and web origins. The tool works out the list of origins Keycloak would allow, the same way + does, and shows which redirect URIs added which origin.

  • Relative redirect URIs such as /callback are resolved against the root URL.
  • App schemes such as com.example.app:/oauth2redirect add no origin, because they are not web addresses.
  • A bare * redirect URI is flagged as unsafe, and a wildcard in the host is flagged as not allowed.
  • Entries in web origins that are not real origins, such as a value with a path or a trailing slash, are flagged.

Then you type the origin your browser sends, and the tool says whether it passes.

What it does not do

It does not call Keycloak and cannot see the client’s saved settings. It models the matching rules on what you paste. It does not cover other CORS layers, such as a proxy that adds or strips headers, or your own API’s CORS settings.

How to use it

  1. Open the client in the admin console and copy its root URL, valid redirect URIs and web origins.
  2. Paste them into the tool, one URI or origin per line.
  3. Read the list of allowed origins and any warnings.
  4. Open your app, look at the Origin header of the failing request in the browser’s network panel, and paste it into the check field.
  5. If it does not pass, add it to web origins, or add a redirect URI on that origin and keep +.

Where it helps

A new single-page app

Public clients for React, Angular or Vue apps call the token endpoint from the browser. They need their origin in web origins from the first day, and + is usually the simplest correct value.

Local development

Developers run apps on http://localhost with different ports. Each port is a separate origin. Add a redirect URI for each one in a development client, rather than opening a production client to every origin.

Moving an app to a new domain

When the app moves, its origin changes. Add the new redirect URI before the switch; with + the origin follows automatically. Remove the old one after the move.

Promoting a realm between environments

Clients copied from staging to production often keep staging origins. Check web origins in every promoted client, and use a realm export diff to spot leftovers.

Common errors and fixes

No Access-Control-Allow-Origin header on the token request

The app’s origin is not allowed for the client. Add it to web origins or add + with a matching redirect URI. Remember that https://app.example.com/ with a slash is not the same entry as https://app.example.com.

It works on one port and not another

Ports are part of the origin. http://localhost:3000 and http://localhost:5173 are different. Add each one you use.

CORS error that is really a different error

If Keycloak or the proxy returns an error page without CORS headers, the browser reports a CORS failure even though the real problem is elsewhere, such as a wrong URL or a 502 from the proxy. Look at the response status in the network panel before you change web origins.

Invalid redirect URI rather than CORS

That error happens earlier, at the authorization endpoint, and is about valid redirect URIs, not web origins. Check the redirect URI list first.

Security notes

  • Avoid *. It lets any website call the token endpoint for the client from a visitor’s browser.
  • Keep redirect URIs exact and narrow. With +, a loose redirect URI also widens the allowed origins.
  • Web origins do not replace PKCE or exact redirect URIs. They only control which pages may read responses in the browser.
  • Remove origins of retired apps and old domains.

Best practices

  • Use + and keep the redirect URI list accurate, so there is one list to maintain.
  • Add explicit origins only for pages that call Keycloak but are never a redirect target.
  • Keep development origins in a separate client from production.
  • Write origins exactly as the browser sends them: scheme, host, port only when it is not the default.
Questions

Frequently asked questions

Why do I get a CORS error from the Keycloak token endpoint?

The page’s origin is not in the client’s web origins. Add it, or add `+` so the origins of the client’s redirect URIs are allowed. Check that the entry has no path or trailing slash.

What does + mean in Keycloak web origins?

It allows the origin of every valid redirect URI of the client. You keep one list, the redirect URIs, and the allowed origins follow it.

Is * in web origins safe?

Rarely. It lets any website call Keycloak’s endpoints for that client from a visitor’s browser. Use `+` or a list of exact origins instead.

What is the difference between valid redirect URIs and web origins?

Valid redirect URIs decide where Keycloak may send the user after sign-in. Web origins decide which websites may read Keycloak’s responses from JavaScript. A browser app usually needs both.

Should a web origin end with a slash?

No. An origin is only the scheme, host and port, such as `https://app.example.com`. A trailing slash makes it a path, and it no longer matches what the browser sends.

Do I need web origins for a server-side app?

Usually not. A server-side app exchanges the code from its back end, where CORS does not apply. Web origins matter when JavaScript in the browser calls Keycloak directly.

What is the allowed-origins claim in a Keycloak token?

A list of the client’s allowed web origins, written into access tokens. Some adapters and APIs read it to apply the same CORS rule on their side.

How do I allow localhost in Keycloak web origins?

Add the exact origin, such as `http://localhost:3000`, or add a redirect URI on it and use `+`. Each port is a separate origin, and it is best kept in a development client.

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.