JWT Tokens Guide
Learn how to implement server-side authentication using JWT tokens for secure backend-to-backend communication with Fanfare.Overview
JWT (JSON Web Token) authentication allows your backend to securely authenticate consumers with Fanfare without client-side credential exposure. This is the recommended approach for production applications with existing user accounts. What you’ll learn:- Understanding Fanfare’s JWT authentication flow
- Implementing server-side token exchange
- Validating admission grants
- Securing your integration
Prerequisites
- Fanfare account with API credentials including secret key
- Backend server (Node.js, Python, Go, etc.)
- Basic understanding of JWT and authentication concepts
When to Use JWT Authentication
Use JWT authentication when:- Your application has existing user accounts
- You need server-to-server authentication
- You want to validate admission grants before checkout
- You require enhanced security for high-value transactions
Authentication Architecture

Step 1: External Authentication Endpoint
Create a backend endpoint to generate exchange codes. For the full authorize/exchange contract — including request fields, response shapes, and identity consolidation viacanonicalSubject — see the External Authentication guide.
Node.js/Express
Python/FastAPI
Step 2: Client-Side Exchange
Exchange the code in the browser:Step 3: Grant Validation Endpoint
Validate admission grants during checkout:Node.js/Express
Step 4: Secure Checkout Flow
Validate admission before processing checkout:Step 5: JWT Token Structure
Understanding the tokens Fanfare uses:Access Token Payload
Admission Grant Context
Step 6: Security Best Practices
Protect Your Secret Key
Validate Token Origin
Implement Rate Limiting
Validate Claims
Step 7: Error Handling
Handle common authentication errors:Complete Integration Example
Backend (Node.js)
Frontend (React)
Troubleshooting
Exchange Code Expired
- Codes expire after 60 seconds
- Generate new code immediately before exchange
- Check for network latency issues
Secret Key Errors
- Verify key has
sk_prefix (notpk_) - Check key permissions in dashboard
- Ensure the key belongs to the correct Fanfare organization and account
Token Validation Fails
- Verify consumer ID matches
- Check token hasn’t expired
- Ensure the request comes from the active session
What’s Next
- Checkout Integration - Complete checkout flows
- Webhooks - Server-side event handling
- Error Handling - Robust error management