Authentication
JWT (JSON Web Token) is the recommended way to authenticate SDK requests. It provides cryptographic verification, automatic token refresh, and per-user session ownership.JWT signing keys are managed in the Moss Dashboard under API Keys.
How It Works
- Your backend holds a JWT signing key (generated in the Moss Dashboard)
- When a user loads your app, your backend signs a JWT with the user’s identity
- The SDK sends this token with every request to the Moss backend
- The Moss backend verifies the signature and extracts the user identity
Setup
1. Generate a Signing Key
In the Moss Dashboard, navigate to API Keys and create a JWT signing key. You’ll receive:- Key ID (
kid) — included in the JWT header - Secret — used to sign tokens (store securely, never expose to the client)
2. Create a Token Endpoint
Add an endpoint to your backend that signs JWTs for authenticated users.- Node.js
- Python
3. Configure the SDK
Pass agetJwt function that fetches a fresh token from your endpoint. The SDK calls this automatically when the token expires.
- React (NPM)
- CDN (Script Tag)
JWT Claims Reference
Token Refresh
The SDK handles token refresh automatically when you providegetJwt:
- Checks token expiration before each request
- Calls
getJwt()when the token is within 60 seconds of expiring - Retries failed requests with the new token
jwt instead:
Next Steps
Configuration
Full SDK configuration reference
Installation
Installation guides by framework