Skip to main content

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

  1. Your backend holds a JWT signing key (generated in the Moss Dashboard)
  2. When a user loads your app, your backend signs a JWT with the user’s identity
  3. The SDK sends this token with every request to the Moss backend
  4. 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)
The secret is shown only once. Store it in your backend’s environment variables or secrets manager.

2. Create a Token Endpoint

Add an endpoint to your backend that signs JWTs for authenticated users.

3. Configure the SDK

Pass a getJwt function that fetches a fresh token from your endpoint. The SDK calls this automatically when the token expires.

JWT Claims Reference

Token Refresh

The SDK handles token refresh automatically when you provide getJwt:
  • Checks token expiration before each request
  • Calls getJwt() when the token is within 60 seconds of expiring
  • Retries failed requests with the new token
If you have a static token that doesn’t need refresh, use jwt instead:
Prefer getJwt over jwt for production applications. It ensures tokens are always fresh.

Next Steps

Configuration

Full SDK configuration reference

Installation

Installation guides by framework