Overview
Coinbase Onramp and Offramp use session tokens for secure authentication. Session tokens are generated on your backend server using your CDP API keys and passed in the URL instead of including sensitive data like wallet addresses as query parameters.How Session Tokens Work
Session tokens provide a secure way to initialize Onramp/Offramp experiences:- Your backend server generates a session token using the CDP API
Security Requirements must be enforced: Your backend API that generates session tokens must implement proper security measures. See Security Requirements for complete implementation guidance.
- The token encapsulates user addresses, supported assets, and client IP
- You pass the token in the Onramp/Offramp URL
- The token expires after 5 minutes and can only be used once
Example URL Format
Implementation Steps
Step 1: Create a CDP Secret API Key
Optional API Key File DownloadFor enhanced security, API key files are no longer automatically downloaded. If you need to reference your API key via file path in your code, click the Download API key button in the modal to save the key file. Otherwise, you can copy the key details directly from the modal and use them as environment variables (recommended for better security).
- Navigate to your project’s API Keys tab
- Select the Secret API Keys section
- Click Create API key
- Configure your key settings (IP allowlist recommended)
- Create your API key and securely store the details
Session tokens must be generated server-side, so you’ll need a Secret API Key (not a Client API Key).
Step 2: Set Up JWT Authentication
To generate session tokens, you need to authenticate with CDP using JWT Bearer tokens. Follow the CDP API key authentication guide to set up JWT generation.Step 3: Generate Session Tokens
Use the Session Token API to generate tokens for each user session:For complete API documentation including all parameters and response formats, see the Create Session Token API Reference.
- Extract the client IP from the network layer of the TCP request to your API
- Do not trust HTTP headers like
X-Forwarded-For
— these can be easily spoofed - Include the client IP in the CDP API call for validation
Step 4: Create Onramp/Offramp URLs
Use the session token to create your Onramp/Offramp URLs:For detailed information about URL parameters and options, see:
- Generating an Onramp URL for onramp parameters
- Generating an Offramp URL for offramp parameters
Onramp URL Example
Offramp URL Example
Session Token Properties
- Expiration: Session tokens expire after 5 minutes
- Single-use: Each token can only be used once
- Server-side generation: Must be generated on your backend server
Support and Resources
- Sample Code: Session Token Implementation
- Authentication Guide: CDP API Key Authentication
- Security Requirements: CORS Security Requirements — Essential CORS protection for your integration
- Community Support: CDP Discord