Skip to main content
signToken creates an HMAC-SHA256 signed JWT for the GatelitSigned auth scheme. It runs on your backend using the Web Crypto API — available natively in Node.js 18+, Bun, Deno, and all edge runtimes (Cloudflare Workers, Vercel Edge).
Import from @gatelit/sdk/sign (not @gatelit/sdk) to tree-shake the rest of the SDK. The /sign subpath export only includes signToken and its dependencies.

Signature

Returns a dot-separated token string: header.payload.signature.

Options

Examples

Minimal — user identity only

Constrained — specific model with a token cap

Full — end-user tracking with request source

Nuxt server route

Next.js API route

Express route

Token structure

The signed token embeds the following JWT claims the gateway reads:
  • iat — Issued at (epoch seconds)
  • exp — Expires at (iat + ttl)
  • sub — Subject (user ID)
  • orgId — (optional) Organisation context
  • policyOverride — (optional) Encoded model restriction and token cap
  • endUserId — (optional) End-user identifier
  • requestSource — (optional) api | dashboard | eval
The gateway verifies the HMAC signature without a database call — fast, stateless, and cache-friendly.