/** The claims the emulator itself resolves and mints. */ export interface JWTClaims { sub: string; sid?: string; org_id?: string; role?: string; /** * Every role the membership grants. Production emits `roles` alongside the singular * `role`, and the WorkOS SDKs read it; a token carrying only `role` passes locally and * loses the claim in production. The emulator models one role per membership, matching * what the `organization_membership` serializer already does. */ roles?: string[]; permissions?: string[]; /** * OAuth scopes granted to an M2M (client_credentials) token: space-delimited, * per RFC 8693 §4.2 — the claim name and encoding production emits, and the one * the WorkOS SDKs read. Not an array, and not `scp`. */ scope?: string; /** Unique token identifier. Required on M2M tokens by the WorkOS SDKs. */ jti?: string; /** The OAuth client the token was minted for; production AuthKit includes it. */ client_id?: string; /** Unix-seconds timestamp of the user's most recent active authentication. */ auth_time?: number; /** * RFC 8693 actor claim, present only when the session was started via impersonation. * The nested `sub` carries the impersonator's email, the identifier the session-tokens * reference documents (and the only one production surfaces for impersonators). */ act?: { sub: string; sub_profile?: string; }; /** * Marks the kind of subject `sub` names. Agent access tokens carry `ai_agent` so a * consumer can tell an agent instance from a user without inspecting the id prefix. */ sub_profile?: string; /** Free-text purpose an agent access token was minted for. */ intent?: { text: string; }; /** Entitlement slugs of the organization the session is scoped to; omitted when empty. */ entitlements?: string[]; /** Slugs of feature flags resolving true for the session's user/org context; omitted when empty. */ feature_flags?: string[]; iss: string; aud: string; exp: number; iat: number; } /** * A decoded token: the minted claims, plus whatever else a JWT template added. The index * signature is what makes template claims readable off a verified token. */ export type JWTPayload = JWTClaims & { [claim: string]: unknown; }; interface SignOptions { expiresIn?: number; /** * Extra claims to merge into the token, as rendered from a JWT template. Reserved * claims (`iss`, `sub`, `exp`, `iat`, `nbf`, `jti`) are dropped: the token's own identity * is not something a template gets to restate. */ claims?: Record; /** * AuthKit client to scope `iss` to, giving the per-client issuer production mints for * `/user_management/authenticate` tokens. Omit and `iss` is the bare configured issuer, * which is what the M2M, SSO and widget tokens want — none of them is the token the * AuthKit discovery document describes. */ issuerClientId?: string; /** * JOSE header `typ`. Defaults to `JWT`; agent access tokens use RFC 9068's `at+jwt`, as * production does. */ typ?: string; } export interface SigningKeyOptions { /** * PEM-encoded RSA private key to sign with. Omit and a fresh key is generated at * startup, which means a JWKS consumer must refetch after every restart. Pin it to keep * the JWKS — and therefore any token minted against it — stable across restarts. */ privateKey?: string; /** * `kid` to advertise in the JWKS and in token headers. Defaults to a value derived from * the key itself, so a pinned key yields a stable `kid` without setting this. */ kid?: string; } export declare class JWTManager { private privateKey; private publicKey; private kid; private _issuer; /** * Base the `iss` claim is built from. Trailing slashes are stripped on the way in, whichever * way it is set, because `authKitIssuer` concatenates: `--issuer https://api.workos.com/` * would otherwise mint `https://api.workos.com//user_management/client_x`, which equals * nothing production emits and nothing a verifier is comparing against. Settable because * `createEmulator` learns the bound URL only after listen() resolves an ephemeral port. */ get issuer(): string; set issuer(value: string); constructor(issuer?: string, signingKey?: SigningKeyOptions); /** * The `iss` of an AuthKit access token, and the `issuer` its OIDC discovery document * advertises — one function so the two cannot drift. * * Production derives it from the environment's client id, not the bare API URL: * `${apiUrl}/user_management/${clientId}` (`getIssuer` in * `api-services/src/jwt-claims/build-access-token-claims.ts`, under the default * `issuerType: 'ClientId'`). Its `'Legacy'` issuer type returns the bare URL instead — * what the emulator used to mint for every token — so a verifier written against a * current WorkOS environment saw an `iss` it would have rejected in production. * * It also makes the discovery document valid: OIDC Discovery 1.0 §4.3 requires `issuer` * to equal the URL prefix the document was fetched from, and that prefix carries the * client id. Reach the emulator under a name other than its configured base URL and the * two diverge again — set `--issuer` to that name if a client enforces §4.3. */ authKitIssuer(clientId: string): string; sign(payload: Omit, options?: SignOptions): string; verify(token: string): JWTPayload; getJWKS(): { keys: Record[]; }; getPublicKeyPem(): string; } export {};