Overview
Risk Legion uses JWT (JSON Web Tokens) for API authentication. Tokens are obtained from Supabase Auth and must be included in all API requests.Obtaining Tokens
Via Supabase Client (Recommended)
Via Script (Testing)
For testing purposes, use the provided script:Using Tokens
HTTP Header
Include the token in theAuthorization header:
cURL Example
JavaScript/TypeScript Example
Token Lifecycle
Token Expiration
| Token Type | Lifetime | Refresh |
|---|---|---|
| Access Token | 1 hour | Use refresh token |
| Refresh Token | 7 days | Re-authenticate |
Automatic Refresh
The Supabase client automatically refreshes tokens:Manual Refresh
Authentication Errors
401 Unauthorized
Token is missing, expired, or invalid:- Check if token is included in request
- Refresh the token if expired
- Re-authenticate if refresh fails
403 Forbidden
Token is valid but user lacks permission:- Verify user has correct role
- Check entity assignments for the user
- Contact admin for access
Security Best Practices
Token Storage
Token Storage
- Store tokens securely (memory or secure storage)
- Never store tokens in localStorage for sensitive apps
- Clear tokens on sign out
- Don’t expose tokens in URLs or logs
Token Transmission
Token Transmission
- Always use HTTPS
- Include token only in Authorization header
- Don’t pass tokens as query parameters
- Validate HTTPS certificates
Token Handling
Token Handling
- Validate token expiration before requests
- Implement automatic refresh logic
- Handle authentication errors gracefully
- Re-authenticate when refresh fails
Server-Side
Server-Side
- Verify JWT signature on every request
- Check token audience and issuer
- Validate token expiration
- Log authentication failures
Test User Creation
Create Test Users
For development and testing:Role-Based Access
Different roles have different API access:| Role | API Access |
|---|---|
| Super Admin | /api/v1/admin/* endpoints |
| Client Admin | All enterprise endpoints |
| Assessor | BRA, Controls, Actions (assigned entities) |
| Reviewer | Read-only access (assigned entities) |
Postman Setup
Environment Variables
Pre-request Script
Troubleshooting
Common Issues
Token not accepted
Token not accepted
- Verify token format:
Bearer <token> - Check for whitespace in token
- Ensure token is for correct environment
- Verify token hasn’t expired
403 after successful auth
403 after successful auth
- User may not be assigned to an enterprise
- Check user role in
enterprise_userstable - Verify entity assignments for Assessors/Reviewers
Token refresh fails
Token refresh fails
- Refresh token may be expired (7 days)
- User may have been deactivated
- Session may have been revoked
- Re-authenticate from scratch