Overview
The Auth Service provides user authentication and authorization using JWT tokens signed with RSA keys. It supports user registration, login, and token verification.Authentication Flow
- Signup - Register a new user with email and password
- Login - Authenticate and receive a JWT token
- Verify - Validate JWT tokens for protected resources
Base URL
Endpoints
Health Check
200- Service is healthy503- Database health check failed
Get JWKS (JSON Web Key Set)
Register User
User’s email address (must be unique)
User’s password (will be hashed with bcrypt)
Unique user ID
User’s email address
User’s role (default: “user”)
201- User created successfully400- Missing required fields409- Email already exists500- Server error503- Database not configured
Login
User’s email address
User’s password
JWT token signed with RS256 algorithm. Contains claims:
sub- User ID (or email if database unavailable)role- User’s roleiss- Issuer (auth-service)exp- Expiration time (24 hours)kid- Key ID for verification
200- Login successful, token returned400- Missing required fields401- Invalid credentials500- Server error
Verify Token
X-User-Id header in the response.
Bearer token in the format:
Bearer <token>Always true for successful verification
User ID extracted from the token’s
sub claimX-User-Id- User ID from the token
200- Token is valid401- Missing or invalid token
- Algorithm must be RS256
- Issuer must be “auth-service”
- Token must not be expired
- Signature must be valid
JWT Token Structure
Tokens issued by the auth service contain the following claims:Error Handling
All error responses follow this format:400- Bad Request (missing or invalid parameters)401- Unauthorized (authentication failed)409- Conflict (duplicate email)500- Internal Server Error503- Service Unavailable (database issues)
Security Notes
- Password Hashing: All passwords are hashed using bcrypt with 10 salt rounds
- Token Signing: JWT tokens are signed using RSA-SHA256 (RS256)
- Token Expiration: Tokens expire after 24 hours
- Key Management: RSA key pairs are generated at startup (development mode). In production, keys should be loaded from Kubernetes Secrets
- CORS: Cross-Origin Resource Sharing is enabled for all origins