Files

34 lines
1.5 KiB
Markdown

# Keycloak
## Compose-Setup (Dev)
`docker compose --profile keycloak up -d` startet Keycloak 26 mit importiertem Realm `homebrewery`
(`docker/keycloak/realm-homebrewery.json`): Client `homebrewery` (vertraulich, Secret `dev-only-client-secret`,
PKCE S256), Benutzer `testuser` / `testuser-dev`, Admin `admin` / `admin-dev`.
```env
HB_AUTH_PROVIDERS=oidc
HB_PUBLIC_URL=http://localhost:8000
HB_OIDC_ISSUER=http://keycloak.localhost:8080/realms/homebrewery
HB_OIDC_CLIENT_ID=homebrewery
HB_OIDC_CLIENT_SECRET=dev-only-client-secret
HB_SESSION_SECRET=<mindestens 32 Byte>
```
`keycloak.localhost` löst im Browser auf den Host auf und im Compose-Netz per Alias auf Keycloak,
daher ist der Issuer für Browser und App-Container derselbe.
## Eigener Keycloak
1. Realm wählen, Client anlegen: *Client authentication* an, *Standard flow* an, Direct access grants aus.
2. *Valid redirect URIs*: `${HB_PUBLIC_URL}/auth/oidc/callback`. *Valid post logout redirect URIs*: `${HB_PUBLIC_URL}/`.
3. PKCE: *Advanced → Proof Key for Code Exchange Code Challenge Method* = `S256`.
4. Issuer: `https://<host>/realms/<realm>`. Secret unter *Credentials*.
## Geprüft
E2E gegen Keycloak 26.4 (Compose-Profil) mit laufender App:
`node scripts/oidc-e2e.mjs --idp keycloak` (bei `NODE_ENV=production` hinter http zusätzlich
`--forwarded-proto https`). Geprüft: Weiterleitung mit PKCE/state/nonce, Login, Callback, Session,
Konto `testuser`, Logout (mit `HB_OIDC_END_SESSION=true` über den `end_session_endpoint`), Fehlerfall ohne Transaktion.