2026-05-19 06:31:43 +02:00
2026-05-19 06:31:43 +02:00
2026-05-19 06:31:43 +02:00
2026-05-19 06:31:43 +02:00
2026-05-19 06:31:43 +02:00
2026-05-19 06:31:43 +02:00
2026-05-19 06:31:43 +02:00
2026-05-19 06:31:43 +02:00
2026-05-19 06:31:43 +02:00

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

docker compose up --build

Dann öffnen:

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:
http://localhost:8080/auth/callback

Für produktive Deployments entsprechend deine echte HTTPS-URL verwenden, zum Beispiel:

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:

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:

docker compose up --build

API

Aktuellen Nutzer lesen

curl http://localhost:8080/api/me

URL kürzen

Erfordert Login-Session.

curl -X POST http://localhost:8080/api/shorten \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/some/very/long/path"}'
curl http://localhost:8080/api/links
curl -X PUT http://localhost:8080/api/links/abc123X \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/new-target"}'
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

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.

Description
No description provided
Readme 42 KiB
Languages
Go 52.7%
CSS 19.8%
JavaScript 14.9%
HTML 11.3%
Dockerfile 1.3%