Overview
Openfront supports multiple authentication methods to suit different use cases. All authentication is handled through theAuthorization header using Bearer tokens or session cookies.
Authentication Methods
Openfront provides four authentication mechanisms:- OAuth Access Tokens - For third-party app integrations
- API Keys - For server-to-server communication
- Customer Tokens - For B2B customer accounts (Openship integration)
- Session Cookies - For browser-based applications
1. OAuth Access Tokens
OAuth tokens are ideal for third-party applications that need to act on behalf of users.How It Works
OAuth tokens are created through the OAuth authorization flow and validated against theOAuthToken model.
Using OAuth Tokens
Bearer token in the format:
Bearer {access_token}Token Validation
The system validates:- Token type must be
access_token - Token must not be revoked (
isRevoked !== "true") - Token must not be expired (
expiresAt > now) - Associated OAuth app must be active
Scopes
OAuth tokens include scopes that define what operations the token can perform. The scopes are attached to the session asoauthScopes and used for permission checking.
2. API Keys
API keys provide server-to-server authentication with fine-grained scope control.Key Format
API keys use theof_ prefix:
Creating an API Key
API keys are created through the Openfront admin dashboard:- Navigate to Settings → API Keys
- Click Create API Key
- Set name, scopes, and optional IP restrictions
- Save the key securely (it’s only shown once)
Using API Keys
Bearer token with
of_ prefix: Bearer of_1234567890abcdefSecurity Features
IP Restrictions
API keys can be restricted to specific IP addresses. The system extracts the client IP from:x-forwarded-forheader (first IP in comma-separated list)x-real-ipheader- Connection remote address
Automatic Expiration
Keys withexpiresAt dates are automatically revoked when expired:
Usage Tracking
Every API request increments usage counters:Scopes
API key scopes define granular permissions:3. Customer Tokens (B2B)
Customer tokens enable B2B customers to access their account information and place orders programmatically.Token Format
Customer tokens use thectok_ prefix:
Use Cases
- Openship integration for B2B order placement
- Automated order creation from ERP systems
- Account balance and invoice management
Using Customer Tokens
Bearer token with
ctok_ prefix: Bearer ctok_1234567890abcdefToken Validation
Customer tokens are validated by:- Checking the
customerTokenfield on the User model - Verifying the user has an active business account
- Ensuring the account status is
active
Generating Customer Tokens
Customers can regenerate their tokens through the API:4. Session Cookies
Session cookies are used for browser-based authentication after user login.Cookie Configuration
Sessions are managed using Iron-sealed cookies:Cookie Properties
Session cookie:
keystonejs-session={sealed_token}- HttpOnly: Yes (prevents XSS attacks)
- Secure: Yes (in production)
- SameSite: lax (CSRF protection)
- Max Age: 360 days
Using Session Cookies
No manual setup needed - browsers automatically send cookies with requests:Testing Authentication
Test API Key
Test Customer Token
Security Best Practices
Recommendations
- Rotate Keys Regularly: Set expiration dates on API keys and rotate them periodically
- Use IP Restrictions: Limit API key usage to known IP addresses when possible
- Minimum Scopes: Grant only the scopes needed for each integration
- Monitor Usage: Track API key usage to detect anomalies
- Secure Storage: Store tokens in environment variables or secret management systems
- HTTPS Only: Always use HTTPS in production to prevent token interception
Environment Variables
Store sensitive credentials in environment variables:Troubleshooting
Common Issues
”Access Denied” Errors
- Verify token format matches the expected prefix (
of_,ctok_, or none for OAuth) - Check token expiration date
- Ensure API key status is
active, notrevoked - Verify IP address is in allowed list (if IP restrictions enabled)
“Insufficient Permissions” Errors
- Check token scopes match required permissions
- Verify user role has necessary access rights
- Ensure OAuth app is active
Session Not Persisting
- Verify
credentials: 'include'is set in fetch requests - Check cookie SameSite settings for cross-origin requests
- Ensure HTTPS in production (required for secure cookies)
Next Steps
API Overview
Learn about the GraphQL API structure
Rate Limiting
Understand rate limits and best practices