Authentication Service (svc-auth)
Overview
svc-auth is a FastAPI service that handles OAuth2 authentication via Auth0 and manages server-side user sessions. It is the only service that communicates directly with Auth0 and the only place where access tokens are ever stored.
Internal port: 3000 (not exposed to host)
Responsibilities
Initiating and completing the Auth0 OAuth2 authorization code flow
Storing access and refresh tokens server-side in Redis (never in the browser)
Issuing and validating signed HTTP-only session cookies
Automatically refreshing tokens before expiry
Exposing a
/verifyendpoint used by nginx to gate protected routes
API Endpoints
See spec/api/svc-auth.md for the full auto-generated reference.
| Method | Path | Description |
|---|---|---|
GET | /login | Redirect to Auth0 authorization endpoint |
GET | /callback | Handle Auth0 callback; create session |
GET | /verify | Validate session (used by nginx auth_request) |
GET | /logout | Clear session and redirect to Auth0 logout |
POST | /logout | Same as GET logout (supports form/AJAX) |
GET | /me | Return current user info from session |
GET | /session/info | Debug session info (dev mode only) |
OAuth2 Flow
Browser → GET /login
↓ generate state + nonce, store in Redis
Auth0 authorization endpoint (redirect)
↓ user authenticates
Auth0 → GET /callback?code=...&state=...
↓ validate state, exchange code for tokens
↓ store access_token + refresh_token in Redis keyed by session_id
↓ set signed session cookie (HTTP-only)
Browser → redirected to app
Session & Token Storage
Sessions are stored in Redis with the following structure:
Session cookie: signed with
itsdangerous.URLSafeTimedSerializerusingSESSION_SECRET; cookie name isSESSION_COOKIE_NAME(default:sid)Redis key (
session:{session_id}): containsuser_id,access_token,refresh_token,expires_atToken refresh: triggered automatically when the access token expires within
TOKEN_REFRESH_THRESHOLDseconds (default: 300 s)
Tokens are never exposed to the browser — the cookie only identifies the session.
nginx Integration
nginx uses the auth_request directive to call /verify before serving any protected route on app.dev.datachainr.com. On a valid session, svc-auth responds 200 and sets X-User-Id and X-Session-Id headers that nginx passes downstream.
Configuration
| Variable | Description | Default |
|---|---|---|
AUTH0_CLIENT_ID | Auth0 application client ID | required |
AUTH0_CLIENT_SECRET | Auth0 application client secret | required |
AUTH0_AUDIENCE | Auth0 API audience | required |
AUTH_CALLBACK_URL | Full URL of the /callback endpoint | required |
REDIS_URL | Redis connection URL | redis://redis:6379 |
REDIS_PASSWORD | Redis password | optional |
SESSION_SECRET | Secret for signing cookies | required |
SESSION_COOKIE_NAME | Cookie name | sid |
SESSION_MAX_AGE | Session TTL in seconds | 900 (15 min) |
TOKEN_REFRESH_THRESHOLD | Seconds before expiry to refresh | 300 |
FRONTEND_URL | Where to redirect after login | required |
ENVIRONMENT | development / production | development |
COOKIE_SECURE | Set Secure flag on cookie | false |
Runtime Dependencies
Redis — session and token storage (same
bff-network)Auth0 — external identity provider
No dedicated PostgreSQL database. svc-auth is stateless beyond Redis.
Networks
bff-network only — cannot reach backend-network or databases.