NestJS identity + OIDC provider with dynamic client registration, optional refresh tokens, and auto-
2.8K
Category: Backend Service
Samakia Auth is a NestJS 11 microservice exposing identity APIs (user CRUD), an OAuth2/OIDC provider (with dynamic client registration), and notification hooks. It persists users to MariaDB, caches sessions in Redis, and publishes email events to RabbitMQ. Object-storage responsibilities are handled by the separate samakia-minio service.
ops/docker/samakia-auth.Dockerfileflowchart TD
subgraph Ingress
I[NGINX Ingress\n auth.samakia.net]
end
I --> A[Auth Service\n(NestJS)]
A -->|JWT/RS256| J[JWKS /.well-known]
A -->|CRUD| DB[(MariaDB\nDB_DATABASE_AUTH)]
A -->|Sessions, rate limit| R[(Redis)]
A -->|mail.send| Q[(RabbitMQ)]
A -.->|OIDC clients| C[Dynamic Registration]
A -.X M[(MinIO App)]:::note
classDef note fill:#f5f5f5,stroke:#bbb,color:#333
class M note
Environment is loaded via @samakia-platform/config. In prod, make docker-publish sources values from Vault export (vault.prod.json). Dynamic client registration endpoint is /auth/clients (advertised in discovery as registration_endpoint).
Config highlights:
AUTH_REFRESH_TOKENS_ENABLED enables refresh tokens in prod; TTLs controlled by AUTH_ACCESS_TOKEN_TTL_SECONDS and AUTH_REFRESH_TOKEN_TTL_SECONDS.AUTH_AUTO_ACTIVATE_ON_LOGIN (boolean) optionally activates a user after successful password verification (migration aid).DB_DATABASE_AUTH (legacy DB_DATABASE is ignored).AUTH_PORT, AUTH_JWT_*, REDIS_*, RABBITMQ_*, SSO keys like GOOGLE_*.Base path: /auth (Ingress host auth.samakia.net). Selected routes:
GET /.well-known/openid-configuration (authorization_endpoint = https://auth.samakia.net/auth/authorize)GET /.well-known/jwks.jsonPOST /auth/registerPOST /auth/clients (OIDC dynamic client registration)POST /auth/activateGET /auth/authorizePOST /auth/authorizePOST /auth/tokenGET /auth/google/startGET /auth/google/callbackPOST /auth/password/reset/startPOST /auth/password/reset/completePOST /usersGET /usersGET /users/:idPATCH /users/:idDELETE /users/:idPOST /auth/clients with metadata (redirect_uris, token_endpoint_auth_method, grant_types, ...).GET /auth/clients/:clientId with registration access token.none).${RABBITMQ_MAIL_QUEUE} (default mail.send)samakia-minio servicesequenceDiagram
participant U as User
participant W as Web (Next.js)
participant A as Auth (OIDC)
participant Q as RabbitMQ
participant M as Mail Worker
U->>W: Submit registration
W->>A: POST /auth/register
A->>Q: Publish mail.send { activationToken }
M->>Q: Consume mail.send
M->>U: Send activation email (SMTP)
U->>A: POST /auth/activate { token }
A-->>U: 200 Activated
sequenceDiagram
participant B as Browser
participant A as Auth
Note over A: AUTH_AUTO_ACTIVATE_ON_LOGIN=true
B->>A: POST /auth/authorize (username/password)
A->>A: Verify credentials
A->>A: If not active → activate
A-->>B: 302 to redirect_uri with code
B->>A: POST /auth/token (code)
A-->>B: { access_token, refresh_token? }
ops/k8s/base/deployments/samakia-auth.yaml, Service + Ingress auth.samakia.net.docker.io/<namespace>/samakia-auth:<tag>3100/tcpapps/samakia-auth/src/app/**.spec.tsmake k6-auth (k6 flow via Docker)kubectl rollout restart deploy/samakia-auth -n samakia-platformkubectl logs deploy/samakia-auth -n samakia-platform -fContent type
Image
Digest
sha256:862440f23…
Size
59.5 MB
Last updated
about 1 year ago
docker pull ankouros/samakia-auth