@broberg/sso 0.18.2 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dpop.ts","../src/fetch-ticket.ts","../src/ticket.ts"],"names":["decodeProtectedHeader","jwtVerify"],"mappings":";;;;;;AAuCA,eAAsB,aAAA,GAAkC;AACtD,EAAA,MAAM,EAAE,UAAA,EAAY,SAAA,EAAU,GAAI,MAAM,gBAAgB,OAAA,EAAS,EAAE,WAAA,EAAa,KAAA,EAAO,CAAA;AACvF,EAAA,MAAM,GAAA,GAAM,MAAM,SAAA,CAAU,SAAS,CAAA;AACrC,EAAA,MAAM,SAAA,GAAiB,EAAE,GAAA,EAAK,GAAA,CAAI,GAAA,EAAK,GAAA,EAAK,GAAA,CAAI,GAAA,EAAK,CAAA,EAAG,GAAA,CAAI,CAAA,EAAG,CAAA,EAAG,IAAI,CAAA,EAAE;AACxE,EAAA,OAAO,EAAE,UAAA,EAAY,SAAA,EAAW,KAAK,MAAM,sBAAA,CAAuB,SAAS,CAAA,EAAE;AAC/E;AAEA,IAAM,GAAA,GAAM,IAAI,WAAA,EAAY;AAC5B,IAAM,MAAA,GAAS,CAAC,KAAA,KACd,IAAA,CAAK,OAAO,YAAA,CAAa,GAAG,IAAI,UAAA,CAAW,KAAK,CAAC,CAAC,CAAA,CAAE,OAAA,CAAQ,KAAA,EAAO,GAAG,CAAA,CAAE,OAAA,CAAQ,OAAO,GAAG,CAAA,CAAE,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AAG/G,eAAsB,gBAAgB,MAAA,EAAiC;AACrE,EAAA,OAAO,MAAA,CAAO,MAAM,MAAA,CAAO,MAAA,CAAO,MAAA,CAAO,WAAW,GAAA,CAAI,MAAA,CAAO,MAAM,CAAC,CAAC,CAAA;AACzE;AAGO,SAAS,aAAa,GAAA,EAAqB;AAChD,EAAA,MAAM,CAAA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084.157 — DPoP (RFC 9449): a bound ticket works only for whoever holds the key\n * (broberg-id-F087.16, joint design #2572/#2574).\n *\n * A DPoP-bound ticket carries `cnf.jkt`, the thumbprint of the caller's public\n * key. With every request the caller signs a short PROOF (method, URL, time, a\n * hash of the ticket) with the matching private key. A ticket copied out of a log\n * is useless on another machine: it has the ticket, not the key.\n *\n * THE RULE THAT MAKES IT PROTECTION (agreed with broberg-id, (A) in #2574): once a\n * receiver verifies with this version, a ticket WITH cnf.jkt needs a valid proof —\n * also while DPoP is otherwise optional. `requireDpop` only decides whether\n * UNBOUND tickets are still accepted. Were bound tickets accepted without a proof\n * during the rollout, a stolen bound ticket would work as bearer the whole time.\n *\n * Not here yet: server nonces (RFC 9449 §8). The jti replay store covers replay\n * inside the iat window.\n */\nimport {\n SignJWT,\n calculateJwkThumbprint,\n decodeProtectedHeader,\n exportJWK,\n generateKeyPair,\n importJWK,\n jwtVerify,\n type JWK,\n} from \"jose\";\nimport { SsoError } from \"./client.js\";\n\n/** One process's DPoP key. The private half cannot be exported. */\nexport interface DpopKey {\n privateKey: CryptoKey;\n publicJwk: JWK;\n /** RFC 7638 thumbprint — what BID puts in the ticket's cnf.jkt. */\n jkt: string;\n}\n\n/** A fresh ES256 key pair, private key non-extractable, never written anywhere. */\nexport async function createDpopKey(): Promise<DpopKey> {\n const { privateKey, publicKey } = await generateKeyPair(\"ES256\", { extractable: false });\n const jwk = await exportJWK(publicKey); // a public key is always exportable\n const publicJwk: JWK = { kty: jwk.kty, crv: jwk.crv, x: jwk.x, y: jwk.y };\n return { privateKey, publicJwk, jkt: await calculateJwkThumbprint(publicJwk) };\n}\n\nconst enc = new TextEncoder();\nconst b64url = (bytes: ArrayBuffer) =>\n btoa(String.fromCharCode(...new Uint8Array(bytes))).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n\n/** `ath`: base64url(SHA-256(ticket)) — ties a proof to one ticket. */\nexport async function accessTokenHash(ticket: string): Promise<string> {\n return b64url(await crypto.subtle.digest(\"SHA-256\", enc.encode(ticket)));\n}\n\n/** RFC 9449 §4.3: htu is compared without query and fragment. */\nexport function normalizeHtu(url: string): string {\n const u = new URL(url);\n return `${u.protocol}//${u.host}${u.pathname}`;\n}\n\n/** Sign one proof. Pass `ticket` when calling a resource server (adds ath); omit it for BID's token endpoint. */\nexport async function createDpopProof(\n key: DpopKey,\n opts: { method: string; url: string; ticket?: string; now?: () => number },\n): Promise<string> {\n const payload: Record<string, unknown> = {\n jti: crypto.randomUUID(),\n htm: opts.method.toUpperCase(),\n htu: normalizeHtu(opts.url),\n iat: Math.floor((opts.now?.() ?? Date.now()) / 1000),\n };\n if (opts.ticket !== undefined) payload.ath = await accessTokenHash(opts.ticket);\n return new SignJWT(payload).setProtectedHeader({ typ: \"dpop+jwt\", alg: \"ES256\", jwk: key.publicJwk }).sign(key.privateKey);\n}\n\n/**\n * Remembers which proofs were already used. The default is in-memory, which\n * holds on ONE machine: a receiver running on two machines must pass a shared\n * store, or a proof replayed against the other machine inside the window passes.\n */\nexport interface ReplayStore {\n /** Record `key`; resolve true if it was already recorded within `ttlMs`. */\n seen(key: string, ttlMs: number): Promise<boolean>;\n}\n\nexport function createMemoryReplayStore(now: () => number = () => Date.now()): ReplayStore {\n const entries = new Map<string, number>();\n return {\n async seen(key, ttlMs) {\n const t = now();\n for (const [k, until] of entries) if (until <= t) entries.delete(k);\n if (entries.has(key)) return true;\n entries.set(key, t + ttlMs);\n return false;\n },\n };\n}\n\nexport interface VerifyProofOptions {\n method: string;\n /** The receiver's PUBLIC URL for this request (behind a proxy the process sees an internal one). */\n url: string;\n ticket: string;\n jkt: string;\n replay: ReplayStore;\n iatWindowSec: number;\n now: () => number;\n}\n\nconst ASYMMETRIC = new Set([\"ES256\", \"ES384\", \"ES512\", \"EdDSA\", \"PS256\", \"PS384\", \"PS512\", \"RS256\", \"RS384\", \"RS512\"]);\n\n/** Throws SsoError naming the first thing that is wrong. */\nexport async function verifyDpopProof(proof: string, o: VerifyProofOptions): Promise<void> {\n let header;\n try {\n header = decodeProtectedHeader(proof);\n } catch {\n throw new SsoError(\"DPoP proof is not a JWS\");\n }\n if (header.typ !== \"dpop+jwt\") throw new SsoError(`DPoP proof has typ ${JSON.stringify(header.typ)}, not \"dpop+jwt\"`);\n if (!header.alg || !ASYMMETRIC.has(header.alg)) throw new SsoError(`DPoP proof alg ${JSON.stringify(header.alg)} is not an accepted asymmetric algorithm`);\n const jwk = header.jwk as JWK | undefined;\n if (!jwk || typeof jwk !== \"object\") throw new SsoError(\"DPoP proof carries no jwk\");\n if (\"d\" in jwk) throw new SsoError(\"DPoP proof jwk contains a private key\");\n\n let payload;\n try {\n const key = await importJWK(jwk, header.alg);\n ({ payload } = await jwtVerify(proof, key, { typ: \"dpop+jwt\", algorithms: [header.alg] }));\n } catch (e) {\n throw new SsoError(`DPoP proof signature rejected: ${e instanceof Error ? e.message : String(e)}`);\n }\n\n if ((await calculateJwkThumbprint(jwk)) !== o.jkt) throw new SsoError(\"DPoP proof key does not match the ticket's cnf.jkt\");\n if (payload.htm !== o.method.toUpperCase()) throw new SsoError(`DPoP proof is for ${JSON.stringify(payload.htm)}, the request is ${o.method.toUpperCase()}`);\n let htu: string;\n try {\n htu = normalizeHtu(String(payload.htu));\n } catch {\n throw new SsoError(\"DPoP proof htu is not a URL\");\n }\n if (htu !== normalizeHtu(o.url)) throw new SsoError(`DPoP proof is for ${htu}, the request is ${normalizeHtu(o.url)}`);\n const nowSec = Math.floor(o.now() / 1000);\n if (typeof payload.iat !== \"number\" || Math.abs(nowSec - payload.iat) > o.iatWindowSec) {\n throw new SsoError(`DPoP proof iat is outside ±${o.iatWindowSec}s`);\n }\n if (payload.ath !== (await accessTokenHash(o.ticket))) throw new SsoError(\"DPoP proof ath does not match this ticket\");\n if (typeof payload.jti !== \"string\" || payload.jti === \"\") throw new SsoError(\"DPoP proof has no jti\");\n if (await o.replay.seen(`${o.jkt}:${payload.jti}`, o.iatWindowSec * 2 * 1000)) {\n throw new SsoError(\"DPoP proof was already used (jti replay)\");\n }\n}\n","/**\n * F084.154 — fetch a BrobergID ticket WITHOUT a key (broberg-id-F087.10/.11).\n *\n * The sending half of F084.153: a workload proves who it is with the identity its\n * platform already gives it, and BID exchanges that for a short-lived ticket\n * (RFC 8693 token exchange). No secret is stored anywhere.\n *\n * Fly.io POST unix:/.fly/api /v1/tokens/oidc {aud: issuer}\n * GitHub Actions GET $ACTIONS_ID_TOKEN_REQUEST_URL&audience=issuer\n * (needs `permissions: id-token: write` in the workflow)\n * then POST {issuer}/oauth2/token grant_type=…token-exchange\n *\n * Reference implementation: broberg-id/.github/workflows/ticket-probe.yml.\n * The ticket itself is never logged or put in an error message.\n */\nimport { existsSync } from \"node:fs\";\nimport { request } from \"node:http\";\nimport { createDpopKey, createDpopProof, type DpopKey } from \"./dpop.js\";\n\nexport const DEFAULT_ISSUER = \"https://id.broberg.ai\";\nconst FLY_SOCKET = \"/.fly/api\";\n\n/** No platform identity to exchange: not on Fly, not in a GitHub Actions job with id-token: write. */\nexport class NoWorkloadIdentityError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"NoWorkloadIdentityError\";\n }\n}\n\n/**\n * BID refused the exchange. `code` is BID's own error name (the part of\n * error_description before the colon, e.g. `no_rule_for_audience`), `status` the\n * HTTP status. A 4xx is PERMANENT for this request — fix the rule, do not retry.\n */\nexport class TicketExchangeError extends Error {\n constructor(message: string, readonly code: string, readonly status: number) {\n super(message);\n this.name = \"TicketExchangeError\";\n }\n}\n\n/** BID or the platform could not be reached, or answered 5xx. TRANSIENT — retry later. */\nexport class TicketUnavailableError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"TicketUnavailableError\";\n }\n}\n\nexport interface TicketClientOptions {\n issuer?: string;\n /** Renew this many seconds before exp. Default 30. */\n renewBeforeSec?: number;\n /** Injectable for tests. */\n env?: Record<string, string | undefined>;\n fetchImpl?: typeof fetch;\n now?: () => number;\n /** Ask Fly's machine API for an OIDC token. Default: POST over the /.fly/api unix socket. */\n flyOidc?: (aud: string) => Promise<string>;\n /** Whether the Fly socket is present. Default: checks /.fly/api. */\n onFly?: () => boolean;\n /**\n * F084.157 — ask BID for DPoP-BOUND tickets. One ES256 key per client\n * (non-extractable, never stored); every call then needs a proof, which\n * `authHeaders` makes. Default false: bearer tickets, exactly as before.\n */\n dpop?: boolean;\n}\n\n/** Headers for one call to a receiver. With `dpop`, `authorization` is `DPoP <ticket>` and `dpop` is the proof. */\nexport interface TicketAuthHeaders {\n authorization: string;\n dpop?: string;\n}\n\nexport interface TicketClient {\n /** A ticket for `audience` (BID's short name, e.g. \"discovery\"), from cache while it is fresh. */\n get(opts: { audience: string; scope?: string }): Promise<string>;\n /**\n * F084.157 — the headers for ONE request to a receiver: a ticket plus, with\n * `dpop`, a fresh proof bound to this method and URL (use it once). Without\n * `dpop`: `{ authorization: \"Bearer <ticket>\" }`.\n */\n authHeaders(opts: { audience: string; scope?: string; method: string; url: string }): Promise<TicketAuthHeaders>;\n}\n\nfunction flyOidcOverSocket(aud: string): Promise<string> {\n return new Promise((resolve, reject) => {\n const body = JSON.stringify({ aud });\n const req = request(\n { socketPath: FLY_SOCKET, path: \"/v1/tokens/oidc\", method: \"POST\", headers: { \"content-type\": \"application/json\", \"content-length\": Buffer.byteLength(body) } },\n (res) => {\n let data = \"\";\n res.setEncoding(\"utf8\");\n res.on(\"data\", (c) => (data += c));\n res.on(\"end\", () => {\n if ((res.statusCode ?? 0) >= 200 && (res.statusCode ?? 0) < 300) resolve(data.trim());\n else reject(new TicketUnavailableError(`Fly OIDC answered ${res.statusCode}`));\n });\n },\n );\n req.on(\"error\", (e) => reject(new TicketUnavailableError(`Fly OIDC socket: ${e.message}`)));\n req.end(body);\n });\n}\n\n/** Seconds since the epoch at which a JWT expires, or null if it cannot be read. */\nfunction jwtExp(token: string): number | null {\n try {\n const payload = JSON.parse(Buffer.from(token.split(\".\")[1] ?? \"\", \"base64url\").toString(\"utf8\"));\n return typeof payload.exp === \"number\" ? payload.exp : null;\n } catch {\n return null;\n }\n}\n\nexport function createTicketClient(options: TicketClientOptions = {}): TicketClient {\n const issuer = (options.issuer ?? DEFAULT_ISSUER).replace(/\\/+$/, \"\");\n const renewBeforeSec = options.renewBeforeSec ?? 30;\n const env = options.env ?? process.env;\n const fetchImpl = options.fetchImpl ?? fetch;\n const now = options.now ?? (() => Date.now());\n const flyOidc = options.flyOidc ?? flyOidcOverSocket;\n const onFly = options.onFly ?? (() => !!env.FLY_APP_NAME && existsSync(FLY_SOCKET));\n\n const cache = new Map<string, { token: string; exp: number }>();\n const inFlight = new Map<string, Promise<string>>();\n let dpopKey: Promise<DpopKey> | null = null;\n const ownKey = () => (dpopKey ??= createDpopKey());\n\n async function platformToken(): Promise<string> {\n if (onFly()) return flyOidc(issuer);\n const url = env.ACTIONS_ID_TOKEN_REQUEST_URL;\n const bearer = env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;\n if (url && bearer) {\n let res: Response;\n try {\n res = await fetchImpl(`${url}&audience=${encodeURIComponent(issuer)}`, { headers: { authorization: `Bearer ${bearer}` } });\n } catch (e) {\n throw new TicketUnavailableError(`GitHub OIDC endpoint unreachable: ${e instanceof Error ? e.message : String(e)}`);\n }\n if (!res.ok) throw new TicketUnavailableError(`GitHub OIDC endpoint answered ${res.status}`);\n const { value } = (await res.json()) as { value?: string };\n if (!value) throw new TicketUnavailableError(\"GitHub OIDC endpoint returned no token\");\n return value;\n }\n throw new NoWorkloadIdentityError(\n \"No workload identity to exchange for a ticket: not on a Fly machine (FLY_APP_NAME + /.fly/api) and not in a GitHub Actions job \" +\n \"(ACTIONS_ID_TOKEN_REQUEST_URL/_TOKEN — add `permissions: id-token: write`). A Mac session keeps using its session key.\",\n );\n }\n\n async function exchange(audience: string, scope: string | undefined): Promise<{ token: string; exp: number }> {\n const subject = await platformToken();\n const form = new URLSearchParams({\n grant_type: \"urn:ietf:params:oauth:grant-type:token-exchange\",\n subject_token: subject,\n subject_token_type: \"urn:ietf:params:oauth:token-type:jwt\",\n audience,\n });\n if (scope) form.set(\"scope\", scope);\n let res: Response;\n try {\n const tokenUrl = `${issuer}/oauth2/token`;\n const headers: Record<string, string> = { \"content-type\": \"application/x-www-form-urlencoded\" };\n if (options.dpop) headers.dpop = await createDpopProof(await ownKey(), { method: \"POST\", url: tokenUrl, now });\n res = await fetchImpl(tokenUrl, { method: \"POST\", headers, body: form });\n } catch (e) {\n throw new TicketUnavailableError(`${issuer} unreachable: ${e instanceof Error ? e.message : String(e)}`);\n }\n let body: { access_token?: string; expires_in?: number; error?: string; error_description?: string } = {};\n try {\n body = (await res.json()) as typeof body;\n } catch {\n /* a non-JSON answer is handled by the status checks below */\n }\n if (res.status >= 500) throw new TicketUnavailableError(`${issuer} answered ${res.status}`);\n if (!res.ok || !body.access_token) {\n const desc = body.error_description ?? \"\";\n const code = desc.includes(\":\") ? desc.slice(0, desc.indexOf(\":\")).trim() : body.error ?? \"exchange_refused\";\n throw new TicketExchangeError(`BrobergID refused the ticket for ${audience}: ${desc || body.error || res.status}`, code, res.status);\n }\n const nowSec = Math.floor(now() / 1000);\n const exp = jwtExp(body.access_token) ?? nowSec + (body.expires_in ?? 300);\n return { token: body.access_token, exp };\n }\n\n const client: TicketClient = {\n async authHeaders({ audience, scope, method, url }) {\n const ticket = await client.get({ audience, scope });\n if (!options.dpop) return { authorization: `Bearer ${ticket}` };\n return { authorization: `DPoP ${ticket}`, dpop: await createDpopProof(await ownKey(), { method, url, ticket, now }) };\n },\n async get({ audience, scope }) {\n const key = `${audience} ${scope ?? \"\"}`;\n const hit = cache.get(key);\n if (hit && hit.exp - renewBeforeSec > now() / 1000) return hit.token;\n const pending = inFlight.get(key);\n if (pending) return pending;\n const p = exchange(audience, scope)\n .then((t) => {\n cache.set(key, t);\n return t.token;\n })\n .finally(() => inFlight.delete(key));\n inFlight.set(key, p);\n return p;\n },\n };\n return client;\n}\n\nlet shared: TicketClient | null = null;\n/** A ticket from the process-wide client (one cache per process). */\nexport function fetchTicket(opts: { audience: string; scope?: string }): Promise<string> {\n shared ??= createTicketClient();\n return shared.get(opts);\n}\n","/**\n * F084.153 — verify a BrobergID ticket LOCALLY (broberg-id-F087.4).\n *\n * A ticket is how one service or agent proves who it is to another without a\n * shared secret: BrobergID signs a short-lived JWT, the receiver checks it\n * against BID's PUBLIC keys. Nothing secret lives at the receiver.\n *\n * Format: broberg-id docs/features/F087.1-identitetsmodel.md §3 (draft, 8/10).\n * iss = the issuer · aud = the receiver's URL · scope = space-separated\n * sub = client_id = the caller · principal_type = human | service | agent\n * F084.159 — a USER ticket (BID F087.37): an app swapped its user's BID login\n * for a ticket to one receiver. sub = the USER, client_id/azp = the app,\n * principal_type = user. The app is mandatory there and never read from sub.\n * org · act {sub} only on delegation (RFC 8693) · exp/iat/jti\n *\n * This is deliberately NOT a method on createSsoClient: a service that only\n * RECEIVES tickets is not a login client — it has no client_id, no redirect,\n * no session. It needs the issuer, its own audience, and the key set.\n *\n * TWO FAILURES, TWO ANSWERS — keep them apart in the caller:\n * JwksUnavailableError → we could not ask BID right now. Answer 503 and let\n * the caller retry; the ticket may be perfectly valid.\n * SsoError → the ticket is not acceptable. Answer 401/403.\n * A known key is served from cache, so a ticket signed with it verifies while\n * BID is briefly unreachable.\n */\nimport { decodeProtectedHeader, jwtVerify, type JWTPayload } from \"jose\";\nimport { ALLOWED_ALGS, SsoError } from \"./client.js\";\nimport { createJwksCache, JwksUnavailableError, type JwksCache } from \"./jwks.js\";\nimport { createMemoryReplayStore, verifyDpopProof, type ReplayStore } from \"./dpop.js\";\n\nexport type PrincipalType = \"human\" | \"service\" | \"agent\" | \"user\";\nconst PRINCIPAL_TYPES: readonly PrincipalType[] = [\"human\", \"service\", \"agent\", \"user\"];\n\n/**\n * F084.156 — one link of an RFC 8693 delegation chain. `act` is the next link\n * outward: agent-b acting for agent-a acting for user-1 reads\n * `{ sub: \"agent-a\", act: { sub: \"user-1\" } }`. `act.sub` alone is the old shape.\n */\nexport interface TicketActor {\n sub: string;\n act?: TicketActor;\n}\n\n/** The newest ticket format version this package understands (BID sets `ver`). */\nexport const TICKET_FORMAT_VERSION = 1;\n/** Delegation deeper than this is refused rather than shortened. */\nexport const MAX_ACT_DEPTH = 5;\n\n/** What a verified ticket tells the receiver — a small, typed principal, never the raw payload. */\nexport interface TicketPrincipal {\n /** Who is calling: the ticket's `sub` — a client id such as `svc-trail`, or on a user ticket the USER's id. */\n principal: string;\n type: PrincipalType;\n /**\n * The client the ticket was issued to. Machine tickets: `client_id`, falling back to `sub`.\n * User tickets: `client_id`, falling back to `azp` — never `sub`, which is the user.\n */\n clientId: string;\n /** The organisation, when BID stated one. */\n org: string | null;\n /** On delegation: who the caller is acting for (RFC 8693 `act`), the WHOLE chain. */\n act: TicketActor | null;\n /** The ticket format version (`ver`); 0 for a ticket issued before BID set one. */\n version: number;\n /**\n * F084.156 — the DPoP key thumbprint when the ticket is sender-constrained.\n * Since 0.16.0 (F084.157) a ticket with cnf.jkt is only accepted together with\n * a valid DPoP proof for that key — see `verify(token, { dpop })`.\n */\n cnf: { jkt: string } | null;\n scopes: string[];\n /** Seconds since the epoch. */\n exp: number;\n jti: string;\n}\n\nexport interface TicketVerifierOptions {\n /** BID's issuer, exactly as it signs `iss` — e.g. `https://id.broberg.ai`. */\n issuer: string;\n /** THIS receiver's audience — its own URL, e.g. `https://discovery.broberg.ai`. */\n audience: string;\n /** The key set URL. Omitted: read once from the issuer's discovery document. */\n jwksUri?: string;\n /**\n * The longest lifetime (exp − iat) a ticket may claim. BID issues 5 min\n * (service) and 15 min (agent); anything longer was not minted by the policy\n * we were told about, so it is refused rather than trusted for longer.\n */\n maxLifetimeSec?: number;\n /** Seconds of clock skew to allow on exp/iat. Default 30. */\n clockToleranceSec?: number;\n /** Fetch the key set at construction, so the first caller does not wait. */\n warmUp?: boolean;\n fetchImpl?: typeof fetch;\n minRefetchIntervalMs?: number;\n /**\n * F084.157 — refuse UNBOUND tickets (bearer). Off by default during the\n * rollout. A BOUND ticket (cnf.jkt) needs a valid proof either way.\n */\n requireDpop?: boolean;\n /** Where used proof ids are remembered. Default in-memory — ONE machine only; share one across machines. */\n replayStore?: ReplayStore;\n /** How far a proof's iat may be from now. Default 60 s. */\n dpopIatWindowSec?: number;\n /** Injectable clock for the DPoP checks (ms). */\n now?: () => number;\n}\n\n/** The DPoP half of a request: the `DPoP` header, and the method + PUBLIC URL the receiver was called on. */\nexport interface DpopRequest {\n proof: string | null | undefined;\n method: string;\n url: string;\n}\n\nexport interface TicketVerifier {\n /**\n * Verify a ticket; with `scope`, also require that scope to be granted. Pass\n * `dpop` with the request's DPoP header, method and public URL — a bound ticket\n * is refused without it.\n */\n verify(token: string, options?: { scope?: string | string[]; dpop?: DpopRequest }): Promise<TicketPrincipal>;\n}\n\nexport function createTicketVerifier(options: TicketVerifierOptions): TicketVerifier {\n const {\n issuer,\n audience,\n maxLifetimeSec = 15 * 60,\n clockToleranceSec = 30,\n fetchImpl = fetch,\n requireDpop = false,\n dpopIatWindowSec = 60,\n now = () => Date.now(),\n } = options;\n const replayStore = options.replayStore ?? createMemoryReplayStore(now);\n if (!issuer) throw new SsoError(\"createTicketVerifier needs an issuer\");\n if (!audience) throw new SsoError(\"createTicketVerifier needs this receiver's audience\");\n\n let cachePromise: Promise<JwksCache> | null = null;\n const cacheFor = (jwksUri: string) =>\n createJwksCache({\n jwksUri,\n fetchImpl,\n ...(options.warmUp ? { warmUp: true } : {}),\n ...(options.minRefetchIntervalMs !== undefined ? { minRefetchIntervalMs: options.minRefetchIntervalMs } : {}),\n });\n\n async function keys(): Promise<JwksCache> {\n cachePromise ??= (async () => {\n if (options.jwksUri) return cacheFor(options.jwksUri);\n const url = `${issuer}/.well-known/openid-configuration`;\n let doc: { issuer?: string; jwks_uri?: string };\n try {\n const res = await fetchImpl(url);\n if (!res.ok) throw new Error(`answered ${res.status}`);\n doc = (await res.json()) as typeof doc;\n } catch (cause) {\n // Reached nothing usable: transient, the same class a key-set outage gets.\n throw new JwksUnavailableError(`${url}: ${cause instanceof Error ? cause.message : String(cause)}`);\n }\n if (doc.issuer !== issuer) {\n throw new SsoError(`issuer is ${issuer} but ${url} says ${doc.issuer} — they must match exactly`);\n }\n if (!doc.jwks_uri) throw new SsoError(`${url} names no jwks_uri`);\n return cacheFor(doc.jwks_uri);\n })().catch((err) => {\n cachePromise = null; // a later call retries instead of caching the failure\n throw err;\n });\n return cachePromise;\n }\n if (options.warmUp) void keys().catch(() => {});\n\n return {\n async verify(token, opts = {}) {\n let header;\n try {\n header = decodeProtectedHeader(token);\n } catch {\n throw new SsoError(\"ticket is not a JWS\");\n }\n if (!header.kid) throw new SsoError(\"ticket has no kid — cannot pick a signing key\");\n if (header.typ === \"logout+jwt\") throw new SsoError(\"a logout token is not a ticket\");\n\n const cache = await keys();\n let payload: JWTPayload;\n try {\n ({ payload } = await jwtVerify(token, async () => cache.getKey(header.kid!, header.alg ?? \"EdDSA\"), {\n issuer,\n audience,\n algorithms: ALLOWED_ALGS,\n clockTolerance: clockToleranceSec,\n requiredClaims: [\"exp\", \"iat\", \"jti\", \"sub\"],\n }));\n } catch (e) {\n // A key-set outage must surface as itself (→ 503), never as \"rejected\".\n if (e instanceof JwksUnavailableError) throw e;\n throw new SsoError(`ticket rejected: ${e instanceof Error ? e.message : String(e)}`);\n }\n\n // An ID token or a logout token must never pass as a ticket. They carry\n // no principal_type; a logout token carries events, an ID token a nonce.\n if (\"events\" in payload) throw new SsoError(\"a logout token is not a ticket\");\n if (\"nonce\" in payload) throw new SsoError(\"an ID token is not a ticket\");\n\n const type = payload.principal_type;\n if (typeof type !== \"string\" || !PRINCIPAL_TYPES.includes(type as PrincipalType)) {\n throw new SsoError(`ticket has no valid principal_type (got ${JSON.stringify(type)})`);\n }\n const lifetime = payload.exp! - payload.iat!;\n if (lifetime > maxLifetimeSec) {\n throw new SsoError(`ticket claims a ${lifetime}s lifetime; at most ${maxLifetimeSec}s is accepted`);\n }\n if (typeof payload.sub !== \"string\" || payload.sub === \"\") throw new SsoError(\"ticket has no sub\");\n\n const scopes = typeof payload.scope === \"string\" ? payload.scope.split(\" \").filter(Boolean) : [];\n const required = opts.scope === undefined ? [] : Array.isArray(opts.scope) ? opts.scope : [opts.scope];\n const missing = required.filter((s) => !scopes.includes(s));\n if (missing.length) throw new SsoError(`ticket lacks scope ${missing.join(\", \")}`);\n\n // F084.156 — ver: unknown future formats are refused by name, never read\n // with today's rules.\n const ver = payload.ver === undefined ? 0 : payload.ver;\n if (typeof ver !== \"number\" || !Number.isInteger(ver) || ver < 0) {\n throw new SsoError(`ticket has an invalid ver (got ${JSON.stringify(payload.ver)})`);\n }\n if (ver > TICKET_FORMAT_VERSION) {\n throw new SsoError(`ticket format version ${ver} is newer than this @broberg/sso understands (${TICKET_FORMAT_VERSION}) — upgrade @broberg/sso`);\n }\n // The whole chain, or a refusal. 0.14.2 kept only act.sub, cutting a chain\n // to its first link, and read a malformed act as \"no delegation\" — both in\n // the direction where the caller looks like it acts for fewer people.\n const act = payload.act === undefined ? null : readActor(payload.act, 1);\n const cnfRaw = payload.cnf as { jkt?: unknown } | undefined;\n const cnf = cnfRaw && typeof cnfRaw.jkt === \"string\" && cnfRaw.jkt ? { jkt: cnfRaw.jkt } : null;\n // F084.157 — a bound ticket needs its proof, always; requireDpop only\n // decides about unbound ones (and then a cnf it cannot read is refused too).\n if (cnf) {\n if (!opts.dpop?.proof) throw new SsoError(\"ticket is DPoP-bound (cnf.jkt) but no DPoP proof was presented\");\n await verifyDpopProof(opts.dpop.proof, {\n method: opts.dpop.method,\n url: opts.dpop.url,\n ticket: token,\n jkt: cnf.jkt,\n replay: replayStore,\n iatWindowSec: dpopIatWindowSec,\n now,\n });\n } else if (requireDpop) {\n throw new SsoError(cnfRaw !== undefined ? \"ticket has a cnf without a string jkt — DPoP is required here\" : \"this receiver requires DPoP; the ticket is not bound (no cnf.jkt)\");\n }\n // F084.159 — on a user ticket sub is the USER. Falling back to it would turn a\n // user id into an app id, so a receiver that requires clientId === \"trail-clipper\"\n // could be satisfied by a user who happens to be called that.\n const named = (v: unknown) => (typeof v === \"string\" && v ? v : null);\n const clientId =\n type === \"user\"\n ? named(payload.client_id) ?? named(payload.azp)\n : named(payload.client_id) ?? payload.sub;\n if (clientId === null) throw new SsoError(\"a user ticket names no app (no client_id or azp)\");\n return {\n principal: payload.sub,\n type: type as PrincipalType,\n clientId,\n org: typeof payload.org === \"string\" && payload.org ? payload.org : null,\n act,\n version: ver,\n cnf,\n scopes,\n exp: payload.exp!,\n jti: String(payload.jti),\n };\n },\n };\n}\n\nfunction readActor(raw: unknown, depth: number): TicketActor {\n if (depth > MAX_ACT_DEPTH) throw new SsoError(`ticket's delegation chain is deeper than ${MAX_ACT_DEPTH}`);\n const link = raw as { sub?: unknown; act?: unknown } | null;\n if (!link || typeof link !== \"object\" || typeof link.sub !== \"string\" || link.sub === \"\") {\n throw new SsoError(`ticket's act (link ${depth}) has no string sub`);\n }\n return link.act === undefined ? { sub: link.sub } : { sub: link.sub, act: readActor(link.act, depth + 1) };\n}\n"]}
1
+ {"version":3,"sources":["../src/dpop.ts","../src/fetch-ticket.ts","../src/ticket.ts"],"names":["decodeProtectedHeader","jwtVerify"],"mappings":";;;;;;AAuCA,eAAsB,aAAA,GAAkC;AACtD,EAAA,MAAM,EAAE,UAAA,EAAY,SAAA,EAAU,GAAI,MAAM,gBAAgB,OAAA,EAAS,EAAE,WAAA,EAAa,KAAA,EAAO,CAAA;AACvF,EAAA,MAAM,GAAA,GAAM,MAAM,SAAA,CAAU,SAAS,CAAA;AACrC,EAAA,MAAM,SAAA,GAAiB,EAAE,GAAA,EAAK,GAAA,CAAI,GAAA,EAAK,GAAA,EAAK,GAAA,CAAI,GAAA,EAAK,CAAA,EAAG,GAAA,CAAI,CAAA,EAAG,CAAA,EAAG,IAAI,CAAA,EAAE;AACxE,EAAA,OAAO,EAAE,UAAA,EAAY,SAAA,EAAW,KAAK,MAAM,sBAAA,CAAuB,SAAS,CAAA,EAAE;AAC/E;AAEA,IAAM,GAAA,GAAM,IAAI,WAAA,EA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A,IAAI,CAAC,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAA,IAAY,OAAO,IAAA,CAAK,GAAA,KAAQ,QAAA,IAAY,IAAA,CAAK,GAAA,KAAQ,EAAA,EAAI;AACxF,IAAA,MAAM,IAAI,QAAA,CAAS,CAAA,mBAAA,EAAsB,KAAK,CAAA,mBAAA,CAAqB,CAAA;AAAA,EACrE;AACA,EAAA,OAAO,KAAK,GAAA,KAAQ,MAAA,GAAY,EAAE,GAAA,EAAK,IAAA,CAAK,KAAI,GAAI,EAAE,GAAA,EAAK,IAAA,CAAK,KAAK,GAAA,EAAK,SAAA,CAAU,KAAK,GAAA,EAAK,KAAA,GAAQ,CAAC,CAAA,EAAE;AAC3G","file":"index.js","sourcesContent":["/**\n * F084.157 — DPoP (RFC 9449): a bound ticket works only for whoever holds the key\n * (broberg-id-F087.16, joint design #2572/#2574).\n *\n * A DPoP-bound ticket carries `cnf.jkt`, the thumbprint of the caller's public\n * key. With every request the caller signs a short PROOF (method, URL, time, a\n * hash of the ticket) with the matching private key. A ticket copied out of a log\n * is useless on another machine: it has the ticket, not the key.\n *\n * THE RULE THAT MAKES IT PROTECTION (agreed with broberg-id, (A) in #2574): once a\n * receiver verifies with this version, a ticket WITH cnf.jkt needs a valid proof —\n * also while DPoP is otherwise optional. `requireDpop` only decides whether\n * UNBOUND tickets are still accepted. Were bound tickets accepted without a proof\n * during the rollout, a stolen bound ticket would work as bearer the whole time.\n *\n * Not here yet: server nonces (RFC 9449 §8). The jti replay store covers replay\n * inside the iat window.\n */\nimport {\n SignJWT,\n calculateJwkThumbprint,\n decodeProtectedHeader,\n exportJWK,\n generateKeyPair,\n importJWK,\n jwtVerify,\n type JWK,\n} from \"jose\";\nimport { SsoError } from \"./client.js\";\n\n/** One process's DPoP key. The private half cannot be exported. */\nexport interface DpopKey {\n privateKey: CryptoKey;\n publicJwk: JWK;\n /** RFC 7638 thumbprint — what BID puts in the ticket's cnf.jkt. */\n jkt: string;\n}\n\n/** A fresh ES256 key pair, private key non-extractable, never written anywhere. */\nexport async function createDpopKey(): Promise<DpopKey> {\n const { privateKey, publicKey } = await generateKeyPair(\"ES256\", { extractable: false });\n const jwk = await exportJWK(publicKey); // a public key is always exportable\n const publicJwk: JWK = { kty: jwk.kty, crv: jwk.crv, x: jwk.x, y: jwk.y };\n return { privateKey, publicJwk, jkt: await calculateJwkThumbprint(publicJwk) };\n}\n\nconst enc = new TextEncoder();\nconst b64url = (bytes: ArrayBuffer) =>\n btoa(String.fromCharCode(...new Uint8Array(bytes))).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n\n/** `ath`: base64url(SHA-256(ticket)) — ties a proof to one ticket. */\nexport async function accessTokenHash(ticket: string): Promise<string> {\n return b64url(await crypto.subtle.digest(\"SHA-256\", enc.encode(ticket)));\n}\n\n/** RFC 9449 §4.3: htu is compared without query and fragment. */\nexport function normalizeHtu(url: string): string {\n const u = new URL(url);\n return `${u.protocol}//${u.host}${u.pathname}`;\n}\n\n/** Sign one proof. Pass `ticket` when calling a resource server (adds ath); omit it for BID's token endpoint. */\nexport async function createDpopProof(\n key: DpopKey,\n opts: { method: string; url: string; ticket?: string; now?: () => number },\n): Promise<string> {\n const payload: Record<string, unknown> = {\n jti: crypto.randomUUID(),\n htm: opts.method.toUpperCase(),\n htu: normalizeHtu(opts.url),\n iat: Math.floor((opts.now?.() ?? Date.now()) / 1000),\n };\n if (opts.ticket !== undefined) payload.ath = await accessTokenHash(opts.ticket);\n return new SignJWT(payload).setProtectedHeader({ typ: \"dpop+jwt\", alg: \"ES256\", jwk: key.publicJwk }).sign(key.privateKey);\n}\n\n/**\n * Remembers which proofs were already used. The default is in-memory, which\n * holds on ONE machine: a receiver running on two machines must pass a shared\n * store, or a proof replayed against the other machine inside the window passes.\n */\nexport interface ReplayStore {\n /** Record `key`; resolve true if it was already recorded within `ttlMs`. */\n seen(key: string, ttlMs: number): Promise<boolean>;\n}\n\nexport function createMemoryReplayStore(now: () => number = () => Date.now()): ReplayStore {\n const entries = new Map<string, number>();\n return {\n async seen(key, ttlMs) {\n const t = now();\n for (const [k, until] of entries) if (until <= t) entries.delete(k);\n if (entries.has(key)) return true;\n entries.set(key, t + ttlMs);\n return false;\n },\n };\n}\n\nexport interface VerifyProofOptions {\n method: string;\n /** The receiver's PUBLIC URL for this request (behind a proxy the process sees an internal one). */\n url: string;\n ticket: string;\n jkt: string;\n replay: ReplayStore;\n iatWindowSec: number;\n now: () => number;\n}\n\nconst ASYMMETRIC = new Set([\"ES256\", \"ES384\", \"ES512\", \"EdDSA\", \"PS256\", \"PS384\", \"PS512\", \"RS256\", \"RS384\", \"RS512\"]);\n\n/** Throws SsoError naming the first thing that is wrong. */\nexport async function verifyDpopProof(proof: string, o: VerifyProofOptions): Promise<void> {\n let header;\n try {\n header = decodeProtectedHeader(proof);\n } catch {\n throw new SsoError(\"DPoP proof is not a JWS\");\n }\n if (header.typ !== \"dpop+jwt\") throw new SsoError(`DPoP proof has typ ${JSON.stringify(header.typ)}, not \"dpop+jwt\"`);\n if (!header.alg || !ASYMMETRIC.has(header.alg)) throw new SsoError(`DPoP proof alg ${JSON.stringify(header.alg)} is not an accepted asymmetric algorithm`);\n const jwk = header.jwk as JWK | undefined;\n if (!jwk || typeof jwk !== \"object\") throw new SsoError(\"DPoP proof carries no jwk\");\n if (\"d\" in jwk) throw new SsoError(\"DPoP proof jwk contains a private key\");\n\n let payload;\n try {\n const key = await importJWK(jwk, header.alg);\n ({ payload } = await jwtVerify(proof, key, { typ: \"dpop+jwt\", algorithms: [header.alg] }));\n } catch (e) {\n throw new SsoError(`DPoP proof signature rejected: ${e instanceof Error ? e.message : String(e)}`);\n }\n\n if ((await calculateJwkThumbprint(jwk)) !== o.jkt) throw new SsoError(\"DPoP proof key does not match the ticket's cnf.jkt\");\n if (payload.htm !== o.method.toUpperCase()) throw new SsoError(`DPoP proof is for ${JSON.stringify(payload.htm)}, the request is ${o.method.toUpperCase()}`);\n let htu: string;\n try {\n htu = normalizeHtu(String(payload.htu));\n } catch {\n throw new SsoError(\"DPoP proof htu is not a URL\");\n }\n if (htu !== normalizeHtu(o.url)) throw new SsoError(`DPoP proof is for ${htu}, the request is ${normalizeHtu(o.url)}`);\n const nowSec = Math.floor(o.now() / 1000);\n if (typeof payload.iat !== \"number\" || Math.abs(nowSec - payload.iat) > o.iatWindowSec) {\n throw new SsoError(`DPoP proof iat is outside ±${o.iatWindowSec}s`);\n }\n if (payload.ath !== (await accessTokenHash(o.ticket))) throw new SsoError(\"DPoP proof ath does not match this ticket\");\n if (typeof payload.jti !== \"string\" || payload.jti === \"\") throw new SsoError(\"DPoP proof has no jti\");\n if (await o.replay.seen(`${o.jkt}:${payload.jti}`, o.iatWindowSec * 2 * 1000)) {\n throw new SsoError(\"DPoP proof was already used (jti replay)\");\n }\n}\n","/**\n * F084.154 — fetch a BrobergID ticket WITHOUT a key (broberg-id-F087.10/.11).\n *\n * The sending half of F084.153: a workload proves who it is with the identity its\n * platform already gives it, and BID exchanges that for a short-lived ticket\n * (RFC 8693 token exchange). No secret is stored anywhere.\n *\n * Fly.io POST unix:/.fly/api /v1/tokens/oidc {aud: issuer}\n * GitHub Actions GET $ACTIONS_ID_TOKEN_REQUEST_URL&audience=issuer\n * (needs `permissions: id-token: write` in the workflow)\n * then POST {issuer}/oauth2/token grant_type=…token-exchange\n *\n * Reference implementation: broberg-id/.github/workflows/ticket-probe.yml.\n * The ticket itself is never logged or put in an error message.\n */\nimport { existsSync } from \"node:fs\";\nimport { request } from \"node:http\";\nimport { createDpopKey, createDpopProof, type DpopKey } from \"./dpop.js\";\n\nexport const DEFAULT_ISSUER = \"https://id.broberg.ai\";\nconst FLY_SOCKET = \"/.fly/api\";\n\n/** No platform identity to exchange: not on Fly, not in a GitHub Actions job with id-token: write. */\nexport class NoWorkloadIdentityError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"NoWorkloadIdentityError\";\n }\n}\n\n/**\n * BID refused the exchange. `code` is BID's own error name (the part of\n * error_description before the colon, e.g. `no_rule_for_audience`), `status` the\n * HTTP status. A 4xx is PERMANENT for this request — fix the rule, do not retry.\n */\nexport class TicketExchangeError extends Error {\n constructor(message: string, readonly code: string, readonly status: number) {\n super(message);\n this.name = \"TicketExchangeError\";\n }\n}\n\n/** BID or the platform could not be reached, or answered 5xx. TRANSIENT — retry later. */\nexport class TicketUnavailableError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"TicketUnavailableError\";\n }\n}\n\nexport interface TicketClientOptions {\n issuer?: string;\n /** Renew this many seconds before exp. Default 30. */\n renewBeforeSec?: number;\n /** Injectable for tests. */\n env?: Record<string, string | undefined>;\n fetchImpl?: typeof fetch;\n now?: () => number;\n /** Ask Fly's machine API for an OIDC token. Default: POST over the /.fly/api unix socket. */\n flyOidc?: (aud: string) => Promise<string>;\n /** Whether the Fly socket is present. Default: checks /.fly/api. */\n onFly?: () => boolean;\n /**\n * F084.157 — ask BID for DPoP-BOUND tickets. One ES256 key per client\n * (non-extractable, never stored); every call then needs a proof, which\n * `authHeaders` makes. Default false: bearer tickets, exactly as before.\n */\n dpop?: boolean;\n}\n\n/** Headers for one call to a receiver. With `dpop`, `authorization` is `DPoP <ticket>` and `dpop` is the proof. */\nexport interface TicketAuthHeaders {\n authorization: string;\n dpop?: string;\n}\n\nexport interface TicketClient {\n /** A ticket for `audience` (BID's short name, e.g. \"discovery\"), from cache while it is fresh. */\n get(opts: { audience: string; scope?: string }): Promise<string>;\n /**\n * F084.157 — the headers for ONE request to a receiver: a ticket plus, with\n * `dpop`, a fresh proof bound to this method and URL (use it once). Without\n * `dpop`: `{ authorization: \"Bearer <ticket>\" }`.\n */\n authHeaders(opts: { audience: string; scope?: string; method: string; url: string }): Promise<TicketAuthHeaders>;\n}\n\nfunction flyOidcOverSocket(aud: string): Promise<string> {\n return new Promise((resolve, reject) => {\n const body = JSON.stringify({ aud });\n const req = request(\n { socketPath: FLY_SOCKET, path: \"/v1/tokens/oidc\", method: \"POST\", headers: { \"content-type\": \"application/json\", \"content-length\": Buffer.byteLength(body) } },\n (res) => {\n let data = \"\";\n res.setEncoding(\"utf8\");\n res.on(\"data\", (c) => (data += c));\n res.on(\"end\", () => {\n if ((res.statusCode ?? 0) >= 200 && (res.statusCode ?? 0) < 300) resolve(data.trim());\n else reject(new TicketUnavailableError(`Fly OIDC answered ${res.statusCode}`));\n });\n },\n );\n req.on(\"error\", (e) => reject(new TicketUnavailableError(`Fly OIDC socket: ${e.message}`)));\n req.end(body);\n });\n}\n\n/** Seconds since the epoch at which a JWT expires, or null if it cannot be read. */\nfunction jwtExp(token: string): number | null {\n try {\n const payload = JSON.parse(Buffer.from(token.split(\".\")[1] ?? \"\", \"base64url\").toString(\"utf8\"));\n return typeof payload.exp === \"number\" ? payload.exp : null;\n } catch {\n return null;\n }\n}\n\nexport function createTicketClient(options: TicketClientOptions = {}): TicketClient {\n const issuer = (options.issuer ?? DEFAULT_ISSUER).replace(/\\/+$/, \"\");\n const renewBeforeSec = options.renewBeforeSec ?? 30;\n const env = options.env ?? process.env;\n const fetchImpl = options.fetchImpl ?? fetch;\n const now = options.now ?? (() => Date.now());\n const flyOidc = options.flyOidc ?? flyOidcOverSocket;\n const onFly = options.onFly ?? (() => !!env.FLY_APP_NAME && existsSync(FLY_SOCKET));\n\n const cache = new Map<string, { token: string; exp: number }>();\n const inFlight = new Map<string, Promise<string>>();\n let dpopKey: Promise<DpopKey> | null = null;\n const ownKey = () => (dpopKey ??= createDpopKey());\n\n async function platformToken(): Promise<string> {\n if (onFly()) return flyOidc(issuer);\n const url = env.ACTIONS_ID_TOKEN_REQUEST_URL;\n const bearer = env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;\n if (url && bearer) {\n let res: Response;\n try {\n res = await fetchImpl(`${url}&audience=${encodeURIComponent(issuer)}`, { headers: { authorization: `Bearer ${bearer}` } });\n } catch (e) {\n throw new TicketUnavailableError(`GitHub OIDC endpoint unreachable: ${e instanceof Error ? e.message : String(e)}`);\n }\n if (!res.ok) throw new TicketUnavailableError(`GitHub OIDC endpoint answered ${res.status}`);\n const { value } = (await res.json()) as { value?: string };\n if (!value) throw new TicketUnavailableError(\"GitHub OIDC endpoint returned no token\");\n return value;\n }\n throw new NoWorkloadIdentityError(\n \"No workload identity to exchange for a ticket: not on a Fly machine (FLY_APP_NAME + /.fly/api) and not in a GitHub Actions job \" +\n \"(ACTIONS_ID_TOKEN_REQUEST_URL/_TOKEN — add `permissions: id-token: write`). A Mac session keeps using its session key.\",\n );\n }\n\n async function exchange(audience: string, scope: string | undefined): Promise<{ token: string; exp: number }> {\n const subject = await platformToken();\n const form = new URLSearchParams({\n grant_type: \"urn:ietf:params:oauth:grant-type:token-exchange\",\n subject_token: subject,\n subject_token_type: \"urn:ietf:params:oauth:token-type:jwt\",\n audience,\n });\n if (scope) form.set(\"scope\", scope);\n let res: Response;\n try {\n const tokenUrl = `${issuer}/oauth2/token`;\n const headers: Record<string, string> = { \"content-type\": \"application/x-www-form-urlencoded\" };\n if (options.dpop) headers.dpop = await createDpopProof(await ownKey(), { method: \"POST\", url: tokenUrl, now });\n res = await fetchImpl(tokenUrl, { method: \"POST\", headers, body: form });\n } catch (e) {\n throw new TicketUnavailableError(`${issuer} unreachable: ${e instanceof Error ? e.message : String(e)}`);\n }\n let body: { access_token?: string; expires_in?: number; error?: string; error_description?: string } = {};\n try {\n body = (await res.json()) as typeof body;\n } catch {\n /* a non-JSON answer is handled by the status checks below */\n }\n if (res.status >= 500) throw new TicketUnavailableError(`${issuer} answered ${res.status}`);\n if (!res.ok || !body.access_token) {\n const desc = body.error_description ?? \"\";\n const code = desc.includes(\":\") ? desc.slice(0, desc.indexOf(\":\")).trim() : body.error ?? \"exchange_refused\";\n throw new TicketExchangeError(`BID refused the ticket for ${audience}: ${desc || body.error || res.status}`, code, res.status);\n }\n const nowSec = Math.floor(now() / 1000);\n const exp = jwtExp(body.access_token) ?? nowSec + (body.expires_in ?? 300);\n return { token: body.access_token, exp };\n }\n\n const client: TicketClient = {\n async authHeaders({ audience, scope, method, url }) {\n const ticket = await client.get({ audience, scope });\n if (!options.dpop) return { authorization: `Bearer ${ticket}` };\n return { authorization: `DPoP ${ticket}`, dpop: await createDpopProof(await ownKey(), { method, url, ticket, now }) };\n },\n async get({ audience, scope }) {\n const key = `${audience} ${scope ?? \"\"}`;\n const hit = cache.get(key);\n if (hit && hit.exp - renewBeforeSec > now() / 1000) return hit.token;\n const pending = inFlight.get(key);\n if (pending) return pending;\n const p = exchange(audience, scope)\n .then((t) => {\n cache.set(key, t);\n return t.token;\n })\n .finally(() => inFlight.delete(key));\n inFlight.set(key, p);\n return p;\n },\n };\n return client;\n}\n\nlet shared: TicketClient | null = null;\n/** A ticket from the process-wide client (one cache per process). */\nexport function fetchTicket(opts: { audience: string; scope?: string }): Promise<string> {\n shared ??= createTicketClient();\n return shared.get(opts);\n}\n","/**\n * F084.153 — verify a BrobergID ticket LOCALLY (broberg-id-F087.4).\n *\n * A ticket is how one service or agent proves who it is to another without a\n * shared secret: BrobergID signs a short-lived JWT, the receiver checks it\n * against BID's PUBLIC keys. Nothing secret lives at the receiver.\n *\n * Format: broberg-id docs/features/F087.1-identitetsmodel.md §3 (draft, 8/10).\n * iss = the issuer · aud = the receiver's URL · scope = space-separated\n * sub = client_id = the caller · principal_type = human | service | agent\n * F084.159 — a USER ticket (BID F087.37): an app swapped its user's BID login\n * for a ticket to one receiver. sub = the USER, client_id/azp = the app,\n * principal_type = user. The app is mandatory there and never read from sub.\n * org · act {sub} only on delegation (RFC 8693) · exp/iat/jti\n *\n * This is deliberately NOT a method on createSsoClient: a service that only\n * RECEIVES tickets is not a login client — it has no client_id, no redirect,\n * no session. It needs the issuer, its own audience, and the key set.\n *\n * TWO FAILURES, TWO ANSWERS — keep them apart in the caller:\n * JwksUnavailableError → we could not ask BID right now. Answer 503 and let\n * the caller retry; the ticket may be perfectly valid.\n * SsoError → the ticket is not acceptable. Answer 401/403.\n * A known key is served from cache, so a ticket signed with it verifies while\n * BID is briefly unreachable.\n */\nimport { decodeProtectedHeader, jwtVerify, type JWTPayload } from \"jose\";\nimport { ALLOWED_ALGS, SsoError } from \"./client.js\";\nimport { createJwksCache, JwksUnavailableError, type JwksCache } from \"./jwks.js\";\nimport { createMemoryReplayStore, verifyDpopProof, type ReplayStore } from \"./dpop.js\";\n\nexport type PrincipalType = \"human\" | \"service\" | \"agent\" | \"user\";\nconst PRINCIPAL_TYPES: readonly PrincipalType[] = [\"human\", \"service\", \"agent\", \"user\"];\n\n/**\n * F084.156 — one link of an RFC 8693 delegation chain. `act` is the next link\n * outward: agent-b acting for agent-a acting for user-1 reads\n * `{ sub: \"agent-a\", act: { sub: \"user-1\" } }`. `act.sub` alone is the old shape.\n */\nexport interface TicketActor {\n sub: string;\n act?: TicketActor;\n}\n\n/** The newest ticket format version this package understands (BID sets `ver`). */\nexport const TICKET_FORMAT_VERSION = 1;\n/** Delegation deeper than this is refused rather than shortened. */\nexport const MAX_ACT_DEPTH = 5;\n\n/** What a verified ticket tells the receiver — a small, typed principal, never the raw payload. */\nexport interface TicketPrincipal {\n /** Who is calling: the ticket's `sub` — a client id such as `svc-trail`, or on a user ticket the USER's id. */\n principal: string;\n type: PrincipalType;\n /**\n * The client the ticket was issued to. Machine tickets: `client_id`, falling back to `sub`.\n * User tickets: `client_id`, falling back to `azp` — never `sub`, which is the user.\n */\n clientId: string;\n /** The organisation, when BID stated one. */\n org: string | null;\n /** On delegation: who the caller is acting for (RFC 8693 `act`), the WHOLE chain. */\n act: TicketActor | null;\n /** The ticket format version (`ver`); 0 for a ticket issued before BID set one. */\n version: number;\n /**\n * F084.156 — the DPoP key thumbprint when the ticket is sender-constrained.\n * Since 0.16.0 (F084.157) a ticket with cnf.jkt is only accepted together with\n * a valid DPoP proof for that key — see `verify(token, { dpop })`.\n */\n cnf: { jkt: string } | null;\n scopes: string[];\n /** Seconds since the epoch. */\n exp: number;\n jti: string;\n}\n\nexport interface TicketVerifierOptions {\n /** BID's issuer, exactly as it signs `iss` — e.g. `https://id.broberg.ai`. */\n issuer: string;\n /** THIS receiver's audience — its own URL, e.g. `https://discovery.broberg.ai`. */\n audience: string;\n /** The key set URL. Omitted: read once from the issuer's discovery document. */\n jwksUri?: string;\n /**\n * The longest lifetime (exp − iat) a ticket may claim. BID issues 5 min\n * (service) and 15 min (agent); anything longer was not minted by the policy\n * we were told about, so it is refused rather than trusted for longer.\n */\n maxLifetimeSec?: number;\n /** Seconds of clock skew to allow on exp/iat. Default 30. */\n clockToleranceSec?: number;\n /** Fetch the key set at construction, so the first caller does not wait. */\n warmUp?: boolean;\n fetchImpl?: typeof fetch;\n minRefetchIntervalMs?: number;\n /**\n * F084.157 — refuse UNBOUND tickets (bearer). Off by default during the\n * rollout. A BOUND ticket (cnf.jkt) needs a valid proof either way.\n */\n requireDpop?: boolean;\n /** Where used proof ids are remembered. Default in-memory — ONE machine only; share one across machines. */\n replayStore?: ReplayStore;\n /** How far a proof's iat may be from now. Default 60 s. */\n dpopIatWindowSec?: number;\n /** Injectable clock for the DPoP checks (ms). */\n now?: () => number;\n}\n\n/** The DPoP half of a request: the `DPoP` header, and the method + PUBLIC URL the receiver was called on. */\nexport interface DpopRequest {\n proof: string | null | undefined;\n method: string;\n url: string;\n}\n\nexport interface TicketVerifier {\n /**\n * Verify a ticket; with `scope`, also require that scope to be granted. Pass\n * `dpop` with the request's DPoP header, method and public URL — a bound ticket\n * is refused without it.\n */\n verify(token: string, options?: { scope?: string | string[]; dpop?: DpopRequest }): Promise<TicketPrincipal>;\n}\n\nexport function createTicketVerifier(options: TicketVerifierOptions): TicketVerifier {\n const {\n issuer,\n audience,\n maxLifetimeSec = 15 * 60,\n clockToleranceSec = 30,\n fetchImpl = fetch,\n requireDpop = false,\n dpopIatWindowSec = 60,\n now = () => Date.now(),\n } = options;\n const replayStore = options.replayStore ?? createMemoryReplayStore(now);\n if (!issuer) throw new SsoError(\"createTicketVerifier needs an issuer\");\n if (!audience) throw new SsoError(\"createTicketVerifier needs this receiver's audience\");\n\n let cachePromise: Promise<JwksCache> | null = null;\n const cacheFor = (jwksUri: string) =>\n createJwksCache({\n jwksUri,\n fetchImpl,\n ...(options.warmUp ? { warmUp: true } : {}),\n ...(options.minRefetchIntervalMs !== undefined ? { minRefetchIntervalMs: options.minRefetchIntervalMs } : {}),\n });\n\n async function keys(): Promise<JwksCache> {\n cachePromise ??= (async () => {\n if (options.jwksUri) return cacheFor(options.jwksUri);\n const url = `${issuer}/.well-known/openid-configuration`;\n let doc: { issuer?: string; jwks_uri?: string };\n try {\n const res = await fetchImpl(url);\n if (!res.ok) throw new Error(`answered ${res.status}`);\n doc = (await res.json()) as typeof doc;\n } catch (cause) {\n // Reached nothing usable: transient, the same class a key-set outage gets.\n throw new JwksUnavailableError(`${url}: ${cause instanceof Error ? cause.message : String(cause)}`);\n }\n if (doc.issuer !== issuer) {\n throw new SsoError(`issuer is ${issuer} but ${url} says ${doc.issuer} — they must match exactly`);\n }\n if (!doc.jwks_uri) throw new SsoError(`${url} names no jwks_uri`);\n return cacheFor(doc.jwks_uri);\n })().catch((err) => {\n cachePromise = null; // a later call retries instead of caching the failure\n throw err;\n });\n return cachePromise;\n }\n if (options.warmUp) void keys().catch(() => {});\n\n return {\n async verify(token, opts = {}) {\n let header;\n try {\n header = decodeProtectedHeader(token);\n } catch {\n throw new SsoError(\"ticket is not a JWS\");\n }\n if (!header.kid) throw new SsoError(\"ticket has no kid — cannot pick a signing key\");\n if (header.typ === \"logout+jwt\") throw new SsoError(\"a logout token is not a ticket\");\n\n const cache = await keys();\n let payload: JWTPayload;\n try {\n ({ payload } = await jwtVerify(token, async () => cache.getKey(header.kid!, header.alg ?? \"EdDSA\"), {\n issuer,\n audience,\n algorithms: ALLOWED_ALGS,\n clockTolerance: clockToleranceSec,\n requiredClaims: [\"exp\", \"iat\", \"jti\", \"sub\"],\n }));\n } catch (e) {\n // A key-set outage must surface as itself (→ 503), never as \"rejected\".\n if (e instanceof JwksUnavailableError) throw e;\n throw new SsoError(`ticket rejected: ${e instanceof Error ? e.message : String(e)}`);\n }\n\n // An ID token or a logout token must never pass as a ticket. They carry\n // no principal_type; a logout token carries events, an ID token a nonce.\n if (\"events\" in payload) throw new SsoError(\"a logout token is not a ticket\");\n if (\"nonce\" in payload) throw new SsoError(\"an ID token is not a ticket\");\n\n const type = payload.principal_type;\n if (typeof type !== \"string\" || !PRINCIPAL_TYPES.includes(type as PrincipalType)) {\n throw new SsoError(`ticket has no valid principal_type (got ${JSON.stringify(type)})`);\n }\n const lifetime = payload.exp! - payload.iat!;\n if (lifetime > maxLifetimeSec) {\n throw new SsoError(`ticket claims a ${lifetime}s lifetime; at most ${maxLifetimeSec}s is accepted`);\n }\n if (typeof payload.sub !== \"string\" || payload.sub === \"\") throw new SsoError(\"ticket has no sub\");\n\n const scopes = typeof payload.scope === \"string\" ? payload.scope.split(\" \").filter(Boolean) : [];\n const required = opts.scope === undefined ? [] : Array.isArray(opts.scope) ? opts.scope : [opts.scope];\n const missing = required.filter((s) => !scopes.includes(s));\n if (missing.length) throw new SsoError(`ticket lacks scope ${missing.join(\", \")}`);\n\n // F084.156 — ver: unknown future formats are refused by name, never read\n // with today's rules.\n const ver = payload.ver === undefined ? 0 : payload.ver;\n if (typeof ver !== \"number\" || !Number.isInteger(ver) || ver < 0) {\n throw new SsoError(`ticket has an invalid ver (got ${JSON.stringify(payload.ver)})`);\n }\n if (ver > TICKET_FORMAT_VERSION) {\n throw new SsoError(`ticket format version ${ver} is newer than this @broberg/sso understands (${TICKET_FORMAT_VERSION}) — upgrade @broberg/sso`);\n }\n // The whole chain, or a refusal. 0.14.2 kept only act.sub, cutting a chain\n // to its first link, and read a malformed act as \"no delegation\" — both in\n // the direction where the caller looks like it acts for fewer people.\n const act = payload.act === undefined ? null : readActor(payload.act, 1);\n const cnfRaw = payload.cnf as { jkt?: unknown } | undefined;\n const cnf = cnfRaw && typeof cnfRaw.jkt === \"string\" && cnfRaw.jkt ? { jkt: cnfRaw.jkt } : null;\n // F084.157 — a bound ticket needs its proof, always; requireDpop only\n // decides about unbound ones (and then a cnf it cannot read is refused too).\n if (cnf) {\n if (!opts.dpop?.proof) throw new SsoError(\"ticket is DPoP-bound (cnf.jkt) but no DPoP proof was presented\");\n await verifyDpopProof(opts.dpop.proof, {\n method: opts.dpop.method,\n url: opts.dpop.url,\n ticket: token,\n jkt: cnf.jkt,\n replay: replayStore,\n iatWindowSec: dpopIatWindowSec,\n now,\n });\n } else if (requireDpop) {\n throw new SsoError(cnfRaw !== undefined ? \"ticket has a cnf without a string jkt — DPoP is required here\" : \"this receiver requires DPoP; the ticket is not bound (no cnf.jkt)\");\n }\n // F084.159 — on a user ticket sub is the USER. Falling back to it would turn a\n // user id into an app id, so a receiver that requires clientId === \"trail-clipper\"\n // could be satisfied by a user who happens to be called that.\n const named = (v: unknown) => (typeof v === \"string\" && v ? v : null);\n const clientId =\n type === \"user\"\n ? named(payload.client_id) ?? named(payload.azp)\n : named(payload.client_id) ?? payload.sub;\n if (clientId === null) throw new SsoError(\"a user ticket names no app (no client_id or azp)\");\n return {\n principal: payload.sub,\n type: type as PrincipalType,\n clientId,\n org: typeof payload.org === \"string\" && payload.org ? payload.org : null,\n act,\n version: ver,\n cnf,\n scopes,\n exp: payload.exp!,\n jti: String(payload.jti),\n };\n },\n };\n}\n\nfunction readActor(raw: unknown, depth: number): TicketActor {\n if (depth > MAX_ACT_DEPTH) throw new SsoError(`ticket's delegation chain is deeper than ${MAX_ACT_DEPTH}`);\n const link = raw as { sub?: unknown; act?: unknown } | null;\n if (!link || typeof link !== \"object\" || typeof link.sub !== \"string\" || link.sub === \"\") {\n throw new SsoError(`ticket's act (link ${depth}) has no string sub`);\n }\n return link.act === undefined ? { sub: link.sub } : { sub: link.sub, act: readActor(link.act, depth + 1) };\n}\n"]}
@@ -57,6 +57,105 @@ interface SsoConfig {
57
57
  declare const DEFAULT_SESSION_MAX_AGE: number;
58
58
  declare function loadSsoConfig(env?: NodeJS.ProcessEnv): SsoConfig;
59
59
 
60
+ /** What a step can answer, as data the app can word itself (the contract's error table). */
61
+ type EmbeddedError = {
62
+ kind: "invalid_code";
63
+ attemptsLeft?: number;
64
+ } | {
65
+ kind: "expired";
66
+ } | {
67
+ kind: "locked";
68
+ retryAfter?: number;
69
+ } | {
70
+ kind: "too_many_requests";
71
+ retryAfter?: number;
72
+ } | {
73
+ kind: "not_embedded";
74
+ } | {
75
+ kind: "signup_not_enabled";
76
+ } | {
77
+ kind: "terms_outdated";
78
+ version?: string;
79
+ } | {
80
+ kind: "invalid_request";
81
+ } | {
82
+ kind: "unavailable";
83
+ message: string;
84
+ };
85
+ /** The server-side state of one embedded login: keep it in a signed cookie (sealEmbeddedFlow). */
86
+ interface EmbeddedFlow {
87
+ flowId: string;
88
+ codeVerifier: string;
89
+ nonce: string;
90
+ email: string;
91
+ }
92
+ interface EmbeddedStartInput {
93
+ email: string;
94
+ /** "signup" creates the account at verify (BID F084.167); needs `name` and the current `termsVersion`. */
95
+ intent?: "login" | "signup";
96
+ name?: string;
97
+ termsVersion?: string;
98
+ /** The user's IP, for BID's per-IP limit. Without it, BID counts your server's IP. */
99
+ endUserIp?: string;
100
+ }
101
+ type EmbeddedStart = {
102
+ ok: true;
103
+ flow: EmbeddedFlow;
104
+ expiresIn: number;
105
+ } | {
106
+ ok: false;
107
+ error: EmbeddedError;
108
+ };
109
+ /** After a code: signed in (the same result as completeLogin), a second factor, or an error. */
110
+ type EmbeddedStep = {
111
+ kind: "done";
112
+ result: LoginResult;
113
+ } | {
114
+ kind: "second_factor";
115
+ methods: ("totp" | "sms")[];
116
+ } | {
117
+ kind: "error";
118
+ error: EmbeddedError;
119
+ };
120
+ interface EmbeddedTerms {
121
+ version: string;
122
+ /** Show it VERBATIM at the button — BID owns the text. */
123
+ text: string;
124
+ links: {
125
+ label: string;
126
+ url: string;
127
+ }[];
128
+ }
129
+ interface EmbeddedClient {
130
+ start(input: EmbeddedStartInput): Promise<EmbeddedStart>;
131
+ verify(flow: EmbeddedFlow, code: string): Promise<EmbeddedStep>;
132
+ sendSms(flow: EmbeddedFlow): Promise<{
133
+ ok: true;
134
+ } | {
135
+ ok: false;
136
+ error: EmbeddedError;
137
+ }>;
138
+ verifySecondFactor(flow: EmbeddedFlow, method: "totp" | "sms", code: string): Promise<EmbeddedStep>;
139
+ /** BID's consent text for signup, current version. Throws SsoError if BID does not answer it. */
140
+ terms(lang: "da" | "en"): Promise<EmbeddedTerms>;
141
+ }
142
+ /** A flow lives as long as BID's code does (10 min). */
143
+ declare const EMBEDDED_FLOW_MAX_AGE = 600;
144
+ /** Seal the flow for a signed, httpOnly cookie (same signing as the login transaction). */
145
+ declare function sealEmbeddedFlow(flow: EmbeddedFlow, secret: string, options?: {
146
+ now?: () => number;
147
+ }): Promise<string>;
148
+ /** Read it back: the flow, or why not — "absent" (no cookie), "expired" (too old), "unreadable" (not ours / tampered). */
149
+ declare function openEmbeddedFlow(raw: string | undefined | null, secret: string, options?: {
150
+ now?: () => number;
151
+ }): Promise<{
152
+ ok: true;
153
+ flow: EmbeddedFlow;
154
+ } | {
155
+ ok: false;
156
+ reason: "absent" | "expired" | "unreadable";
157
+ }>;
158
+
60
159
  /**
61
160
  * The signing-key cache.
62
161
  *
@@ -357,6 +456,12 @@ interface SsoClient {
357
456
  verifyIdToken(idToken: string, options?: {
358
457
  nonce?: string;
359
458
  }): Promise<SsoClaims>;
459
+ /**
460
+ * components-F084.165 — the embedded login and signup (BID F084.166 v1.1 + F084.167), called
461
+ * from YOUR SERVER as a confidential client (needs `clientSecret`). Ends in the same
462
+ * LoginResult as completeLogin. Keep the returned flow in a cookie with sealEmbeddedFlow.
463
+ */
464
+ embedded: EmbeddedClient;
360
465
  logoutUrl(options?: {
361
466
  idTokenHint?: string;
362
467
  postLogoutRedirectUri?: string;
@@ -623,4 +728,4 @@ declare function cookieHeader(name: string, value: string, opts: {
623
728
  }): string;
624
729
  declare function readCookie(header: string | null | undefined, name: string): string | undefined;
625
730
 
626
- export { AVATAR_TYPES as A, type BeginLoginOptions as B, type CreateSsoClientOptions as C, DEFAULT_SESSION_MAX_AGE as D, SsoTokenInactiveError as E, type TokenSet as F, cookieHeader as G, createJwksCache as H, type IntrospectOptions as I, type JwksCache as J, createSsoClient as K, type LoginResult as L, MAX_AVATAR_BYTES as M, loadSsoConfig as N, memoryTokenStore as O, readCookie as P, signSession as Q, signValue as R, type SsoClient as S, type TokenStore as T, verifySession as U, verifyValue as V, type SsoConfig as a, type SessionPayload as b, type AddressOwnership as c, type BidProfile as d, type Discovery as e, type IntrospectedToken as f, type InvitationOutcome as g, type InvitationResult as h, type InviteUsersInput as i, type JwksCacheOptions as j, JwksError as k, JwksUnavailableError as l, JwksUnknownKeyError as m, type LoginStart as n, type LogoutToken as o, MAX_INVITATIONS as p, type MigrationState as q, type MigrationStatus as r, SsoAppApiError as s, SsoAvatarRejectedError as t, type SsoClaims as u, SsoConfigError as v, SsoError as w, SsoInsufficientScopeError as x, SsoIntrospectionUnavailableError as y, SsoReauthError as z };
731
+ export { sealEmbeddedFlow as $, AVATAR_TYPES as A, type BeginLoginOptions as B, type CreateSsoClientOptions as C, DEFAULT_SESSION_MAX_AGE as D, EMBEDDED_FLOW_MAX_AGE as E, SsoAvatarRejectedError as F, type SsoClaims as G, SsoConfigError as H, type IntrospectOptions as I, type JwksCache as J, SsoError as K, type LoginResult as L, MAX_AVATAR_BYTES as M, SsoInsufficientScopeError as N, SsoIntrospectionUnavailableError as O, SsoReauthError as P, SsoTokenInactiveError as Q, type TokenSet as R, type SsoClient as S, type TokenStore as T, cookieHeader as U, createJwksCache as V, createSsoClient as W, loadSsoConfig as X, memoryTokenStore as Y, openEmbeddedFlow as Z, readCookie as _, type SsoConfig as a, signSession as a0, signValue as a1, verifySession as a2, verifyValue as a3, type SessionPayload as b, type AddressOwnership as c, type BidProfile as d, type Discovery as e, type EmbeddedClient as f, type EmbeddedError as g, type EmbeddedFlow as h, type EmbeddedStart as i, type EmbeddedStartInput as j, type EmbeddedStep as k, type EmbeddedTerms as l, type IntrospectedToken as m, type InvitationOutcome as n, type InvitationResult as o, type InviteUsersInput as p, type JwksCacheOptions as q, JwksError as r, JwksUnavailableError as s, JwksUnknownKeyError as t, type LoginStart as u, type LogoutToken as v, MAX_INVITATIONS as w, type MigrationState as x, type MigrationStatus as y, SsoAppApiError as z };
@@ -57,6 +57,105 @@ interface SsoConfig {
57
57
  declare const DEFAULT_SESSION_MAX_AGE: number;
58
58
  declare function loadSsoConfig(env?: NodeJS.ProcessEnv): SsoConfig;
59
59
 
60
+ /** What a step can answer, as data the app can word itself (the contract's error table). */
61
+ type EmbeddedError = {
62
+ kind: "invalid_code";
63
+ attemptsLeft?: number;
64
+ } | {
65
+ kind: "expired";
66
+ } | {
67
+ kind: "locked";
68
+ retryAfter?: number;
69
+ } | {
70
+ kind: "too_many_requests";
71
+ retryAfter?: number;
72
+ } | {
73
+ kind: "not_embedded";
74
+ } | {
75
+ kind: "signup_not_enabled";
76
+ } | {
77
+ kind: "terms_outdated";
78
+ version?: string;
79
+ } | {
80
+ kind: "invalid_request";
81
+ } | {
82
+ kind: "unavailable";
83
+ message: string;
84
+ };
85
+ /** The server-side state of one embedded login: keep it in a signed cookie (sealEmbeddedFlow). */
86
+ interface EmbeddedFlow {
87
+ flowId: string;
88
+ codeVerifier: string;
89
+ nonce: string;
90
+ email: string;
91
+ }
92
+ interface EmbeddedStartInput {
93
+ email: string;
94
+ /** "signup" creates the account at verify (BID F084.167); needs `name` and the current `termsVersion`. */
95
+ intent?: "login" | "signup";
96
+ name?: string;
97
+ termsVersion?: string;
98
+ /** The user's IP, for BID's per-IP limit. Without it, BID counts your server's IP. */
99
+ endUserIp?: string;
100
+ }
101
+ type EmbeddedStart = {
102
+ ok: true;
103
+ flow: EmbeddedFlow;
104
+ expiresIn: number;
105
+ } | {
106
+ ok: false;
107
+ error: EmbeddedError;
108
+ };
109
+ /** After a code: signed in (the same result as completeLogin), a second factor, or an error. */
110
+ type EmbeddedStep = {
111
+ kind: "done";
112
+ result: LoginResult;
113
+ } | {
114
+ kind: "second_factor";
115
+ methods: ("totp" | "sms")[];
116
+ } | {
117
+ kind: "error";
118
+ error: EmbeddedError;
119
+ };
120
+ interface EmbeddedTerms {
121
+ version: string;
122
+ /** Show it VERBATIM at the button — BID owns the text. */
123
+ text: string;
124
+ links: {
125
+ label: string;
126
+ url: string;
127
+ }[];
128
+ }
129
+ interface EmbeddedClient {
130
+ start(input: EmbeddedStartInput): Promise<EmbeddedStart>;
131
+ verify(flow: EmbeddedFlow, code: string): Promise<EmbeddedStep>;
132
+ sendSms(flow: EmbeddedFlow): Promise<{
133
+ ok: true;
134
+ } | {
135
+ ok: false;
136
+ error: EmbeddedError;
137
+ }>;
138
+ verifySecondFactor(flow: EmbeddedFlow, method: "totp" | "sms", code: string): Promise<EmbeddedStep>;
139
+ /** BID's consent text for signup, current version. Throws SsoError if BID does not answer it. */
140
+ terms(lang: "da" | "en"): Promise<EmbeddedTerms>;
141
+ }
142
+ /** A flow lives as long as BID's code does (10 min). */
143
+ declare const EMBEDDED_FLOW_MAX_AGE = 600;
144
+ /** Seal the flow for a signed, httpOnly cookie (same signing as the login transaction). */
145
+ declare function sealEmbeddedFlow(flow: EmbeddedFlow, secret: string, options?: {
146
+ now?: () => number;
147
+ }): Promise<string>;
148
+ /** Read it back: the flow, or why not — "absent" (no cookie), "expired" (too old), "unreadable" (not ours / tampered). */
149
+ declare function openEmbeddedFlow(raw: string | undefined | null, secret: string, options?: {
150
+ now?: () => number;
151
+ }): Promise<{
152
+ ok: true;
153
+ flow: EmbeddedFlow;
154
+ } | {
155
+ ok: false;
156
+ reason: "absent" | "expired" | "unreadable";
157
+ }>;
158
+
60
159
  /**
61
160
  * The signing-key cache.
62
161
  *
@@ -357,6 +456,12 @@ interface SsoClient {
357
456
  verifyIdToken(idToken: string, options?: {
358
457
  nonce?: string;
359
458
  }): Promise<SsoClaims>;
459
+ /**
460
+ * components-F084.165 — the embedded login and signup (BID F084.166 v1.1 + F084.167), called
461
+ * from YOUR SERVER as a confidential client (needs `clientSecret`). Ends in the same
462
+ * LoginResult as completeLogin. Keep the returned flow in a cookie with sealEmbeddedFlow.
463
+ */
464
+ embedded: EmbeddedClient;
360
465
  logoutUrl(options?: {
361
466
  idTokenHint?: string;
362
467
  postLogoutRedirectUri?: string;
@@ -623,4 +728,4 @@ declare function cookieHeader(name: string, value: string, opts: {
623
728
  }): string;
624
729
  declare function readCookie(header: string | null | undefined, name: string): string | undefined;
625
730
 
626
- export { AVATAR_TYPES as A, type BeginLoginOptions as B, type CreateSsoClientOptions as C, DEFAULT_SESSION_MAX_AGE as D, SsoTokenInactiveError as E, type TokenSet as F, cookieHeader as G, createJwksCache as H, type IntrospectOptions as I, type JwksCache as J, createSsoClient as K, type LoginResult as L, MAX_AVATAR_BYTES as M, loadSsoConfig as N, memoryTokenStore as O, readCookie as P, signSession as Q, signValue as R, type SsoClient as S, type TokenStore as T, verifySession as U, verifyValue as V, type SsoConfig as a, type SessionPayload as b, type AddressOwnership as c, type BidProfile as d, type Discovery as e, type IntrospectedToken as f, type InvitationOutcome as g, type InvitationResult as h, type InviteUsersInput as i, type JwksCacheOptions as j, JwksError as k, JwksUnavailableError as l, JwksUnknownKeyError as m, type LoginStart as n, type LogoutToken as o, MAX_INVITATIONS as p, type MigrationState as q, type MigrationStatus as r, SsoAppApiError as s, SsoAvatarRejectedError as t, type SsoClaims as u, SsoConfigError as v, SsoError as w, SsoInsufficientScopeError as x, SsoIntrospectionUnavailableError as y, SsoReauthError as z };
731
+ export { sealEmbeddedFlow as $, AVATAR_TYPES as A, type BeginLoginOptions as B, type CreateSsoClientOptions as C, DEFAULT_SESSION_MAX_AGE as D, EMBEDDED_FLOW_MAX_AGE as E, SsoAvatarRejectedError as F, type SsoClaims as G, SsoConfigError as H, type IntrospectOptions as I, type JwksCache as J, SsoError as K, type LoginResult as L, MAX_AVATAR_BYTES as M, SsoInsufficientScopeError as N, SsoIntrospectionUnavailableError as O, SsoReauthError as P, SsoTokenInactiveError as Q, type TokenSet as R, type SsoClient as S, type TokenStore as T, cookieHeader as U, createJwksCache as V, createSsoClient as W, loadSsoConfig as X, memoryTokenStore as Y, openEmbeddedFlow as Z, readCookie as _, type SsoConfig as a, signSession as a0, signValue as a1, verifySession as a2, verifyValue as a3, type SessionPayload as b, type AddressOwnership as c, type BidProfile as d, type Discovery as e, type EmbeddedClient as f, type EmbeddedError as g, type EmbeddedFlow as h, type EmbeddedStart as i, type EmbeddedStartInput as j, type EmbeddedStep as k, type EmbeddedTerms as l, type IntrospectedToken as m, type InvitationOutcome as n, type InvitationResult as o, type InviteUsersInput as p, type JwksCacheOptions as q, JwksError as r, JwksUnavailableError as s, JwksUnknownKeyError as t, type LoginStart as u, type LogoutToken as v, MAX_INVITATIONS as w, type MigrationState as x, type MigrationStatus as y, SsoAppApiError as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@broberg/sso",
3
- "version": "0.18.2",
3
+ "version": "0.19.0",
4
4
  "description": "The thin client for BrobergID — send a user to central login, verify the ID token against JWKS, keep a local session. Public client + PKCE only: no passwords, no passkeys, no client secret can live in an app.",
5
5
  "type": "module",
6
6
  "license": "MIT",