Overview
Chronoverse uses a hybrid authentication approach combining:- JWT tokens (short-lived, 15 minutes) for authorization
- Session cookies (long-lived) for maintaining user sessions
- CSRF tokens for protecting state-changing operations
All authenticated endpoints require both a valid session cookie and CSRF token for state-changing operations (POST, PUT, PATCH, DELETE).
JWT Token Details
JSON Web Tokens (JWT) are used for secure authorization between services.Token Structure
Tokens are signed using the EdDSA algorithm with Ed25519 keys and contain the following claims:Audience - The service name (chronoverse)
Issuer - The service that issued the token
Subject - The user ID
User role - Either
user or adminIssued at - Unix timestamp when token was created
Not before - Unix timestamp when token becomes valid
Expiration - Unix timestamp when token expires (15 minutes from issuance)
Token Expiry
JWT tokens expire after 15 minutes for security. However, the session remains valid longer, and tokens are automatically reissued on subsequent requests.Authentication Flow
1. Register a New User
Create a new user account:User’s email address
User’s password
- Status:
201 Created - Sets two HTTP-only cookies:
session- Encrypted session tokencsrf- CSRF protection token
2. Login
Authenticate an existing user:User’s email address
User’s password
- Status:
201 Created - Sets two HTTP-only cookies:
session- Encrypted session token containing the JWTcsrf- CSRF protection token
Save the cookies using
-c cookies.txt to use them in subsequent requests.3. Using Authenticated Endpoints
For GET requests (read-only operations):4. Validate Session
Check if your current session is valid:- Status:
200 OK- Session is valid - Status:
401 Unauthorized- Session is invalid or expired
5. Logout
End your session and clear cookies:- Status:
204 No Content - Clears both
sessionandcsrfcookies - Deletes the session from the server
Cookie Details
Session Cookie
Thesession cookie contains an encrypted JWT token:
- Name:
session - HttpOnly:
true(not accessible via JavaScript) - Secure: Depends on deployment (true for HTTPS)
- SameSite: Configurable (LAX, STRICT, or NONE)
- Path:
/ - Expiry: Configured session expiry duration
CSRF Cookie
Thecsrf cookie provides CSRF protection:
- Name:
csrf - HttpOnly:
true - Secure: Depends on deployment
- SameSite: Configurable
- Path:
/ - Expiry: Configured CSRF expiry duration
The CSRF token is automatically validated by the server for all state-changing operations.
Security Best Practices
Use HTTPS in Production
Use HTTPS in Production
Always use HTTPS in production to protect session cookies and tokens from interception.
Secure Cookie Storage
Secure Cookie Storage
Token Auto-Renewal
Token Auto-Renewal
JWT tokens are automatically reissued on each request, so you don’t need to manually handle token refresh as long as your session is valid.
Session Expiry
Session Expiry
Sessions expire after a configured duration of inactivity. Implement proper logout functionality in your application.
CSRF Protection
CSRF Protection
All state-changing operations require a valid CSRF token, protecting against cross-site request forgery attacks.
Error Responses
Authentication Errors
401 Unauthorized
session not found- No session cookie providedinvalid token- JWT token is invalid or malformedfailed to decrypt session- Session cookie is corruptedinvalid auth token- Session not found in Redis store
400 Bad Request
csrf token not found- CSRF token missing for state-changing operationsinvalid request body- Request body is malformed
412 Precondition Failed
failed to verify csrf token- CSRF token validation failed
Example Error Response
Programmatic Usage
JavaScript/TypeScript Example
Python Example
Internal Service Authentication
For internal service-to-service communication, the API supports admin role tokens:- Tokens with
role: adminbypass certain authorization checks - Admin role is identified by checking the role claim in the JWT token
- Use
IsInternalService(ctx)to verify admin role from metadata