updated the docs, removed oauth and introduced sanctum pat
This commit is contained in:
@@ -1,28 +1,30 @@
|
||||
# API-Nutzung der Tenant Admin App
|
||||
|
||||
Diese Dokumentation beschreibt alle API-Endpunkte, die die Tenant Admin App mit der Backend-Hauptapp kommuniziert. Alle Requests sind tenant-scoped und erfordern JWT-Authentifizierung.
|
||||
Diese Dokumentation beschreibt alle API-Endpunkte der Tenant Admin App. Alle Requests sind tenant-scoped und erfordern ein Sanctum Personal Access Token (PAT) mit der Fähigkeit `tenant-admin` bzw. `tenant:<id>`.
|
||||
|
||||
## Authentifizierung
|
||||
|
||||
### OAuth2 Flow (PKCE)
|
||||
- **Start**: `GET /oauth/authorize` (Browser-Redirect mit PKCE-Challenge)
|
||||
- **Params**: `client_id`, `redirect_uri`, `scope=tenant:read tenant:write`, `state`, `code_challenge`, `code_challenge_method=S256`
|
||||
- **Response**: Authorization Code
|
||||
### Passwort-Login (PAT)
|
||||
- **Endpoint**: `POST /api/v1/tenant-auth/login`
|
||||
- **Body** (`application/json`): `{ "login": "username oder email", "password": "••••" }`
|
||||
- **Response**: `{ token, token_type, abilities[], user { ... } }`
|
||||
- **Fehler**: `422` bei ungültigen Daten, `429` bei Rate-Limit (`throttle:tenant-auth`).
|
||||
- **Hinweis**: `login` akzeptiert E-Mail _oder_ Usernamen. Erfolgreiche Logins revoken vorhandene PATs mit Name `tenant-admin`.
|
||||
|
||||
- **Token Exchange**: `POST /oauth/token`
|
||||
- **Body**: `grant_type=authorization_code`, `client_id`, `code`, `redirect_uri`, `code_verifier`
|
||||
- **Response**: `{ access_token, refresh_token, expires_in, token_type }`
|
||||
- **Headers**: `Content-Type: application/x-www-form-urlencoded`
|
||||
### Session→PAT Exchange (Google/Login-Shell)
|
||||
- **Endpoint**: `POST /api/v1/tenant-auth/exchange`
|
||||
- **Middleware**: Sanctum stateful cookies (`SANCTUM_STATEFUL_DOMAINS`), `throttle:tenant-auth`.
|
||||
- **Use-Case**: Nach Google-Login oder Marketing-Checkout Session wird das PAT ohne erneute Passwort-Eingabe ausgegeben.
|
||||
- **Response**: identisch zum Passwort-Login.
|
||||
|
||||
- **Token Refresh**: `POST /oauth/token`
|
||||
- **Body**: `grant_type=refresh_token`, `client_id`, `refresh_token`
|
||||
- **Response**: Neuer Access/Refresh-Token
|
||||
### Token Status & Logout
|
||||
- **`GET /api/v1/tenant-auth/me`** – liefert `{ user, tenant, abilities }` und spiegelt die PAT-Fähigkeiten wider.
|
||||
- **`POST /api/v1/tenant-auth/logout`** – löscht das aktuelle PAT aus `personal_access_tokens`.
|
||||
|
||||
- **Token Validation**: `GET /api/v1/tenant/me`
|
||||
- **Redirect URI**: Standardmaessig `${origin}/event-admin/auth/callback` (per Vite-Env anpassbar)
|
||||
- **Headers**: `Authorization: Bearer {access_token}`
|
||||
- **Response**: `{ id, email, tenant_id, role, name }`
|
||||
- **Hinweis**: `client_id` entspricht `VITE_OAUTH_CLIENT_ID`; Seeder `OAuthClientSeeder` synchronisiert Frontend und Backend.
|
||||
### Legacy Payload `/tenant/me`
|
||||
- **Endpoint**: `GET /api/v1/tenant/me`
|
||||
- **Response**: historisches Format (`tenant_id`, `remaining_events`, `scopes`), betrieben über denselben PAT.
|
||||
- **Kompatibilität**: Dient älteren Clients als Übergang; neue Features sollten `/tenant-auth/me` verwenden.
|
||||
|
||||
## Dashboard
|
||||
|
||||
@@ -188,7 +190,7 @@ Diese Dokumentation beschreibt alle API-Endpunkte, die die Tenant Admin App mit
|
||||
## Allgemeine Headers
|
||||
|
||||
Alle API-Requests enthalten:
|
||||
- **Authorization**: `Bearer {access_token}` (JWT mit tenant_id)
|
||||
- **Authorization**: `Bearer {access_token}` (Sanctum PAT mit Fähigkeit `tenant:{id}`)
|
||||
- **Content-Type**: `application/json` (für POST/PATCH)
|
||||
- **If-Match**: `{etag}` (für Concurrency-Control bei Updates)
|
||||
- **Accept**: `application/json`
|
||||
@@ -230,7 +232,7 @@ Mutierende Endpunkte (PATCH/DELETE) erfordern:
|
||||
|
||||
## Sicherheit
|
||||
|
||||
- **Tenant-Isolation**: Alle Endpunkte prüfen JWT-tenant_id gegen request tenant_id
|
||||
- **Tenant-Isolation**: Middleware vergleicht PAT-Fähigkeit (`tenant:{id}`) mit dem angefragten Tenant
|
||||
- **RBAC**: Nur tenant_admin kann mutieren, member kann nur lesen/hochladen
|
||||
- **Rate Limiting**: 100 Requests/Minute pro Tenant
|
||||
- **ETag**: Automatische Concurrency-Control
|
||||
@@ -259,8 +261,9 @@ curl -H "Authorization: Bearer {token}" \
|
||||
|
||||
### Environment-Variablen
|
||||
- **VITE_API_URL**: Backend-API-URL (Pflicht)
|
||||
- **VITE_OAUTH_CLIENT_ID**: OAuth-Client-ID (Pflicht, muss mit `config/services.php` übereinstimmen – der Seeder legt damit den Client in `oauth_clients` an)
|
||||
- **VITE_REVENUECAT_PUBLIC_KEY**: Optional fuer In-App-Kaeufe (RevenueCat)
|
||||
- **VITE_ENABLE_TENANT_SWITCHER**: Dev-Flag um Tenants im Header auszuwählen (optional, Default `false`)
|
||||
- **VITE_REVENUECAT_PUBLIC_KEY**: Optional für In-App-Käufe (RevenueCat)
|
||||
- **SANCTUM_STATEFUL_DOMAINS** (Backend): Enthält die Origins des Admin-PWA/TWA, damit der Session→PAT-Exchange funktioniert.
|
||||
- **REVENUECAT_WEBHOOK_SECRET / REVENUECAT_PRODUCT_MAPPINGS / REVENUECAT_APP_USER_PREFIX / REVENUECAT_WEBHOOK_QUEUE**: Backend-Konfiguration für RevenueCat-Webhooks, siehe `config/services.php`.
|
||||
|
||||
### Build & Deploy
|
||||
@@ -273,4 +276,3 @@ curl -H "Authorization: Bearer {token}" \
|
||||
- Installierbar auf Desktop/Mobile via "Zum Startbildschirm hinzufügen".
|
||||
|
||||
Für weitere Details siehe die spezifischen Dokumentationsdateien.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user