Keycloak client¶
If your application signs people in itself — with next-auth, keycloak-js or as a
Spring resource server — it needs an OpenID Connect client of its own in realm
onconnect. The keycloak-client resource type creates it: one client per
environment, with your project's redirect addresses. Nothing to request from
the platform team.
Only \"may enter / may not enter\"?
Then you do not need a client of your own — the
oauth2-proxy trait protects the application without a
line of code.
1. Create the Resource¶
apiVersion: openchoreo.dev/v1alpha1
kind: Resource
metadata:
name: myproject-keycloak
namespace: onconnect
spec:
owner:
projectName: myproject
type:
kind: ClusterResourceType
name: keycloak-client
parameters:
redirectPaths: [/api/auth/callback/keycloak]
groupsClaim: true
| Parameter | Default | Meaning |
|---|---|---|
clientId |
resource name, prefixed with the project unless it already starts with it | Base of the client id, see Client id. |
publicClient |
false |
true for browser-only applications (single-page apps): no secret, PKCE (S256) enforced. Otherwise a confidential client with a secret. |
redirectPaths |
["/*"] |
Paths appended to every hostname to form the allowed redirect addresses, e.g. /api/auth/callback/keycloak. A trailing * is allowed. |
standardFlow |
true |
Authorization code flow. |
serviceAccount |
false |
Client credentials for calls the application makes on its own behalf (server to server). Confidential clients only; uses the same client id and secret. |
groupsClaim |
false |
A groups claim with full group paths (/apps/<project>, …) in ID token, access token and userinfo. |
defaultScopes |
[] |
Additional client scopes, e.g. onconnect-user-claims for lanr and institution. |
clientRolesClaim |
— | Name of a claim carrying this client's roles (ID token only). No such claim when unset. |
2. Bind it to environments¶
Like every Resource, the client needs one ResourceReleaseBinding per
environment — see Databases.
Per environment, under resourceTypeEnvironmentConfigs:
| Value | Default | Meaning |
|---|---|---|
hostnames |
[] |
Additional hostnames, e.g. one from the custom-hostname trait. |
defaultHostnames |
true |
Include the project's hostnames: <project>.app.ccc-onconnect.de in production, <project>.<environment>.test.ccc-onconnect.de elsewhere. |
clientId |
— | Replaces the complete client id in this environment, e.g. to keep an existing id. |
From hostnames and redirectPaths the platform builds the allowed redirect
addresses, web origins and post-logout redirects (https://<hostname><path>).
3. Use it in the component¶
dependencies:
resources:
- ref: myproject-keycloak
envBindings:
issuer: KEYCLOAK_ISSUER
clientId: KEYCLOAK_CLIENT_ID
clientSecret: KEYCLOAK_CLIENT_SECRET # confidential clients only
| Output | Content |
|---|---|
clientId |
client id of this environment |
clientSecret |
secret (confidential clients only) |
issuer |
https://accounts.ccc-onconnect.de/realms/onconnect — the public issuer |
internalIssuerBase |
the same realm through the in-cluster service |
jwksUri |
keys for token validation, in-cluster |
Which issuer for what: tokens carry the public issuer — validate tokens
against it and send browsers there. Calls from the server (token exchange,
userinfo, fetching keys) are better made through internalIssuerBase or
jwksUri; the public names may resolve differently from inside the cluster.
Append /protocol/openid-connect/{token,userinfo,certs,logout} to
internalIssuerBase.
Client id¶
All environments share one realm, so each environment needs its own client id:
| Environment | Client id |
|---|---|
| production | <base> |
| development, staging | <base>-<environment> |
<base> is clientId, otherwise the resource name (prefixed with the project
unless it already starts with it): myproject-keycloak stays
myproject-keycloak, sso in project myproject becomes myproject-sso.
Secret¶
Keycloak generates the secret when the client is created. New releases and promotions do not change it. Only when an environment's binding is removed does the platform delete the client in Keycloak — a new binding creates a new client with a new secret.