Overview
The Authentication API provides endpoints for user authentication, token management, and session handling. Supports both JWT token-based and Redis session-based authentication modes.v2.1.0 adds Keycloak SSO support and Redis session management for production deployments.
Base URL
Authentication Modes
- Token Mode
- Session Mode
Stateless JWT authentication
- Client receives access token + refresh token
- Access token included in
Authorizationheader - Refresh token used to get new access tokens
Endpoints
POST /auth/login
Authenticate user and create session or issue tokens.string
required
User’s username or email
string
required
User’s password
string
default:"password"
OAuth2 grant type. Options:
password, refresh_tokenSuccess
Authentication successful
Unauthorized
Invalid credentials
Too Many Requests
Rate limit exceeded
POST /auth/refresh
Refresh access token using refresh token.string
required
Valid refresh token from login response
Refresh tokens are rotated on each refresh for security. The old refresh token is invalidated.
Success
Token refreshed successfully
Unauthorized
Invalid or expired refresh token
POST /auth/logout
Logout user and revoke session/tokens. Headers:Authorization: Bearer {token}(token mode)Cookie: session_id={session_id}(session mode)
Success
Logout successful
Unauthorized
Not authenticated
GET /auth/me
Get current authenticated user information. Headers:Authorization: Bearer {token}(token mode)Cookie: session_id={session_id}(session mode)
Success
User information retrieved
Unauthorized
Not authenticated or session/token expired
GET /auth/sessions
List active sessions for current user (session mode only). Headers:Authorization: Bearer {token}orCookie: session_id={session_id}
Success
Sessions retrieved
Unauthorized
Not authenticated
DELETE /auth/sessions/
Revoke a specific session (session mode only). Path Parameters:session_id: Session ID to revoke
Success
Session revoked
Forbidden
Cannot revoke another user’s session
Not Found
Session not found
POST /auth/verify
Verify token validity and get user information. Headers:Authorization: Bearer {token}
Success
Token is valid
Unauthorized
Token is invalid or expired
Keycloak SSO Endpoints
WhenAUTH_PROVIDER=keycloak, additional endpoints are available:
GET /auth/keycloak/login
Redirect to Keycloak login page (browser flow). Query Parameters:redirect_uri: URL to redirect after login (optional)
GET /auth/keycloak/callback
OAuth2 callback endpoint (handled automatically). Query Parameters:code: Authorization code from Keycloakstate: CSRF protection state
GET /auth/keycloak/logout
Logout from Keycloak and revoke tokens. Request Example:Error Responses
All authentication endpoints may return the following errors:401 Unauthorized
403 Forbidden
429 Too Many Requests
500 Internal Server Error
SDK Examples
Python
JavaScript/TypeScript
Security Best Practices
Token Storage
Token Storage
Browser: Store access tokens in memory, refresh tokens in HttpOnly cookiesMobile: Use secure storage (Keychain/Keystore)Server: Store tokens in environment variables or secret managerNever: Store tokens in localStorage (vulnerable to XSS)
Token Refresh
Token Refresh
- Refresh tokens before expiration (e.g., when < 5 minutes left)
- Implement automatic retry on 401 with token refresh
- Handle refresh token rotation
- Clear tokens on logout
Session Management
Session Management
- Set appropriate session TTL (balance UX vs security)
- Use sliding windows for active users
- Limit concurrent sessions per user
- Revoke sessions on password change
- Monitor for session hijacking
Rate Limiting
Rate Limiting
- Implement exponential backoff on failures
- Respect
Retry-Afterheader on 429 errors - Monitor authentication failure rates
- Alert on suspicious patterns
Related Documentation
Authentication Guide
Learn about authentication modes
Keycloak SSO
Setup Keycloak integration
Redis Sessions
Configure session storage
Authorization Guide
OpenFGA permission model
Secure by Default: All authentication endpoints use industry-standard security practices!