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.
| Value | Is it an origin? |
|---|---|
https://app.example.com | Yes |
https://app.example.com:8443 | Yes, a different origin from the one above |
http://localhost:3000 | Yes, for local development |
https://app.example.com/ | No, the trailing slash is a path |
https://app.example.com/callback | No, it has a path |
app.example.com | No, 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-Originonly if the request’s origin is allowed for the client. - The
allowed-originsclaim 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.
| Entry | Meaning |
|---|---|
+ | Allow the origin of every valid redirect URI of the client |
* | Allow every origin |
| An origin | Allow exactly that scheme, host and port |
{
"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.
- 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.
- The user signs in on Keycloak’s own pages. Still no CORS: the page and Keycloak share an origin.
- Keycloak redirects back to the app with a code. Again a navigation, so no CORS.
- 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.
- 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
/callbackare resolved against the root URL. - App schemes such as
com.example.app:/oauth2redirectadd 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
- Open the client in the admin console and copy its root URL, valid redirect URIs and web origins.
- Paste them into the tool, one URI or origin per line.
- Read the list of allowed origins and any warnings.
- Open your app, look at the
Originheader of the failing request in the browser’s network panel, and paste it into the check field. - 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.