Forward Token Structure
Lava uses a forward token system for authenticating API requests. A forward token is a base64-encoded string that contains three components:Token Components
| Component | Purpose | Required | Obtained From |
|---|---|---|---|
| Secret Key | Identifies the merchant account | Yes | Generated in merchant dashboard |
| Connection Secret | Links to a specific wallet | Yes | Returned from checkout completion |
| Product Secret | Specifies pricing configuration | Optional | Product configuration in dashboard |
Example Token Flow
Authentication Flow
Step 1: Token Validation
When Lava receives a request with a forward token:- Decode: Base64 decode the token to extract components
- Cache Lookup: Check Redis cache for secret key validation (less than 5ms)
- Database Fallback: If not cached, query database and cache result
- Verify Status: Ensure merchant account is active and not deleted
Step 2: Connection Validation
With a valid secret key, Lava validates the connection:- Connection Lookup: Find connection record by connection secret
- Status Check: Verify connection is
enabledand notdeleted - Wallet Check: Confirm linked wallet exists and is active
- Product Validation: If product secret provided, validate pricing config
Step 3: Balance Verification
Before forwarding the request:- Balance Query: Check wallet’s active balance
- Threshold Check: Compare against minimum required balance
- Overdraft Policy: Apply product’s overdraft behavior (block or allow)
- Update Connection: Mark connection as “limited” if balance is low
All three validation steps complete in under 10ms total through aggressive Redis caching.
Security Best Practices
Secret Key Management
Do:- ✅ Store secret keys in environment variables
- ✅ Use different keys for test vs production
- ✅ Rotate keys periodically (Lava supports multiple active keys)
- ✅ Revoke compromised keys immediately in dashboard
- ❌ Hard-code keys in source code
- ❌ Share keys in public repositories
- ❌ Use production keys in development/testing
- ❌ Send keys via insecure channels (email, Slack, etc.)
Connection Secret Handling
Connection secrets are user-specific and should be stored securely on your backend:- Store in your database linked to user accounts
- Never expose in frontend JavaScript or mobile apps
- Generate fresh tokens for each API request (don’t cache tokens)
- Implement token expiration if storing long-term
Product Secret Usage
Product secrets are optional and used to apply custom pricing:- Safe to use in client-side code (they don’t grant access alone)
- Different products can have different pricing tiers
- Allows A/B testing different fee structures
- Can be rotated without affecting user connections