Authentication
Billbora uses a hybrid authentication system designed for both server-to-server integrations and frontend applications. This guide covers all authentication methods and best practices.Authentication Methods
API Keys
Simple authentication for server-to-server integrations
JWT Tokens
Secure authentication for frontend applications with organization context
API Keys
API keys are the simplest way to authenticate with the Billbora API, ideal for server-to-server integrations.Getting API Keys
1
Log into Billbora
Navigate to app.billbora.com and log in.
2
Go to API Settings
Navigate to Settings → API → Credentials.
3
Generate API Key
Click Generate New API Key and copy the generated key.
Using API Keys
Include your API key in theAuthorization header with the Bearer scheme:
API Key Security
Best Practices
Best Practices
- Store API keys in environment variables, never in code
- Use different keys for different environments (development, staging, production)
- Rotate keys regularly (every 90 days recommended)
- Monitor API key usage in your dashboard
- Revoke compromised keys immediately
Key Management
Key Management
- Each organization can have multiple API keys
- Keys can be scoped to specific permissions
- Usage analytics are available per key
- Keys can be temporarily disabled without deletion
JWT Authentication
JWT authentication is designed for frontend applications and provides organization context switching capabilities.Authentication Flow
The JWT authentication flow involves multiple steps:Step 1: Supabase Authentication
First, authenticate with Supabase to get the initial JWT token:Step 2: Token Exchange
Exchange the Supabase token for a Billbora token with organization context:Step 3: Using JWT Tokens
Use the Billbora JWT token for API requests:Token Refresh
JWT tokens expire after 1 hour. Use the refresh token to get a new access token:Organization Context
One of the key features of Billbora’s authentication system is organization context switching.Switching Organizations
Users can belong to multiple organizations and switch between them:Getting Available Organizations
Fetch organizations the current user has access to:Error Handling
Handle authentication errors gracefully:Common Error Codes
Common Error Codes
invalid_credentials: Wrong email/password combinationtoken_expired: JWT token has expired, refresh neededinvalid_token: Malformed or invalid tokenorganization_access_denied: User doesn’t have access to requested organizationrate_limited: Too many authentication attempts
Error Response Format
Error Response Format
Security Best Practices
Token Storage
- Store tokens securely (not in localStorage for sensitive apps)
- Use httpOnly cookies for web applications when possible
- Clear tokens on logout
- Implement token expiration checking
Network Security
- Always use HTTPS in production
- Implement proper CORS policies
- Validate SSL certificates
- Monitor for unusual authentication patterns
Application Security
- Implement proper session management
- Use secure password requirements
- Enable two-factor authentication
- Implement account lockout policies
Monitoring
- Monitor authentication failures
- Set up alerts for suspicious activity
- Regularly audit API key usage
- Implement request rate limiting