Authentication
Fanfare uses different authentication methods depending on the API and use case.API Keys
Every organization has two types of API keys:Publishable Key
- Format:
pk_live_xxxxxxxxxxxxorpk_test_xxxxxxxxxxxx - Usage: Client-side code (browsers, mobile apps)
- Permissions: Read-only access to public resources, consumer session creation
- Security: Safe to expose in client-side code
Secret Key
- Format:
sk_live_xxxxxxxxxxxxorsk_test_xxxxxxxxxxxx - Usage: Server-side code only
- Permissions: Full API access including write operations
- Security: Must be kept confidential, never expose in client-side code
Authentication Methods
Consumer API - Browser (Publishable Key)
For browser-based consumer interactions, use the publishable key in theX-Publishable-Key header:
Consumer API - Authenticated Consumer
After a consumer authenticates (via OTP, external auth, etc.), use the access token:Consumer API - Server-Side (Secret Key)
For server-to-server calls to the Consumer API, use the secret key:Admin API (Secret Key Required)
All Admin API calls require the secret key:Consumer Authentication Flows
Guest Session
Create an anonymous session for tracking purposes:OTP Authentication (Email)
Request a one-time password:OTP Authentication (Phone)
Request an SMS code:External Authentication (Server-Side)
For integrating with your existing authentication system: Step 1: Create exchange code (server-side)Token Refresh
Refresh an expired access token:Logout
Invalidate the current session:Token Structure
Access tokens are JWTs containing:Token Lifetimes
| Token Type | Default Lifetime | Configurable |
|---|---|---|
| Access Token | 1 hour | Yes |
| Refresh Token | 30 days | Yes |
| Exchange Code | 60 seconds | No |
Security Best Practices
- Never expose secret keys in client-side code, version control, or logs
- Rotate keys regularly using the Admin dashboard
- Use environment variables for storing keys in server-side applications
- Implement token refresh to maintain sessions without re-authentication
- Use HTTPS for all API communications (enforced by Fanfare)