init
This commit is contained in:
@@ -1,2 +1,143 @@
|
||||
# urlshortener
|
||||
# Go URL Shortener mit PocketID Login
|
||||
|
||||
Ein Docker-fähiger URL-Shortener in Go mit SQLite, Web-UI, PocketID/OIDC-Login und Link-Verwaltung pro Nutzer.
|
||||
|
||||
## Features
|
||||
|
||||
- PocketID/OIDC Login über Authorization Code Flow
|
||||
- Signiertes HttpOnly Session-Cookie
|
||||
- Nutzergebundene Links über `owner_sub`
|
||||
- Links erstellen, anzeigen, ändern und löschen
|
||||
- Öffentliche Redirects über `/{code}`
|
||||
- SQLite bleibt als Datenbank
|
||||
- Dockerfile und docker-compose inklusive
|
||||
- `AUTH_MODE=local` als lokaler Demo-Modus ohne PocketID
|
||||
|
||||
## Start im lokalen Demo-Modus
|
||||
|
||||
```bash
|
||||
docker compose up --build
|
||||
```
|
||||
|
||||
Dann öffnen:
|
||||
|
||||
```text
|
||||
http://localhost:8080
|
||||
```
|
||||
|
||||
Im Standard ist `AUTH_MODE=local` aktiv. Der Login-Button erzeugt dann eine lokale Demo-Session.
|
||||
|
||||
## PocketID konfigurieren
|
||||
|
||||
In PocketID einen OIDC Client anlegen:
|
||||
|
||||
- Confidential Client / Public Client aus
|
||||
- Client ID und Client Secret notieren
|
||||
- Callback URL eintragen:
|
||||
|
||||
```text
|
||||
http://localhost:8080/auth/callback
|
||||
```
|
||||
|
||||
Für produktive Deployments entsprechend deine echte HTTPS-URL verwenden, zum Beispiel:
|
||||
|
||||
```text
|
||||
https://links.example.com/auth/callback
|
||||
```
|
||||
|
||||
PocketID wird als normaler OIDC Provider verwendet. `OIDC_ISSUER` ist die Basis-URL deiner PocketID-Instanz, ohne trailing slash und ohne `/.well-known/openid-configuration`.
|
||||
|
||||
## docker-compose mit PocketID
|
||||
|
||||
In `docker-compose.yml` die Environment-Variablen setzen:
|
||||
|
||||
```yaml
|
||||
environment:
|
||||
ADDR: ":8080"
|
||||
BASE_URL: "https://links.example.com"
|
||||
DB_PATH: "/data/shortener.db"
|
||||
|
||||
AUTH_MODE: "oidc"
|
||||
OIDC_ISSUER: "https://pocketid.example.com"
|
||||
OIDC_CLIENT_ID: "deine-client-id"
|
||||
OIDC_CLIENT_SECRET: "dein-client-secret"
|
||||
OIDC_REDIRECT_URL: "https://links.example.com/auth/callback"
|
||||
OIDC_SCOPES: "openid profile email"
|
||||
SESSION_SECRET: "bitte-mindestens-32-zeichen-langer-geheimer-string"
|
||||
```
|
||||
|
||||
Dann:
|
||||
|
||||
```bash
|
||||
docker compose up --build
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### Aktuellen Nutzer lesen
|
||||
|
||||
```bash
|
||||
curl http://localhost:8080/api/me
|
||||
```
|
||||
|
||||
### URL kürzen
|
||||
|
||||
Erfordert Login-Session.
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/api/shorten \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"url":"https://example.com/some/very/long/path"}'
|
||||
```
|
||||
|
||||
### Eigene Links anzeigen
|
||||
|
||||
```bash
|
||||
curl http://localhost:8080/api/links
|
||||
```
|
||||
|
||||
### Link ändern
|
||||
|
||||
```bash
|
||||
curl -X PUT http://localhost:8080/api/links/abc123X \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"url":"https://example.com/new-target"}'
|
||||
```
|
||||
|
||||
### Link löschen
|
||||
|
||||
```bash
|
||||
curl -X DELETE http://localhost:8080/api/links/abc123X
|
||||
```
|
||||
|
||||
## Konfiguration
|
||||
|
||||
| Variable | Standard | Beschreibung |
|
||||
|---|---:|---|
|
||||
| `ADDR` | `:8080` | Listen-Adresse |
|
||||
| `BASE_URL` | `http://localhost:8080` | Basis für erzeugte Kurz-URLs |
|
||||
| `DB_PATH` | `/data/shortener.db` | SQLite-Datenbankpfad |
|
||||
| `AUTH_MODE` | `local` | `local` oder `oidc` |
|
||||
| `OIDC_ISSUER` | leer | Basis-URL der PocketID-Instanz |
|
||||
| `OIDC_CLIENT_ID` | leer | OIDC Client ID |
|
||||
| `OIDC_CLIENT_SECRET` | leer | OIDC Client Secret |
|
||||
| `OIDC_REDIRECT_URL` | leer | Muss zur PocketID Callback URL passen |
|
||||
| `OIDC_SCOPES` | `openid profile email` | OIDC Scopes |
|
||||
| `SESSION_SECRET` | zufällig bei Start | Mindestens 32 Byte/Zeichen, in Produktion fest setzen |
|
||||
|
||||
## Lokaler Start ohne Docker
|
||||
|
||||
```bash
|
||||
go mod tidy
|
||||
AUTH_MODE=local DB_PATH=./shortener.db go run .
|
||||
```
|
||||
|
||||
## Hinweise zur Migration
|
||||
|
||||
Die App ergänzt alte SQLite-Datenbanken sanft um:
|
||||
|
||||
- `owner_sub`
|
||||
- `owner_name`
|
||||
- `updated_at`
|
||||
|
||||
Alte Links ohne Besitzer bleiben öffentlich weiterleitbar, erscheinen aber keinem Nutzer im Dashboard.
|
||||
|
||||
Reference in New Issue
Block a user