Widget and token
The widget shows users their progress, badges and rewards right on your site. It runs in the browser, so it must never get the API key. Instead, your server issues a short-lived user token.
sequenceDiagram participant B as Browser participant S as Your server participant A as Zirva B->>S: opens the profile page S->>S: sign a 15-minute JWT S-->>B: page and token B->>A: GET /v1/widget/status (Bearer JWT) A-->>B: progress, badges, rewards
The token
Section titled “The token”- JWT format,
HS256algorithm. - The signing key is the whole widget secret string (
wsk_…), in UTF-8, without decoding. - The JWT header’s
kidis the widget secret ID (wk_…). subis the user’suser_ref.iatandexpare required,expno later than 15 minutes afteriat. We allow up to a minute of clock skew.
The token is read-only: it can fetch the status but cannot reserve or redeem a reward.
// Next.js server code: npm install joseimport { SignJWT } from 'jose';
const secret = new TextEncoder().encode(process.env.AAPP_WIDGET_SECRET); // wsk_…
export async function widgetToken(userRef: string) { return new SignJWT({}) .setProtectedHeader({ alg: 'HS256', kid: process.env.AAPP_WIDGET_KEY_ID! }) // wk_… .setSubject(userRef) .setIssuedAt() .setExpirationTime('15m') .sign(secret);}The GET /v1/widget/status response is the same status as GET /v1/users/{user_ref}/status, minus internal fields: no user_ref, no reward and scenario IDs or versions, and no orders.