-
Notifications
You must be signed in to change notification settings - Fork 73
Howto Keycloak OIDC
This guide configures Keycloak as an OIDC provider for Bindery. Users sign in via the Keycloak login page and are mapped to Bindery accounts by their stable Keycloak user UUID (sub).
Prerequisites:
- Keycloak v21+ running with an existing realm
- Bindery v0.24.0+
- Admin access to the Keycloak admin console
-
BINDERY_OIDC_REDIRECT_BASE_URLset to your public Bindery URL
- In the Keycloak admin console, select your realm (e.g.
myrealm). - Go to Clients → Create client.
- Fill in:
- Client type: OpenID Connect
-
Client ID:
bindery
- Click Next.
- Enable Client authentication (this makes it a confidential client with a secret).
- Authentication flow: leave Standard flow checked, uncheck everything else.
- Click Next, then Save.
Expected result: client bindery appears in the Clients list.
- Open the
binderyclient → Settings tab. - Under Valid redirect URIs, add:
https://bindery.example.com/api/v1/auth/oidc/keycloak/callback - Under Web origins, add
https://bindery.example.com. - Click Save.
- Go to the Credentials tab of the
binderyclient. - Copy the Client secret value.
To pass group membership to Bindery so you can use allowed_groups / allowed_admin_groups:
- Go to the
binderyclient → Client scopes tab → clickbindery-dedicated. - Click Add mapper → By configuration → Group Membership.
- Fill in:
-
Name:
groups -
Token Claim Name:
groups - Full group path: On
- Add to ID token: On
-
Name:
- Click Save.
Keycloak groups in the token are prefixed with / — e.g. /bindery-users. Match this exactly in allowed_groups.
environment:
BINDERY_OIDC_REDIRECT_BASE_URL: "https://bindery.example.com"Restart Bindery if adding for the first time.
Settings → Security → OIDC Providers → Add provider, or:
curl -X POST http://bindery:8787/api/v1/settings/auth/oidc/providers \
-H "X-Api-Key: <admin-key>" \
-H "Content-Type: application/json" \
-d '{
"id": "keycloak",
"name": "Keycloak",
"issuer": "https://keycloak.example.com/realms/myrealm",
"client_id": "bindery",
"client_secret": "<your-client-secret>",
"scopes": "openid email profile groups",
"allowed_groups": "/bindery-users"
}'The issuer must include the realm path — Keycloak's OIDC discovery endpoint is at <issuer>/.well-known/openid-configuration.
Expected result: Sign in with Keycloak button appears on the Bindery login page.
- Open a private window →
https://bindery.example.com/login→ click Sign in with Keycloak. - Browser redirects to Keycloak → log in.
- Keycloak redirects back to Bindery → Bindery validates the ID token, maps the user by
(https://keycloak.example.com/realms/myrealm, <keycloak-user-uuid>), provisions the account. - Confirm in Settings → Users.
The Keycloak user UUID is the stable sub claim. Renaming the Keycloak username does not change the UUID, so no orphaned accounts are created.
| Symptom | Cause | Fix |
|---|---|---|
| Bindery can't reach Keycloak discovery URL | Network/firewall blocking Bindery → Keycloak | Test: curl https://keycloak.example.com/realms/myrealm/.well-known/openid-configuration from inside the Bindery container |
invalid_client on callback |
Client secret wrong or client not confidential | Re-copy the secret from Keycloak Credentials tab; confirm Client authentication is enabled |
redirect_uri_mismatch |
Redirect URI not registered | Add https://bindery.example.com/api/v1/auth/oidc/keycloak/callback to Valid redirect URIs in Keycloak |
issuer mismatch in token validation |
issuer in Bindery config doesn't match Keycloak realm URL |
The issuer must be https://keycloak.example.com/realms/<realm-name> exactly — check the iss claim in the ID token with BINDERY_LOG_LEVEL=debug
|
allowed_groups blocks all users |
Groups not in token, or wrong format | Confirm the groups mapper is added to the client scope (step 4). Groups are /-prefixed: use /bindery-users not bindery-users
|
Users outside allowed_groups can still log in |
allowed_groups not saved to Bindery provider |
Re-check the provider config via GET /api/v1/settings/auth/oidc/providers/keycloak
|
See also: Troubleshooting — OIDC | docs/auth-oidc.md
Getting started
Setup guides
How-to guides — proxy auth (v1.0)
How-to guides — OIDC (v1.0)
- Google Sign-In
- GitHub OAuth via Dex
- Authelia as OIDC provider
- Authentik
- Keycloak
- Rotate OIDC client secrets
- Recover from broken OIDC
How-to guides — multi-user (v1.0)
Reference
Contributing