API Security Best Practices
Comprehensive API security patterns and practices used in Ever Gauzy.
Authentication
All API endpoints (except public endpoints) require JWT authentication:
Authorization: Bearer {jwt-token}
Token Lifecycle
- User authenticates via
/api/auth/login - Server issues a JWT access token (short-lived) and refresh token (long-lived)
- Client includes access token in all requests
- When access token expires, client uses refresh token to get a new one
- When refresh token expires, user must re-authenticate
Token Configuration
| Variable | Description | Recommended |
|---|---|---|
JWT_SECRET | Signing key | 256-bit random |
JWT_TOKEN_EXPIRATION_TIME | Access token TTL | 3600 (1 hour) |
JWT_REFRESH_SECRET | Refresh key | 256-bit random |
JWT_REFRESH_EXPIRATION_TIME | Refresh token TTL | 604800 (7 days) |