Overview
The Onboarding API uses JWT (JSON Web Token) Bearer Token authentication. Unlike the QR API which uses HTTP Basic Auth, the Onboarding API requires you to generate and sign JWT tokens with your secret key.JWT tokens ensure that requests are authentic and haven’t been tampered with. The secret key is private and should never be exposed publicly.
How JWT Authentication Works
1
Generate JWT Payload
Create a JSON payload containing the account ID and email address
2
Sign with Secret Key
Sign the payload with your secret key using the HS256 algorithm
3
Include in Authorization Header
Send the JWT token in the
Authorization: Bearer {token} header4
Server Verification
Modulus Labs verifies the token signature using the same secret key
Authentication Flow
Secret Key
Your secret key will be provided by Modulus Labs. Store it securely:JWT Payload Structure
The JWT payload must contain these required fields:| Field | Type | Required | Description |
|---|---|---|---|
sub | number | Yes | Account ID received from Create Account API |
email | string | Yes | Email address registered to the account |
Example Payload
The Account ID received from the Create Account API. This identifies which merchant account is making the request.Example:
1, 12345The email address registered to the merchant account. Must match the email used during account creation.Format: Valid email addressExample:
"[email protected]", "[email protected]"Generating JWT Tokens
Here’s how to generate JWT tokens in different languages:Required Libraries
Install the necessary JWT libraries for your language:- Node.js
- Python
- PHP
- Ruby
- Go
Making Authenticated Requests
Include the JWT token in theAuthorization header with the Bearer prefix:
Token Best Practices
Generate Per Request
Generate a new token for each API request rather than reusing old tokens
Secure Storage
Store secret keys in environment variables or secret management systems
HTTPS Only
Always send tokens over HTTPS to prevent interception
Server-Side Only
Never generate or store tokens in client-side JavaScript
Validate Inputs
Validate accountId and email before generating tokens
Handle Errors
Implement proper error handling for token generation failures
Token Expiration
The Onboarding API JWT tokens do not require an expiration time (
exp claim). However, you can add one for additional security if desired.Optional: Adding Expiration
If you want to add token expiration for extra security:Error Responses
Authentication errors return a standard error format:401 Unauthorized
Invalid Token
Invalid Token
Cause: Token signature doesn’t match or token is malformedSolution:
- Verify you’re using the correct secret key
- Ensure the token is properly formatted
- Check for any whitespace in the token string
Expired Token
Expired Token
Cause: Token has expired (if you added an
exp claim)Solution:- Generate a new token
- Increase expiration time if needed
Missing Token
Missing Token
Cause: Authorization header is missing or doesn’t contain Bearer tokenSolution:
- Ensure header format is:
Authorization: Bearer {token} - Check that the token is not empty
Invalid Credentials
Invalid Credentials
Cause: Account ID or email in payload doesn’t match account recordsSolution:
- Verify the account ID is correct
- Ensure email matches the registered account email
Security Considerations
Security Checklist
1
Store Keys Securely
Use environment variables, AWS Secrets Manager, or similar secure storage
2
Use HTTPS
All API requests must be made over HTTPS (HTTP will fail)
3
Server-Side Generation
Always generate JWT tokens on your backend server, never in browser JavaScript
4
Rotate Keys
Implement a key rotation strategy if your secret key is compromised
5
Monitor Usage
Log and monitor API usage to detect suspicious activity