Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
fc30448
Move auth flow to backend
jurei733 Oct 2, 2025
bba6239
Update the README with a new section explaining the Keycloak OAuth2 A…
jurei733 Oct 9, 2025
f7f4e20
Fixes security issue for the untrusted URL redirect vulnerability
jurei733 Nov 19, 2025
7949c7e
Fixes the type confusion vulnerability in the auth controller callbac…
jurei733 Nov 19, 2025
459a33f
Fixes the server-side URL redirect vulnerability in the authenticatio…
jurei733 Nov 19, 2025
68c7d86
Ensure that JWT_SECRET infrastructure is dismantled since Keycloak no…
jurei733 Nov 19, 2025
2a8b463
Fix the authentication crash issue by adding safe decodeURIComponent …
jurei733 Nov 19, 2025
6f39641
Fix the authentication callback error handling issue
jurei733 Nov 19, 2025
d3fd60a
Refactor that Keycloak configuration values (keycloakUrl, keycloakRea…
jurei733 Nov 19, 2025
f0fb06c
Configure the routing through environment variables instead of hard-c…
jurei733 Nov 19, 2025
2ce46f0
Remove processing of obsolete environment variable 'JWT_SECRET'
svwolter Jan 30, 2026
02fabcc
Rename 'KEYCLOAK_URL' to 'OIDC_PROVIDER_URL'
svwolter Feb 2, 2026
89c07d7
Rename 'KEYCLOAK_REALM' to 'OIDC_REALM'
svwolter Feb 2, 2026
81f1210
Rename 'KEYCLOAK_CLIENT_ID' to 'OAUTH2_CLIENT_ID'
svwolter Feb 2, 2026
3390e4a
Rename 'KEYCLOAK_CLIENT_SECRET' to 'OAUTH2_CLIENT_SECRET'
svwolter Feb 2, 2026
3110a14
Generalize Keycloak integration to OIDC
svwolter Feb 3, 2026
8de99b6
Roll back the 'Nginx OIDC runtime configuration'
svwolter Feb 3, 2026
3c0b54c
Delete obsolete docker compose environment variable 'API_HOST'
svwolter Feb 5, 2026
deb47b0
Revise processing of docker compose environment variable 'BACKEND_CAL…
svwolter Feb 5, 2026
c41e3cd
Revise docker compose environment files
svwolter Feb 6, 2026
1839c7a
Revise install script
svwolter Feb 9, 2026
243f036
Add initial coding box keycloak realm
svwolter Feb 17, 2026
639c608
Move auth flow to backend
jurei733 Oct 2, 2025
2ac1ec6
Implement PKCE support for OIDC authentication flow, overhaul backend…
jurei733 Mar 10, 2026
a6ab395
Add keycloak dev environment
svwolter Mar 23, 2026
61d26d9
Add Postgres 14 image pull to dev makefile
jurei733 Mar 27, 2026
c747f0b
Add "admin" role to coding-box-realm configuration
jurei733 Mar 27, 2026
2df579c
Update README with Keycloak realm setup and timestamp replacement steps
jurei733 Apr 11, 2026
efd46a8
Add comprehensive documentation for OIDC authentication flow, includi…
jurei733 Apr 11, 2026
8612c7c
Remove unnecessary "peer" field entries and dependency "path-to-regex…
jurei733 Apr 11, 2026
105aa79
Add initial .env file with configuration values for Redis, Postgres, …
jurei733 Apr 11, 2026
62164cd
Update default admin credentials and document them for local developm…
jurei733 Apr 11, 2026
a8d7f48
Refactor workspace creation and testing for consistency and enhanced …
jurei733 Apr 13, 2026
d5c8051
Fix OAuth redirect validation
jurei733 Apr 28, 2026
e3a6923
test: allow docx integration test more time
jurei733 Apr 28, 2026
6f11872
Fix OIDC rebase conflict regressions
jurei733 Jun 1, 2026
3a855c2
fix backend oidc and workspace token auth
jurei733 Jun 2, 2026
1423c58
add replay-safe coding job endpoints
jurei733 Jun 2, 2026
679f4a7
update frontend oidc token handling
jurei733 Jun 2, 2026
e59df91
configure frontend redirect port in dev compose
jurei733 Jun 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
## Version
TAG=latest

## Image Registry Path
# Docker Hub: (aka registry-1.docker.io/) leave REGISTRY_PATH value empty!
# Docker Hub Proxy: scm.cms.hu-berlin.de:443/iqb/dependency_proxy/containers/
# GitLab: scm.cms.hu-berlin.de:4567/iqb/coding-box/
REGISTRY_PATH=scm.cms.hu-berlin.de:443/iqb/dependency_proxy/containers/

## Redis
REDIS_PORT=6379

## Database
POSTGRES_PORT=5432
POSTGRES_USER=root
POSTGRES_PASSWORD=root-password
POSTGRES_DB=coding-box

## Backend
API_PORT=3333
JWT_SECRET=random_string
AUTH_MODE=dev

## Frontend
HTTP_PORT=4200

## Infrastructure
SERVER_NAME=localhost

# OpenID Connect (OIDC)
OIDC_PROVIDER_URL=https://keycloak.kodierbox.iqb.hu-berlin.de
OIDC_ISSUER=https://keycloak.kodierbox.iqb.hu-berlin.de/realms/coding-box
OIDC_ACCOUNT_ENDPOINT=https://keycloak.kodierbox.iqb.hu-berlin.de/realms/coding-box/account
OIDC_AUTHORIZATION_ENDPOINT=https://keycloak.kodierbox.iqb.hu-berlin.de/realms/coding-box/protocol/openid-connect/auth
OIDC_TOKEN_ENDPOINT=https://keycloak.kodierbox.iqb.hu-berlin.de/realms/coding-box/protocol/openid-connect/token
OIDC_USERINFO_ENDPOINT=https://keycloak.kodierbox.iqb.hu-berlin.de/realms/coding-box/protocol/openid-connect/userinfo
OIDC_END_SESSION_ENDPOINT=https://keycloak.kodierbox.iqb.hu-berlin.de/realms/coding-box/protocol/openid-connect/logout
OIDC_JWKS_URI=https://keycloak.kodierbox.iqb.hu-berlin.de/realms/coding-box/protocol/openid-connect/certs
OAUTH2_CLIENT_ID=coding-box
OAUTH2_CLIENT_SECRET=
OAUTH2_REDIRECT_URL=//localhost:3333/api/auth/callback

# Keycloak
## Realm Admin
ADMIN_NAME=admin
ADMIN_PASSWORD=change_me

# Keycloak DB
KEYCLOAK_DB_USER=keycloak
KEYCLOAK_DB_PASSWORD=change_me
KEYCLOAK_DB_NAME=keycloak
15 changes: 14 additions & 1 deletion .env.coding-box.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ REGISTRY_PATH=

## Database
POSTGRES_USER=root
POSTGRES_PASSWORD=root-password
POSTGRES_PASSWORD=change_me
POSTGRES_DB=coding-box

## Backend
Expand All @@ -20,3 +20,16 @@ JWT_SECRET=random_string
## Infrastructure
SERVER_NAME=hostname.de
TRAEFIK_DIR=

# OpenID Connect (OIDC)
OIDC_PROVIDER_URL=https://keycloak.${SERVER_NAME}
OIDC_ISSUER=https://keycloak.${SERVER_NAME}/auth/realms/iqb
OIDC_ACCOUNT_ENDPOINT=https://keycloak.${SERVER_NAME}/auth/realms/iqb/account
OIDC_AUTHORIZATION_ENDPOINT=https://keycloak.${SERVER_NAME}/auth/realms/iqb/protocol/openid-connect/auth
OIDC_TOKEN_ENDPOINT=https://keycloak.${SERVER_NAME}/auth/realms/iqb/protocol/openid-connect/token
OIDC_USERINFO_ENDPOINT=https://keycloak.${SERVER_NAME}/auth/realms/iqb/protocol/openid-connect/userinfo
OIDC_END_SESSION_ENDPOINT=https://keycloak.${SERVER_NAME}/auth/realms/iqb/protocol/openid-connect/logout
OIDC_JWKS_URI=https://keycloak.${SERVER_NAME}/auth/realms/iqb/protocol/openid-connect/certs
OAUTH2_CLIENT_ID=coding-box
OAUTH2_CLIENT_SECRET=change_me
OAUTH2_REDIRECT_URL=//${SERVER_NAME}/api/auth/callback
30 changes: 30 additions & 0 deletions .env.dev.template
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ POSTGRES_DB=coding-box
## Backend
API_PORT=3333
JWT_SECRET=random_string
AUTH_MODE=dev
# Optional override if GeoGebra changes the public bundle URL.
# GEOGEBRA_BUNDLE_DOWNLOAD_URL=https://download.geogebra.org/package/geogebra-math-apps-bundle

Expand All @@ -27,3 +28,32 @@ HTTP_PORT=4200

## Infrastructure
SERVER_NAME=localhost

# OpenID Connect (OIDC)
OIDC_PROVIDER_URL=http://${SERVER_NAME}:8080
OIDC_ISSUER=http://${SERVER_NAME}:8080/realms/coding-box
OIDC_ACCOUNT_ENDPOINT=http://${SERVER_NAME}:8080/realms/coding-box/account
OIDC_AUTHORIZATION_ENDPOINT=http://${SERVER_NAME}:8080/realms/coding-box/protocol/openid-connect/auth
OIDC_TOKEN_ENDPOINT=http://keycloak:8080/realms/coding-box/protocol/openid-connect/token
OIDC_USERINFO_ENDPOINT=http://keycloak:8080/realms/coding-box/protocol/openid-connect/userinfo
OIDC_END_SESSION_ENDPOINT=http://keycloak:8080/realms/coding-box/protocol/openid-connect/logout
OIDC_JWKS_URI=http://keycloak:8080/realms/coding-box/protocol/openid-connect/certs
OAUTH2_CLIENT_ID=coding-box
OAUTH2_CLIENT_SECRET=change_me
OAUTH2_REDIRECT_URL=//${SERVER_NAME}:${API_PORT}/api/auth/callback

# Keycloak
## Realm Admin
ADMIN_NAME=admin
ADMIN_PASSWORD=change_me

# Keycloak DB
KEYCLOAK_DB_USER=keycloak
KEYCLOAK_DB_PASSWORD=change_me
KEYCLOAK_DB_NAME=keycloak

# Keycloak Backend Configuration
KEYCLOAK_URL=http://${SERVER_NAME}:8080/
KEYCLOAK_REALM=coding-box
KEYCLOAK_CLIENT_ID=coding-box
KEYCLOAK_CLIENT_SECRET=change_me
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ docker.env
.DS_Store
Thumbs.db

# Keycloak files
config/keycloak/realm/coding-box-realm.config

# Backend files
auth.constants.ts
database.constants.ts
Expand Down
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,39 @@ Stellen Sie sicher, dass die folgenden Tools auf Ihrem System installiert sind:
cp .env.dev.template .env.dev
```

2. Installieren Sie die Abhängigkeiten:
2. Kopieren Sie die Vorlage der Keycloak-Realm-Konfiguration:

```
cp config/keycloak/realm/coding-box-realm.config.template config/keycloak/realm/coding-box-realm.config
```

3. Ersetzen Sie den Shell-Befehl für den Timestamp durch einen numerischen Wert:

Öffnen Sie die Datei `config/keycloak/realm/coding-box-realm.config` und ersetzen Sie
`CODING_BOX_ADMIN_CREATED_TIMESTAMP=date --utc +"%s%3N"`
durch einen aktuellen Timestamp in Millisekunden, z.B.:
`CODING_BOX_ADMIN_CREATED_TIMESTAMP=1775907461877`

4. Installieren Sie die Abhängigkeiten:

```
npm install
```

5. **Standard-Anmeldedaten für die Entwicklung**

Nach dem Start der Umgebung sind folgende Standard-Anmeldedaten verfügbar:

- **Keycloak Admin Console** (http://localhost:8080/admin):
- Benutzername: `admin`
- Passwort: `change_me`

- **Kodierbox Realm** (http://localhost:8080/realms/coding-box):
- Benutzername: `coding-box-admin`
- Passwort: `change_me`

**Wichtig:** Ändern Sie diese Passwörter nach dem ersten Login aus Sicherheitsgründen.

---

## Entwicklungsprozess
Expand Down Expand Up @@ -214,6 +241,30 @@ und geben Sie danach folgenden Befehl zum Hochfahren der Webanwendung ein:
make coding-box-up
```

## Authentication

### Keycloak Auth Flow (OIDC + PKCE)

Die Anwendung nutzt **Keycloak** als Identity Provider mit dem **OAuth2 Authorization Code Flow** und **PKCE**:

1. **Login starten** (`GET /api/auth/login`): Backend erzeugt `state` und PKCE (`code_verifier`, `code_challenge`) und leitet zum Keycloak‑Login weiter.
2. **Benutzer‑Login**: Nutzer meldet sich bei Keycloak an (Passwort, SSO, etc.).
3. **Callback** (`GET /api/auth/callback`): Keycloak liefert `code` und `state` zurück.
4. **Token‑Exchange**: Backend tauscht `code` gegen Tokens am Keycloak‑Token‑Endpoint, mit PKCE `code_verifier` (ohne Client‑Secret).
5. **Userinfo**: Backend ruft User‑Profil via `userinfo`‑Endpoint ab.
6. **User‑Persistenz**: Nutzer wird in der lokalen DB gespeichert (Identität über `sub`).
7. **Token‑Weitergabe**: Backend leitet den Nutzer zur Frontend‑URL zurück und hängt `token`, `id_token`, `refresh_token` als Query‑Params an.
8. **Frontend‑Session**: Frontend speichert Tokens in `localStorage` und lädt `auth-data` (Arbeitsbereiche).

Details:
- `state` enthält optional die Ziel‑URL (`redirect_uri`) und wird serverseitig geprüft.
- PKCE‑Verifier wird serverseitig kurzzeitig gespeichert (TTL 5 Minuten).
- API‑Requests senden den Access‑Token als `Authorization: Bearer <token>`.
- Logout nutzt `POST /api/auth/logout` und invalidiert die SSO‑Session bei Keycloak.

---

## Additional Information
Nachdem die Prozesse dieser Befehle beendet sind, ist der Edge-Router und das Monitoring aktiv, die Kodierbox
Datenbank eingerichtet, die Kodierbox API und Web-Site ansprechbar.
Ein Zugriff auf den Server über einen Browser sollte dann sofort möglich sein.
Expand Down
Loading