Skip to content

Keycloak OIDC client JSON generator

Generate an OpenID Connect client for Keycloak as JSON you can import: a public app, a confidential web app, a service account or an API that only checks tokens.

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

Client

Made-up values are filled in.

+ means every origin of the redirect URIs.

Client JSON

web-app.json
{
  "clientId": "web-app",
  "name": "Web app",
  "enabled": true,
  "protocol": "openid-connect",
  "publicClient": true,
  "standardFlowEnabled": true,
  "implicitFlowEnabled": false,
  "directAccessGrantsEnabled": false,
  "serviceAccountsEnabled": false,
  "consentRequired": false,
  "frontchannelLogout": true,
  "rootUrl": "https://app.example.com",
  "baseUrl": "https://app.example.com",
  "redirectUris": [
    "https://app.example.com/*"
  ],
  "webOrigins": [
    "+"
  ],
  "attributes": {
    "pkce.code.challenge.method": "S256",
    "post.logout.redirect.uris": "https://app.example.com/*"
  }
}
How to import it
In the admin console, open the realm, then Clients, Import client, and choose this file. Or put the object in the clients list of a realm import file.

How to use it

  1. Pick the kind of client.
  2. Enter the client id, root URL and redirect URIs.
  3. Set web origins and whether PKCE is required.
  4. Save the file and import it under Clients, Import client.

What to know

Single-page and mobile apps cannot keep a secret, so they are public clients that use the authorization code flow with PKCE. Server-side apps are confidential and authenticate with a secret.

A service account client signs in as itself with the client credentials grant, for machine-to-machine calls. An API that only checks tokens needs no flows at all.

The generated client leaves the secret out, so Keycloak creates a new one, and turns off the implicit flow and direct access grants, which modern apps do not need.

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

KindRuns whereSigns in withKey settings
PublicBrowser or mobile deviceAuthorization code flow with PKCEpublicClient: true, no secret
ConfidentialYour serverAuthorization code flow, plus a client secretpublicClient: false, clientAuthenticatorType: client-secret
Service accountA back-end job or serviceClient credentials grantserviceAccountsEnabled: true, standard flow off
Resource serverAn API that only checks tokensNothing: it never signs anyone inEvery 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.

A public client for the sample app at app.example.com
{
  "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, http outside 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

  1. Pick the kind of client.
  2. Enter the client id and a display name.
  3. For browser clients, enter the root URL, redirect URIs, post logout redirect URIs and web origins, one per line.
  4. Keep Require PKCE on unless an old library cannot send a code challenge.
  5. 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

ErrorWhat it meansFix
Invalid parameter: redirect_uriThe 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 endpointThe page’s origin is not in webOrigins.Add the origin, or add + and a redirect URI on that origin.
invalid_clientA confidential client sent no secret or the wrong one.Copy the current secret from the Credentials tab.
unauthorized_clientThe client used a grant it does not allow.Turn on the flow it needs, such as Service accounts roles.
Missing parameter: code_challenge_methodPKCE is required but the app sent no code challenge.Turn on PKCE in the app’s library.
Client already exists on importA 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-app in 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.

Questions

Frequently asked questions

Should my Keycloak client be public or confidential?

Public if the code runs on the user’s device, such as a single-page app or a mobile app. Confidential if it runs on a server you control and can keep a secret. Public clients should require PKCE.

How do I import a client JSON into Keycloak?

Open the realm in the admin console, go to Clients and choose Import client. Pick the JSON file, check the fields and save. You can also add the object to the `clients` list of a realm import file.

How do I make PKCE required for a Keycloak client?

Set the attribute `pkce.code.challenge.method` to `S256`. In the admin console the same setting is on the client’s Advanced tab. Requests without a code challenge are then refused.

Why does Keycloak say invalid redirect_uri?

The redirect URI the app sent does not match any of the client’s valid redirect URIs. Matching is exact, except for a wildcard at the end of the path. Check scheme, host, port and path.

Where is the client secret after import?

If the JSON has no `secret`, Keycloak generates one. Open the client in the admin console and read it on the Credentials tab, where you can also regenerate it.

What is a service account client in Keycloak?

A confidential client with service accounts turned on. It gets tokens for itself with the client credentials grant, without any user. You assign roles to it like you would to a user.

What does + mean in web origins?

It allows the origin of every valid redirect URI of the client. It saves listing the same sites twice and keeps the two lists in step.

Can I create a bearer-only client in Keycloak 26?

The current admin console has no bearer-only switch. Create a client with every flow turned off instead. Nobody can sign in through it, and other clients can add it to their tokens’ audience.

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.