What a Keycloak client is
In Keycloak, a client is an application or service that relies on the realm. Every app that signs users in, every API that checks tokens and every job that calls another service with its own identity has a client.
The client holds the rules for that app: which flows it may use, where Keycloak may send users back after sign-in, which browser origins may call the token endpoint, and whether it must prove who it is with a secret. Getting these right is most of the work of securing an OpenID Connect app.
Clients can be created in the admin console, through the admin API, or imported from JSON. JSON is the form that can be reviewed, kept in version control and applied the same way in every environment.
The four kinds of client this tool builds
| Kind | Runs where | Signs in with | Key settings |
|---|---|---|---|
| Public | Browser or mobile device | Authorization code flow with PKCE | publicClient: true, no secret |
| Confidential | Your server | Authorization code flow, plus a client secret | publicClient: false, clientAuthenticatorType: client-secret |
| Service account | A back-end job or service | Client credentials grant | serviceAccountsEnabled: true, standard flow off |
| Resource server | An API that only checks tokens | Nothing: it never signs anyone in | Every flow off |
The deciding question is whether the code can keep a secret. Code that runs on a user’s device cannot, because anyone can read it. Those apps are public clients and rely on PKCE instead of a secret.
How Keycloak 26 reads a client
An imported client is a JSON object in the same shape as a client in a realm export. The fields below are the ones that matter most.
{
"clientId": "web-app",
"protocol": "openid-connect",
"publicClient": true,
"standardFlowEnabled": true,
"implicitFlowEnabled": false,
"directAccessGrantsEnabled": false,
"redirectUris": ["https://app.example.com/*"],
"webOrigins": ["+"],
"attributes": {
"pkce.code.challenge.method": "S256",
"post.logout.redirect.uris": "https://app.example.com/*"
}
}Redirect URIs
Keycloak sends authorization codes only to addresses that match redirectUris. A wildcard is allowed at the end of the path only, as in https://app.example.com/*. A redirect URI of * on its own lets the client send codes anywhere and should never reach production.
Web origins
webOrigins lists the browser origins that get CORS headers from the token and UserInfo endpoints. The value + means the origins of all valid redirect URIs, so you list each site once.
Attributes
Some settings live in attributes as strings. pkce.code.challenge.method set to S256 makes PKCE required. post.logout.redirect.uris lists where users may return after logout, with several values joined by ##.
What this tool does
The generator builds the client object from a few choices and checks your input as you type.
- Sets the flags for the kind of client you pick, with the implicit flow and direct access grants off.
- Adds PKCE with S256 for browser clients when you leave that option on.
- Writes post logout redirect URIs into the right attribute.
- Can turn on the device authorization grant and user consent.
- Warns about a
*redirect URI,httpoutside localhost, a wildcard that is not at the end, and*web origins. - Lets you copy the JSON or save it as a file.
It leaves the secret out of confidential and service account clients, so Keycloak generates a new one on import. You read it afterwards on the client’s Credentials tab.
What it does not do
It does not add protocol mappers, client scopes, roles or fine-grained settings such as token lifespans per client. It does not build SAML clients; the SAML client generator does that. It never talks to your server.
How to use it
- Pick the kind of client.
- Enter the client id and a display name.
- For browser clients, enter the root URL, redirect URIs, post logout redirect URIs and web origins, one per line.
- Keep Require PKCE on unless an old library cannot send a code challenge.
- Save the file, then in the admin console open the realm, go to Clients, choose Import client and pick the file.
Where it pays off
Writing clients as JSON is most useful when the same client must exist in more than one place.
First production deploy
Generate each client once, review it, and keep the file with the app’s code. Staging and production then get the same flags, and only the addresses change.
Moving between environments
Clients copied by hand drift apart over time: a redirect URI added in one place, PKCE forgotten in another. Importing from reviewed files keeps them in step. The realm export diff shows where two realms already differ.
Cleaning up older clients
Clients created years ago often still allow the implicit flow or the password grant. Compare them with a freshly generated client of the same kind to see which flags to turn off.
Machine-to-machine access
A service account client gives a back-end job its own identity. Assign it roles on its Service account roles tab instead of sharing a person’s account.
Common errors and fixes
| Error | What it means | Fix |
|---|---|---|
| Invalid parameter: redirect_uri | The app sent a redirect URI that matches none of redirectUris. | Add the exact address, or a path wildcard at the end. |
| CORS error on the token endpoint | The page’s origin is not in webOrigins. | Add the origin, or add + and a redirect URI on that origin. |
invalid_client | A confidential client sent no secret or the wrong one. | Copy the current secret from the Credentials tab. |
unauthorized_client | The client used a grant it does not allow. | Turn on the flow it needs, such as Service accounts roles. |
| Missing parameter: code_challenge_method | PKCE is required but the app sent no code challenge. | Turn on PKCE in the app’s library. |
| Client already exists on import | A client with that client id is in the realm. | Change the client id, or update the existing client instead. |
Security notes
- List exact redirect URIs. Avoid wildcards on the host, which Keycloak does not allow anyway, and avoid
*alone. - Require PKCE for public clients. It protects the authorization code if it is intercepted.
- Leave the implicit flow off. It returns tokens in the URL, and modern libraries do not need it.
- Leave direct access grants off unless a legacy app cannot use a browser flow. That grant sends the user’s password through the app.
- Rotate a confidential client’s secret if it may have leaked, and keep it out of source control.
Best practices
- Use one client per app. Sharing a client between apps mixes their redirect URIs and sessions.
- Name clients after the app and environment only if your realms are shared; a client id of
web-appin each environment is easier to manage. - Prefer
+in web origins over listing origins twice. - Give service accounts only the roles they need.
- Keep the client JSON next to the app code and review changes like any other config.
What happened to bearer-only
Older Keycloak versions had a bearer-only switch for APIs that only check tokens. The current admin console does not show it. A client with every flow off serves the same purpose: nobody can sign in through it, and tokens can still name it as their audience through an audience mapper on the calling app’s client.