Documentation Index
Fetch the complete documentation index at: https://mintlify.com/cgwire/zou/llms.txt
Use this file to discover all available pages before exploring further.
Refresh Access Token
GET /api/auth/refresh-token
Tokens are considered outdated every two weeks. This route allows you to extend their lifetime before they get outdated. Use the refresh token to obtain a new access token.Headers
Bearer refresh token for authenticationFormat:
Bearer <refresh_token>Response
Present for browser requests, indicates refresh success
New JWT access token (present for non-browser requests)
Status Codes
200- Token refreshed successfully401- Invalid or expired refresh token403- User does not have required permissions
For browser requests, the new access token is automatically set as an HTTP-only cookie. For API clients, the access token is returned in the response body.
If 2FA enforcement is enabled and the user hasn’t configured 2FA, the new access token will have a
requires_2fa_setup claim that restricts access until 2FA is configured.Token Lifecycle
Access Tokens
Access tokens are short-lived JWT tokens used to authenticate API requests. They are valid for a limited time (typically a few hours) and should be included in theAuthorization header for protected endpoints.
Format:
sub: User ID (subject)identity_type: Always “person” for user tokensexp: Expiration timestampjti: JWT ID for token revocationrequires_2fa_setup: Present when 2FA setup is required (optional)
Refresh Tokens
Refresh tokens are long-lived tokens used to obtain new access tokens. They should be stored securely and only used with the/api/auth/refresh-token endpoint.
Validity:
- Access tokens: Several hours
- Refresh tokens: 2 weeks
- Store refresh tokens securely (encrypted storage, HTTP-only cookies)
- Never expose refresh tokens in URLs or logs
- Refresh access tokens proactively before they expire
- Implement token rotation for enhanced security
Token Revocation
Tokens are automatically revoked when:- User logs out - The logout endpoint revokes the current token
- Token expires - Expired tokens are no longer valid
- User changes password - All existing tokens are invalidated
- Account is deactivated - All tokens for the account become invalid
Manual Token Revocation
To manually revoke a token, use the logout endpoint:Token Storage
Browser Applications
For browser-based applications, Zou automatically manages token storage using HTTP-only cookies when the request comes from a browser user agent:- Access token cookie:
access_token_cookie - Refresh token cookie:
refresh_token_cookie - Cookies are HTTP-only and secure
- Cookies include CSRF protection
Native/Desktop Applications
For non-browser applications, tokens are returned in the response body:- Desktop apps: Use OS-provided secure storage (Keychain, Credential Manager)
- Mobile apps: Use platform-specific secure storage (Keychain, KeyStore)
- Never store tokens in plain text files or unencrypted databases
Token Validation
To validate if a token is still valid, use the authentication check endpoint:Error Handling
Common Token Errors
401 Unauthorized
The token is invalid, expired, or missing:403 Forbidden
The token is valid but the user doesn’t have permission:422 Unprocessable Entity
The token format is invalid:Refresh Token Flow
Implement automatic token refresh to handle expired access tokens:Security Best Practices
Use HTTPS Only
Use HTTPS Only
Always use HTTPS to prevent token interception. Never send tokens over unencrypted HTTP connections.
Store Tokens Securely
Store Tokens Securely
- Browser: Use HTTP-only cookies (automatic with Zou)
- Desktop: Use OS credential managers (Keychain, Windows Credential Manager)
- Mobile: Use platform secure storage (iOS Keychain, Android KeyStore)
- Never store tokens in localStorage or plain text
Implement Token Rotation
Implement Token Rotation
Refresh tokens regularly before expiration. Consider implementing refresh token rotation where each refresh returns a new refresh token.
Handle Token Expiration
Handle Token Expiration
Implement proper error handling for 401 responses and automatically refresh tokens when needed.
Revoke on Logout
Revoke on Logout
Always call the logout endpoint when the user logs out to revoke tokens server-side.
Monitor Token Usage
Monitor Token Usage
Log token usage and watch for suspicious patterns like:
- Multiple simultaneous sessions from different IPs
- Rapid token refresh attempts
- Access from unusual locations