Backend Phase B (2/2): OIDC auth + config validation
- internal/auth/oidc.go: OIDCService mit go-oidc v3
- id_token-Verifikation via JWKS (Signatur, iss, aud, exp)
- Provider-Caching (sync.Map, lazy init per Issuer-URL)
- Unterstützt Google + Generic OIDC
- internal/auth/user.go: GetByOIDCSubject + CreateOIDCUser
(find-or-create via (oidc_issuer, oidc_subject))
- internal/httpapi/auth.go: POST /auth/oidc Handler
(id_token verifiziern → find-or-create User → issueSession)
- internal/httpapi/api.go: /auth/oidc Route verdrahtet
- internal/config/config.go: OIDC-Validierung
(enabled → client_id + issuer Pflicht)
- go.mod/go.sum: go-oidc/v3 + oauth2 Abhängigkeiten
- AGENTS.md: Phase B vollständig als erledigt markiert
Verifiziert: E2E gegen lokalen Mock-IdP (Discovery → JWKS →
signiertes id_token → User angelegt → 2. Login gleicher User →
tampered Token → 401). Alle Fehlerpfade geprüft.
go build ./... && go vet ./... && go test ./internal/auth/... ✅
This commit is contained in:
parent
7b1c18590e
commit
a5ef8cf3ba
8 changed files with 322 additions and 23 deletions
47
AGENTS.md
47
AGENTS.md
|
|
@ -90,18 +90,19 @@ mitbringsl/
|
|||
│ │ ├── config/config.go # Config (caarlos0/env)
|
||||
│ │ ├── logging/logging.go # slog JSON-Setup
|
||||
│ │ ├── store/db.go # pgxpool-Setup
|
||||
│ │ ├── auth/ # PHASE B – Password + Session
|
||||
│ │ ├── auth/ # PHASE B – Password + Session + OIDC
|
||||
│ │ │ ├── password.go # Argon2id im PHC-Format (HashPassword/VerifyPassword)
|
||||
│ │ │ ├── password_test.go # PHC-Roundtrip-Tests
|
||||
│ │ │ ├── user.go # UserStore: CreateUser/GetByEmail/GetByID
|
||||
│ │ │ ├── user.go # UserStore: CreateUser/GetByEmail/GetByID/GetByOIDCSubject/CreateOIDCUser
|
||||
│ │ │ ├── session.go # SessionStore: opaque Tokens, SHA-256-Hash, Create/Lookup/Revoke
|
||||
│ │ │ ├── oidc.go # OIDCService: id_token-Verifikation (JWKS/iss/aud/exp), Provider-Caching
|
||||
│ │ │ └── pgcode.go # isUniqueViolation (SQLSTATE 23505)
|
||||
│ │ └── httpapi/
|
||||
│ │ ├── api.go # API-Objekt + Router (Health + /auth/* aktiv, Rest auskommentiert)
|
||||
│ │ ├── render.go # JSON-Render + Problem + Fehler-Sentinale + decodeJSON
|
||||
│ │ ├── middleware.go # requestID/logging/recover/cors + Chain
|
||||
│ │ ├── health.go # /healthz + /readyz
|
||||
│ │ └── auth.go # Register/Login/Logout-Handler + RequireAuth-Middleware
|
||||
│ │ └── auth.go # Register/Login/Logout/OIDC-Handler + RequireAuth-Middleware
|
||||
│ ├── migrations/
|
||||
│ │ ├── embed.go # //go:embed *.sql
|
||||
│ │ ├── 000001_init_schema.up.sql # users/sessions/lists/list_members/items/op_log/item_names
|
||||
|
|
@ -135,7 +136,12 @@ Legende: ✅ erledigt · 🚧 in Arbeit · ⬜ offen
|
|||
`Register`/`Login`/`Logout` + `RequireAuth`-Middleware.
|
||||
**Verifiziert:** `go test ./internal/auth/...` grün, E2E-Smoke-Test gegen echtes
|
||||
PostgreSQL via Docker (Register/Login/Logout/Duplicate/Short-PW/Wrong-PW alle korrekt).
|
||||
- 🚧 **Phase B – OIDC:** go-oidc-Verifikation (Google + Generic) + `POST /auth/oidc`.
|
||||
- ✅ **Phase B – OIDC:** `OIDCService` (go-oidc v3, JWKS-Signatur, iss/aud/exp, Provider-Caching)
|
||||
+ `POST /auth/oidc` (find-or-create User via `(oidc_issuer, oidc_subject)`, reuses `issueSession`)
|
||||
+ Config-Validierung (enabled → client_id/issuer Pflicht).
|
||||
**Verifiziert:** E2E-Flow gegen lokalen Mock-IdP (Discovery → JWKS → signiertes id_token
|
||||
→ User angelegt → 2. Login findet gleichen User → tampered Token → 401). Alle Fehlerpfade
|
||||
geprüft (disabled→400, unknown provider→400, missing fields→400, invalid→401).
|
||||
- ⬜ **Phase C – Sync-Kern:** `op_log`-Append (idempotent), HLC, Projektion op→items/lists (LWW+Tombstones).
|
||||
- ⬜ **Phase C – Endpoints:** `/api/lists`, `/api/lists/{id}/ops` (push+pull).
|
||||
- ⬜ **Phase C – Suggestions:** `item_names`-Trigger + `/api/suggestions`.
|
||||
|
|
@ -149,23 +155,24 @@ Legende: ✅ erledigt · 🚧 in Arbeit · ⬜ offen
|
|||
- ⬜ **Phase F – README + docs** (ARCHITECTURE/SYNC/API).
|
||||
|
||||
### Wo genau weitermachen?
|
||||
**Nächster Schritt = Phase B Teil 2 (OIDC)** – Teil 1 (Password-Auth) ist fertig ✅:
|
||||
**Phase B ist komplett ✅. Nächster Schritt = Phase C (Sync-Kern).**
|
||||
|
||||
Teil 1 (erledigt):
|
||||
Phase B erledigt:
|
||||
- ✅ `internal/auth/password.go` – Argon2id im PHC-Format (HashPassword/VerifyPassword).
|
||||
- ✅ `internal/auth/user.go` – UserStore (CreateUser/GetByEmail/GetByID).
|
||||
- ✅ `internal/auth/user.go` – UserStore (CreateUser/GetByEmail/GetByID/GetByOIDCSubject/CreateOIDCUser).
|
||||
- ✅ `internal/auth/session.go` – SessionStore (crypto/rand + base64url + SHA-256, Create/Lookup/Revoke).
|
||||
- ✅ `internal/httpapi/auth.go` – Register/Login/Logout + RequireAuth-Middleware.
|
||||
- ✅ In `api.go` sind `/auth/register`, `/auth/login`, `/auth/logout` aktiv verdrahtet.
|
||||
- ✅ `internal/auth/oidc.go` – OIDCService (id_token-Verifikation via go-oidc v3, Provider-Caching).
|
||||
- ✅ `internal/httpapi/auth.go` – Register/Login/Logout/OIDC + RequireAuth-Middleware.
|
||||
- ✅ `config.go` – OIDC-Validierung (enabled → client_id/issuer Pflicht).
|
||||
- ✅ Alle `/auth/*`-Routen aktiv verdrahtet.
|
||||
|
||||
Teil 2 (offen – OIDC):
|
||||
1. `internal/auth/oidc.go` – Verifikation eines `id_token` via `github.com/coreos/go-oidc/v3`
|
||||
(JWKS-Signatur, iss/aud/exp prüfen). Provider-Auswahl anhand `issuer` aus Config.
|
||||
2. `POST /auth/oidc`-Handler in `internal/httpapi/auth.go`: empfängt `{provider, id_token}`,
|
||||
verifiziert, findet/legt User an (oidc_issuer+oidc_subject UNIQUE), stellt Session aus
|
||||
(gleicher `issueSession`-Pfad wie Login).
|
||||
3. In `api.go` `mux.HandleFunc("POST /auth/oidc", a.auth.OIDC)` einkommentieren.
|
||||
4. Config-Validierung: wenn `OIDC_GOOGLE_ENABLED=true`, muss `OIDC_GOOGLE_CLIENT_ID` gesetzt sein.
|
||||
Phase C – Sync-Kern (offen):
|
||||
1. `internal/sync/hlc.go` – Hybrid Logical Clock (client- + server-seitig, `(ts, counter)`).
|
||||
2. `op_log`-Append in `internal/store/opstore.go`: `AppendOp` idempotent via `UNIQUE(client_id, client_seq)`,
|
||||
zurück: server-seitiger `seq` + `now()`-basierte HLC.
|
||||
3. Projektion op→items/lists: `internal/store/liststore.go`/`itemstore.go` mit LWW (`hlc_ts`) + Tombstones (`deleted_at`).
|
||||
4. Endpoints `GET/POST /api/lists`, `GET/POST /api/lists/{id}/ops` (Pull `?since=`, Push idempotent).
|
||||
5. Suggestions: `item_names`-Trigger + `GET /api/suggestions?q=`.
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -208,5 +215,7 @@ docker run --rm --network <net> \
|
|||
```
|
||||
|
||||
## Git-Status
|
||||
- Repo initialisiert, Branch `main`. **Remote ist noch NICHT konfiguriert.**
|
||||
- Es wurde **noch nicht committet** (Stand beim Schreiben dieser Datei).
|
||||
- Repo initialisiert, Branch `main`. Remote ist konfiguriert (`origin`).
|
||||
- Phase A + Phase B (1/2: Password/Sessions) committed und gepusht.
|
||||
- Phase B (2/2: OIDC) committed und gepusht. **Phase B vollständig ✅.**
|
||||
- Nächster Schritt: **Phase C – Sync-Kern** (siehe Roadmap oben).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue