People sign in to the KIMS v2 CMS with their KIMS Keycloak accounts. The CMS is an OpenID Connect client of KIMS's existing realm: authorization code flow, PKCE (S256), and a confidential client with a secret. Keycloak decides who may sign in (the cms-access client role); the CMS's own People screen decides what they may do.
Who does what:
| Step | KIMS's Keycloak admin | Our engineer |
|---|---|---|
| Answer the open points (version, realm, verified email, network) | Yes | Asks them, using Settle these first |
| Create the client, role and settings | Yes (or gives us realm-admin rights for the day) | Gives this page; checks every setting after |
| Copy the client secret into the Kubernetes Secret | Yes, or hands it over in person | Never stores it anywhere else |
| Test discovery and the client | Yes |
One client per environment: kims-cms (production) and, if UAT exists, kims-cms-uat, each with its own cms-access role. Then access to UAT does not give access to production.
#How the CMS uses the client
Knowing this makes every setting below obvious:
| Moment | What the CMS does (code in apps/cms/src/lib/auth/) |
Keycloak endpoint |
|---|---|---|
| Start | Fetches <KEYCLOAK_ISSUER>/.well-known/openid-configuration and checks its issuer equals KEYCLOAK_ISSUER exactly |
discovery |
| Sign-in | Sends the browser to the authorization endpoint with response_type=code, scope=openid email profile, state, nonce, code_challenge and code_challenge_method=S256, and redirect_uri=<CMS_URL>/api/auth/callback/keycloak |
authorization |
| Callback | Exchanges the code server to server with the client secret (HTTP basic) and the PKCE verifier | token |
| Callback | Verifies the ID token and access token (RS256 only, issuer, audience or azp, typ), requires email_verified: true and the role cms-access in resource_access.<client id>.roles of the access token |
JWKS (keys) |
| Every request | While the 300 s access token is valid: introspects the refresh token (sees a disabled user or removed role at once). After it expires: refreshes, and the new access token must still carry cms-access |
introspection, token |
| Sign-out | Ends the Keycloak session server to server with the refresh token, then shows the CMS login page | end session |
| Keycloak ends a session | Keycloak POSTs a signed logout token to <CMS_URL>/api/auth/backchannel-logout; the CMS deletes the matching sessions |
(Keycloak calls the CMS) |
#Settle these first
Ask KIMS's Keycloak admin before creating anything:
| Question | Why it matters |
|---|---|
| Which Keycloak version? | These steps are for the 26.x admin console. Some labels moved in 26.3; versions before 19 have a different console; versions before 17 put /auth in every URL. See If KIMS runs an older Keycloak |
| Which realm? | Sets the issuer https://<KEYCLOAK_HOST>/realms/<REALM> |
| Do accounts have a verified email? (Especially accounts from Active Directory or LDAP) | The CMS refuses every sign-in without email_verified: true. The most likely thing to break. See Users |
| Can the CMS pods reach Keycloak on 443? | Discovery, keys, token, introspection and end-session calls come from the pods |
| Can Keycloak reach the CMS host on 443? | For the back-channel logout. Without it, revocation still works but less directly (Revocation) |
| Realm token and session settings | The CMS expects a 300 s access token, 30 min idle, 10 h maximum, refresh token rotation (Sessions and tokens) |
| Is the Keycloak certificate from a public CA? | The pods trust public CAs only. An internal CA needs a chart change first (Troubleshooting) |
#Read the version and the issuer
The version: in the admin console, the ? (Help) menu at the top right, Server info (or the master realm's Server info page). Ask the admin to read it out.
The issuer, from any machine that reaches Keycloak:
curl -s https://<KEYCLOAK_HOST>/realms/<REALM>/.well-known/openid-configuration | grep -o '"issuer":"[^"]*"'curl -s https://<KEYCLOAK_HOST>/realms/<REALM>/.well-known/openid-configuration | grep -o '"issuer":"[^"]*"'(Invoke-RestMethod -Uri "https://<KEYCLOAK_HOST>/realms/<REALM>/.well-known/openid-configuration").issuerYou should see "issuer":"https://<KEYCLOAK_HOST>/realms/<REALM>" (Windows prints just the URL). That exact string, character for character, is KEYCLOAK_ISSUER: same scheme, same host, no trailing slash. If it shows an internal host name (for example http://keycloak:8080/...), KIMS's Keycloak hostname setting is wrong for outside callers, and the CMS will refuse to start sign-ins: see Troubleshooting: issuer mismatch.
#Create the client
In the admin console (https://<KEYCLOAK_HOST>/admin/), choose KIMS's realm in the realm selector at the top left, then:
#Page 1: General settings
- Clients, Create client.
- Client type:
OpenID Connect. - Client ID:
kims-cms(UAT:kims-cms-uat). This isKEYCLOAK_CLIENT_ID. KIMS may have a naming rule; any ID works if the CMS gets the same one. - Name:
KIMS CMS(UAT:KIMS CMS (UAT)). Shown on Keycloak's consent and account pages. - Description:
KIMS v2 content management system. - Always display in UI: off.
- Next.
#Page 2: Capability config
- Client authentication: On. This makes it a confidential client with a secret.
- Authorization: Off.
- Authentication flow: tick Standard flow only. Untick Direct access grants, Implicit flow, Service accounts roles, OAuth 2.0 Device Authorization Grant and OIDC CIBA Grant. If shown, leave Standard Token Exchange unticked.
- PKCE Method (Keycloak 26.3 and later): S256. If your version shows a Require PKCE switch instead, turn it on (it means S256). On 26.0 to 26.2 this setting is not on this page: set it after saving, see PKCE on Keycloak before 26.3.
- If shown, leave Require DPoP bound tokens off.
- Next.
#Page 3: Login settings
Use the environment's CMS host, for example cms.kimshospitals.com, in place of <CMS_HOST>. Always https://.
| Field | Value | Why |
|---|---|---|
| Root URL | https://<CMS_HOST> |
|
| Home URL | https://<CMS_HOST>/ |
Link from Keycloak's account page |
| Valid redirect URIs | https://<CMS_HOST>/api/auth/callback/keycloak |
The only redirect the CMS uses, built from CMS_URL. The repository's notes use https://<CMS_HOST>/*, which also works; the exact path is tighter |
| Valid post logout redirect URIs | https://<CMS_HOST>/* |
The CMS ends sessions server to server and does not use a logout redirect today; this matches the reference realm and allows one later |
| Web origins | https://<CMS_HOST> |
The CMS calls Keycloak only from the server, so this is just the matching origin. Never * |
Then Save. The client opens on its Settings tab.
#Logout settings
Still on Clients, kims-cms, Settings tab, scroll to the Logout settings section:
| Field | Value |
|---|---|
| Front channel logout | Off |
| Backchannel logout URL | https://<CMS_HOST>/api/auth/backchannel-logout |
| Backchannel logout session required | On |
| Backchannel logout revoke offline sessions | On |
Save (the button at the bottom of the Settings tab).
With session required on, Keycloak puts the session id (sid) in the logout token, so the CMS ends exactly the sessions started from that Keycloak session. The CMS checks the logout token's signature, issuer, audience, the back-channel event claim, iat and jti, and refuses a token older than 10 minutes.
If Front channel logout is turned on, Keycloak 26 hides the back-channel fields. Turn it off first.
#PKCE on Keycloak before 26.3
On 26.0, 26.1 and 26.2 (and older), PKCE is under Clients, kims-cms, Advanced tab, section Advanced settings: Proof Key for Code Exchange Code Challenge Method: S256. Click that section's own Save button (each section on the Advanced tab saves separately).
The CMS always sends an S256 challenge, so sign-in also works without this setting. Setting it makes Keycloak refuse any request for this client without PKCE, which is the point.
#The client secret
Clients, kims-cms, Credentials tab:
- Client Authenticator:
Client Id and Secret. - Client Secret: the copy icon copies it.
It is KEYCLOAK_CLIENT_SECRET, and goes only into the Kubernetes Secret kims-keycloak, key client-secret (Secrets). Not into the Helm values, not into chat, email or a ticket.
Regenerate makes a new secret at once and the old one stops working. Every CMS refresh and introspection then fails until the kims-keycloak Secret is updated and the CMS pods restarted, and signed-in people see "Could not confirm your access". Regenerate only together with that update.
#The cms-access client role
Clients, kims-cms, Roles tab:
- Create role.
- Role name:
cms-access. Exactly this, unless KIMS needs another name; then setKEYCLOAK_ACCESS_ROLEto the same name in the Helm values. - Description:
May sign in to the KIMS CMS. What a person can do inside the CMS is decided by the CMS's own roles. - Save.
It must be a client role on this client, not a realm role: the CMS reads it from resource_access.<client id>.roles. Giving it to people is on Users.
#Client scopes: make sure the role reaches the token
Clients, kims-cms, Client scopes tab. Keycloak assigns the realm's default scopes to a new client. Check this list:
| Assigned client scope | Assigned type | Gives the CMS |
|---|---|---|
kims-cms-dedicated |
(dedicated) | Mappers for this client only. Usually empty |
basic (Keycloak 25 and later) |
Default | sub and auth_time |
profile |
Default | name |
email |
Default | email and email_verified |
roles |
Default | resource_access.kims-cms.roles, with cms-access |
web-origins |
Default | |
acr |
Default |
roles must be Default, not Optional. The CMS asks only for openid email profile, so an Optional scope is never included, and with no roles scope every sign-in is refused for "no access role". If it is missing: Add client scope, tick roles, Add, choose Default.
#Check the roles scope's mapper (realm-wide, only look)
Client scopes (left menu), roles, Mappers tab, client roles. It should be:
| Field | Value |
|---|---|
| Mapper type | User Client Role |
| Multivalued | On |
| Token Claim Name | resource_access.${client_id}.roles |
| Add to access token | On |
| Add to token introspection | On |
| Add to ID token | Off is fine |
These are Keycloak's defaults. If KIMS has changed this mapper realm-wide, do not change it back (other applications may rely on it); instead add a mapper of type User Client Role with these values to kims-cms-dedicated: Client scopes tab, kims-cms-dedicated, Configure a new mapper (or Add mapper, By configuration), User Client Role, Client ID kims-cms, values as above.
#Check the client
#Every setting, side by side
| Setting | Where | Expected |
|---|---|---|
| Client ID | Settings, General settings | kims-cms |
| Client authentication | Settings, Capability config | On |
| Standard flow only | Settings, Capability config | Only Standard flow ticked |
| PKCE | Settings, Capability config (26.3+) or Advanced, Advanced settings | S256 |
| Valid redirect URIs | Settings, Access settings | https://<CMS_HOST>/api/auth/callback/keycloak (or https://<CMS_HOST>/*) |
| Web origins | Settings, Access settings | https://<CMS_HOST> |
| Front channel logout | Settings, Logout settings | Off |
| Backchannel logout URL | Settings, Logout settings | https://<CMS_HOST>/api/auth/backchannel-logout |
| Backchannel logout session required | Settings, Logout settings | On |
| Client role | Roles | cms-access |
roles scope |
Client scopes | Default |
#A test user's token has the role
Once a user has cms-access (Users):
- Clients,
kims-cms, Client scopes tab, Evaluate sub-tab. - Users: pick the test user.
- Open Generated access token.
You should see:
"resource_access": {
"kims-cms": {
"roles": ["cms-access"]
}
}and, under Generated ID token, "email_verified": true and the user's email. If resource_access is missing, the roles scope is not Default on the client.
#The pods can reach Keycloak
After the first deploy, from a machine with cluster access (the same command on every system):
kubectl -n kims exec deploy/kims-cms -- node -e "fetch(process.env.KEYCLOAK_ISSUER + '/.well-known/openid-configuration').then(r => r.json()).then(d => console.log(d.issuer === process.env.KEYCLOAK_ISSUER ? 'OK issuer matches' : 'MISMATCH ' + d.issuer)).catch(e => console.log('FAILED', e.cause ? e.cause.code : e.message))"kubectl -n kims exec deploy/kims-cms -- node -e "fetch(process.env.KEYCLOAK_ISSUER + '/.well-known/openid-configuration').then(r => r.json()).then(d => console.log(d.issuer === process.env.KEYCLOAK_ISSUER ? 'OK issuer matches' : 'MISMATCH ' + d.issuer)).catch(e => console.log('FAILED', e.cause ? e.cause.code : e.message))"kubectl -n kims exec deploy/kims-cms -- node -e "fetch(process.env.KEYCLOAK_ISSUER + '/.well-known/openid-configuration').then(r => r.json()).then(d => console.log(d.issuer === process.env.KEYCLOAK_ISSUER ? 'OK issuer matches' : 'MISMATCH ' + d.issuer)).catch(e => console.log('FAILED', e.cause ? e.cause.code : e.message))"You should see OK issuer matches. MISMATCH means KEYCLOAK_ISSUER is not exactly what Keycloak says; FAILED means the pods cannot reach Keycloak or do not trust its certificate.
#Keycloak can reach the back-channel URL
Revocation: test the back-channel path.
#Hand over the values
| Value | Example | Goes into | Secret |
|---|---|---|---|
| Issuer | https://<KEYCLOAK_HOST>/realms/<REALM> |
Helm values env.KEYCLOAK_ISSUER |
No |
| Client ID | kims-cms |
Helm values env.KEYCLOAK_CLIENT_ID |
No |
| Access role | cms-access |
Helm values env.KEYCLOAK_ACCESS_ROLE (default cms-access) |
No |
| Client secret | (from the Credentials tab) | Kubernetes Secret kims-keycloak, key client-secret |
Yes |
| CMS URL | https://<CMS_HOST> |
Helm values env.CMS_URL. Must match the redirect URI's origin exactly |
No |
See Helm values and Secrets.
#UAT and production
| Setting | Production client | UAT client |
|---|---|---|
| Client ID | kims-cms |
kims-cms-uat |
| Redirect, post logout, web origins, back-channel URL | production CMS host | UAT CMS host |
cms-access role |
on kims-cms |
on kims-cms-uat (a separate role) |
| Secret | its own, in production's kims-keycloak |
its own, in UAT's kims-keycloak |
Same realm, unless KIMS keeps production in a realm of its own.
#If KIMS runs an older Keycloak
| Version | What differs |
|---|---|
| 26.0 to 26.2 | PKCE is on the Advanced tab (above). Otherwise as written |
| 25 | As 26.0. Has the basic scope |
| 19 to 24 | Same new admin console, small label differences; no basic scope (sub is always in the token anyway). On 24 the mapper toggle may read Add to token introspection or be absent (introspection then includes the roles by default) |
| 17 and 18 (Quarkus) | Older console by default. "Client authentication On" is Access Type: confidential; PKCE is Advanced Settings, Proof Key for Code Exchange Code Challenge Method; Valid Post Logout Redirect URIs does not exist (it arrived in 19) |
| 16 and older (WildFly) | All of the above, and every URL has /auth: the issuer is https://<KEYCLOAK_HOST>/auth/realms/<REALM>. Use exactly what discovery reports. These versions are out of support; tell us before relying on one |
The CMS needs only standard OIDC: discovery, PKCE S256, refresh tokens, token introspection, RS256 keys and back-channel logout with sid (Keycloak 12 and later). Refresh token rotation and the email_verified claim exist in all of these.
#If it goes wrong
See Keycloak troubleshooting. The common ones:
| What you see | Cause |
|---|---|
Keycloak page: Invalid parameter: redirect_uri |
Valid redirect URIs does not match <CMS_URL>/api/auth/callback/keycloak |
| CMS: "Your KIMS account does not have access to the CMS" for everyone | roles scope not Default, role not given, or email not verified |
| CMS: "KIMS sign-in refused the sign-in" | Wrong client secret, or Client authentication off |
#Sources
kims-v2/apps/cms/src/lib/auth/keycloak.ts,config.ts,sign-in.ts,gate.ts,pkce.ts,backchannel.tskims-v2/apps/cms/src/app/api/auth/signin/route.ts,callback/keycloak/route.ts,logout/route.ts,backchannel-logout/route.tskims-v2/local/keycloak/kims-realm.json(the reference client; secrets not copied)kims-v2/docs/CONFIG.md, Keycloakkims-v2/docs/ON-SITE-DEPLOYMENT.md(main), step 6kims-v2/deploy/helm/kims/values-production.example.yaml(main)- https://www.keycloak.org/docs/latest/server_admin/index.html (Managing OpenID Connect clients; Client scopes; Roles)
- https://www.keycloak.org/2025/07/keycloak-2630-released (PKCE setting moved to the Settings tab)
- https://www.keycloak.org/docs/latest/release_notes/index.html
- https://www.keycloak.org/server/hostname
- https://openid.net/specs/openid-connect-backchannel-1_0.html
- https://datatracker.ietf.org/doc/html/rfc7636 (PKCE)
- https://datatracker.ietf.org/doc/html/rfc7662 (token introspection)