@softistx/alxia-react-router 0.87.0 → 0.88.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/README.md +67 -2
- package/dist/chunks/{index-t2ph23wk.js → index-5hjhzztk.js} +6 -17
- package/dist/chunks/{index-t2ph23wk.js.map → index-5hjhzztk.js.map} +3 -4
- package/dist/chunks/{index-v2z5k640.js → index-6zx9dfvs.js} +3 -18
- package/dist/chunks/{index-v2z5k640.js.map → index-6zx9dfvs.js.map} +3 -4
- package/dist/chunks/index-njfh26ez.js +19 -0
- package/dist/chunks/index-njfh26ez.js.map +10 -0
- package/dist/chunks/index-t68hwhz1.js +37 -0
- package/dist/chunks/{index-0786n4qe.js.map → index-t68hwhz1.js.map} +5 -4
- package/dist/errors/index.js +5 -3
- package/dist/errors/index.js.map +2 -2
- package/dist/oidc/dpop-fetch.d.ts +39 -0
- package/dist/oidc/dpop-fetch.d.ts.map +1 -0
- package/dist/oidc/env.d.ts +52 -0
- package/dist/oidc/env.d.ts.map +1 -0
- package/dist/oidc/index.d.ts +3 -0
- package/dist/oidc/index.d.ts.map +1 -1
- package/dist/oidc/index.js +248 -24
- package/dist/oidc/index.js.map +8 -5
- package/dist/oidc/oidc.d.ts +18 -0
- package/dist/oidc/oidc.d.ts.map +1 -1
- package/dist/oidc/routes.d.ts +76 -0
- package/dist/oidc/routes.d.ts.map +1 -0
- package/dist/session/index.js +9 -7
- package/dist/session/index.js.map +2 -2
- package/dist/session/model/index.js +2 -2
- package/docs/README.md +1 -1
- package/docs/guide/fetcher.md +13 -0
- package/docs/guide/oidc.md +172 -6
- package/docs/roadmap.md +8 -0
- package/docs/troubleshooting.md +109 -0
- package/package.json +7 -7
- package/dist/chunks/index-0786n4qe.js +0 -25
package/dist/oidc/index.js.map
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/oidc/dpop.ts", "../src/oidc/seal.ts", "../src/oidc/errors.ts", "../src/oidc/oidc.ts", "../src/oidc/flow.ts", "../src/oidc/revoke.ts"],
|
|
3
|
+
"sources": ["../src/oidc/dpop.ts", "../src/oidc/seal.ts", "../src/oidc/dpop-fetch.ts", "../src/oidc/env.ts", "../src/oidc/errors.ts", "../src/oidc/oidc.ts", "../src/oidc/flow.ts", "../src/oidc/revoke.ts", "../src/oidc/routes.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import {\n\tcalculateJwkThumbprint,\n\texportJWK,\n\tgenerateKeyPair,\n\timportJWK,\n\ttype JWK,\n\tSignJWT,\n} from 'jose';\nimport { randomToken, toBase64Url } from './seal';\n\n/** The signature algorithms of a DPoP key (RFC 9449). */\nexport type DpopAlgorithm = 'ES256' | 'EdDSA';\n\n/** A DPoP key pair as it is stored with the session: the private JWK and its algorithm. */\nexport interface DpopKey {\n\treadonly alg: DpopAlgorithm;\n\treadonly jwk: JWK;\n}\n\n/** What a proof is signed for. */\nexport interface DpopProofInput {\n\t/** The HTTP method of the request the proof goes with. */\n\treadonly method: string;\n\t/** The request's URL; its query and fragment are dropped (`htu`). */\n\treadonly url: string | URL;\n\t/** The access token the proof is bound to (`ath`), for a call to a resource. */\n\treadonly accessToken?: string | undefined;\n\t/** The server's last `DPoP-Nonce`. */\n\treadonly nonce?: string | undefined;\n\t/** The clock, in ms; `Date.now` by default. */\n\treadonly now?: (() => number) | undefined;\n}\n\nconst encoder = new TextEncoder();\n\n/** A fresh DPoP key pair (ES256 by default), the private half as a JWK. */\nexport async function generateDpopKey(\n\talg: DpopAlgorithm = 'ES256',\n): Promise<DpopKey> {\n\tconst { privateKey } = await generateKeyPair(alg, { extractable: true });\n\treturn {\n\t\talg,\n\t\tjwk: pick(await exportJWK(privateKey), ['kty', 'crv', 'x', 'y', 'd']),\n\t};\n}\n\n/** Only the named members of a JWK that are set. */\nconst pick = (jwk: JWK, names: readonly (keyof JWK)[]): JWK =>\n\tObject.fromEntries(\n\t\tnames.flatMap((name) =>\n\t\t\tjwk[name] === undefined ? [] : [[name, jwk[name]]],\n\t\t),\n\t) as JWK;\n\nconst publicOf = (jwk: JWK): JWK => pick(jwk, ['kty', 'crv', 'x', 'y']);\n\n/** The RFC 7638 thumbprint of the key's public half (the `jkt` a server binds a token to). */\nexport const dpopThumbprint = (key: DpopKey): Promise<string> =>\n\tcalculateJwkThumbprint(publicOf(key.jwk), 'sha256');\n\n/** The URL a proof names: no query, no fragment. */\nexport function dpopTarget(url: string | URL): string {\n\tconst target = new URL(url);\n\ttarget.search = '';\n\ttarget.hash = '';\n\treturn target.toString();\n}\n\n/**\n * A DPoP proof (RFC 9449 section 4): a JWT of type `dpop+jwt` carrying the\n * key's public half, signed for one method and URL, with `ath` when it goes\n * with an access token and `nonce` when the server asked for one.\n */\nexport async function signDpopProof(\n\tkey: DpopKey,\n\tinput: DpopProofInput,\n): Promise<string> {\n\tconst signer = await importJWK(key.jwk, key.alg);\n\tconst iat = Math.floor((input.now ?? Date.now)() / 1000);\n\tconst ath =\n\t\tinput.accessToken === undefined\n\t\t\t? undefined\n\t\t\t: toBase64Url(\n\t\t\t\t\tnew Uint8Array(\n\t\t\t\t\t\tawait crypto.subtle.digest(\n\t\t\t\t\t\t\t'SHA-256',\n\t\t\t\t\t\t\tencoder.encode(input.accessToken),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t);\n\treturn new SignJWT({\n\t\thtm: input.method.toUpperCase(),\n\t\thtu: dpopTarget(input.url),\n\t\tjti: randomToken(16),\n\t\tiat,\n\t\t...(input.nonce !== undefined && { nonce: input.nonce }),\n\t\t...(ath !== undefined && { ath }),\n\t})\n\t\t.setProtectedHeader({\n\t\t\ttyp: 'dpop+jwt',\n\t\t\talg: key.alg,\n\t\t\tjwk: publicOf(key.jwk),\n\t\t})\n\t\t.sign(signer);\n}\n\n/** The last `DPoP-Nonce` each server sent, by origin (RFC 9449 section 8: a nonce belongs to one server). */\nexport interface NonceMemory {\n\tget(url: string | URL): string | undefined;\n\tset(url: string | URL, nonce: string): void;\n}\n\nexport function nonceMemory(): NonceMemory {\n\tconst nonces = new Map<string, string>();\n\treturn {\n\t\tget: (url) => nonces.get(new URL(url).origin),\n\t\tset: (url, nonce) => void nonces.set(new URL(url).origin, nonce),\n\t};\n}\n\n/** Whether a response asks for a (new) nonce: 400 `use_dpop_nonce` at an endpoint, 401 `WWW-Authenticate` at a resource. */\nexport async function wantsNonce(response: Response): Promise<boolean> {\n\tif (!response.headers.get('dpop-nonce')) return false;\n\tif (response.status === 401) {\n\t\treturn /use_dpop_nonce/.test(\n\t\t\tresponse.headers.get('www-authenticate') ?? '',\n\t\t);\n\t}\n\tif (response.status !== 400) return false;\n\tconst body: unknown = await response\n\t\t.clone()\n\t\t.json()\n\t\t.catch(() => null);\n\treturn (\n\t\ttypeof body === 'object' &&\n\t\tbody !== null &&\n\t\t(body as Record<string, unknown>)['error'] === 'use_dpop_nonce'\n\t);\n}\n\n/**\n * The DPoP side of a signed-in user: signs proofs for calls to a resource with\n * the session's key, bound to its access token.\n */\nexport interface DpopBinding {\n\t/** The key's thumbprint (`jkt`). */\n\treadonly thumbprint: string;\n\t/** A proof for one call (`htm`, `htu`, `ath`), with the nonce the server last sent unless one is given. */\n\tproof(input: {\n\t\treadonly method: string;\n\t\treadonly url: string | URL;\n\t\treadonly nonce?: string | undefined;\n\t}): Promise<string>;\n\t/** The two headers of a call: `Authorization: DPoP <token>` and `DPoP: <proof>`. */\n\theaders(input: {\n\t\treadonly method: string;\n\t\treadonly url: string | URL;\n\t\treadonly nonce?: string | undefined;\n\t}): Promise<{ readonly authorization: string; readonly dpop: string }>;\n\t/**\n\t * `fetch` with both headers set and the nonce retry: on `401` with\n\t * `WWW-Authenticate: DPoP error=\"use_dpop_nonce\"` it signs again with the\n\t * `DPoP-Nonce` header and retries once. Give a string or bytes as `body`,\n\t * since a stream cannot be sent twice.\n\t */\n\tfetch(input: string | URL, init?: RequestInit): Promise<Response>;\n}\n\nexport function dpopBinding(config: {\n\treadonly key: DpopKey;\n\treadonly thumbprint: string;\n\treadonly accessToken: string;\n\treadonly nonces: NonceMemory;\n\treadonly fetch: (input: string, init?: RequestInit) => Promise<Response>;\n\treadonly now: () => number;\n}): DpopBinding {\n\tconst { key, accessToken, nonces } = config;\n\tconst proof: DpopBinding['proof'] = ({ method, url, nonce }) =>\n\t\tsignDpopProof(key, {\n\t\t\tmethod,\n\t\t\turl,\n\t\t\taccessToken,\n\t\t\tnonce: nonce ?? nonces.get(url),\n\t\t\tnow: config.now,\n\t\t});\n\treturn {\n\t\tthumbprint: config.thumbprint,\n\t\tproof,\n\t\tasync headers(input) {\n\t\t\treturn {\n\t\t\t\tauthorization: `DPoP ${accessToken}`,\n\t\t\t\tdpop: await proof(input),\n\t\t\t};\n\t\t},\n\t\tasync fetch(input, init) {\n\t\t\tconst url = String(input);\n\t\t\tconst method = init?.method ?? 'GET';\n\t\t\tconst send = async (nonce?: string) => {\n\t\t\t\tconst headers = new Headers(init?.headers);\n\t\t\t\theaders.set('authorization', `DPoP ${accessToken}`);\n\t\t\t\theaders.set('dpop', await proof({ method, url, nonce }));\n\t\t\t\tconst response = await config.fetch(url, { ...init, headers });\n\t\t\t\tconst sent = response.headers.get('dpop-nonce');\n\t\t\t\tif (sent) nonces.set(url, sent);\n\t\t\t\treturn response;\n\t\t\t};\n\t\t\tconst first = await send();\n\t\t\tif (!(await wantsNonce(first))) return first;\n\t\t\treturn send(first.headers.get('dpop-nonce') ?? undefined);\n\t\t},\n\t};\n}\n",
|
|
6
6
|
"const encoder = new TextEncoder();\nconst decoder = new TextDecoder();\n\n/** Bytes as unpadded base64url. */\nexport const toBase64Url = (bytes: Uint8Array): string => {\n\tlet binary = '';\n\tfor (const byte of bytes) binary += String.fromCharCode(byte);\n\treturn btoa(binary)\n\t\t.replaceAll('+', '-')\n\t\t.replaceAll('/', '_')\n\t\t.replaceAll('=', '');\n};\n\nconst fromBase64Url = (text: string): Uint8Array<ArrayBuffer> => {\n\tconst padded = text.replaceAll('-', '+').replaceAll('_', '/');\n\tconst binary = atob(padded + '='.repeat((4 - (padded.length % 4)) % 4));\n\treturn Uint8Array.from(binary, (char) => char.charCodeAt(0));\n};\n\n/** `bytes` random bytes as base64url. */\nexport const randomToken = (bytes = 32): string =>\n\ttoBase64Url(crypto.getRandomValues(new Uint8Array(bytes)));\n\n/** Whether two strings are equal, comparing every byte whatever the first difference. */\nexport function sameText(a: string, b: string): boolean {\n\tconst left = encoder.encode(a);\n\tconst right = encoder.encode(b);\n\tlet difference = left.length ^ right.length;\n\tfor (let index = 0; index < Math.max(left.length, right.length); index++) {\n\t\tdifference |= (left[index] ?? 0) ^ (right[index] ?? 0);\n\t}\n\treturn difference === 0;\n}\n\n/** The base64url S256 challenge of a PKCE verifier. */\nexport async function s256(verifier: string): Promise<string> {\n\treturn toBase64Url(\n\t\tnew Uint8Array(\n\t\t\tawait crypto.subtle.digest('SHA-256', encoder.encode(verifier)),\n\t\t),\n\t);\n}\n\n/**\n * An AES-256-GCM sealer keyed from the session secret and a purpose, so a\n * challenge cookie cannot be replayed as a token cookie: the value is\n * encrypted (the tokens stay unreadable) and authenticated (nobody can forge\n * or edit it).\n */\nexport function sealer(secret: string, purpose: string) {\n\tconst key = crypto.subtle\n\t\t.digest('SHA-256', encoder.encode(`alxia-oidc/${purpose}/${secret}`))\n\t\t.then((raw) =>\n\t\t\tcrypto.subtle.importKey('raw', raw, 'AES-GCM', false, [\n\t\t\t\t'encrypt',\n\t\t\t\t'decrypt',\n\t\t\t]),\n\t\t);\n\tconst additionalData = encoder.encode(purpose);\n\treturn {\n\t\tasync seal(value: unknown): Promise<string> {\n\t\t\tconst iv = crypto.getRandomValues(new Uint8Array(12));\n\t\t\tconst data = new Uint8Array(\n\t\t\t\tawait crypto.subtle.encrypt(\n\t\t\t\t\t{ name: 'AES-GCM', iv, additionalData },\n\t\t\t\t\tawait key,\n\t\t\t\t\tencoder.encode(JSON.stringify(value)),\n\t\t\t\t),\n\t\t\t);\n\t\t\tconst out = new Uint8Array(iv.length + data.length);\n\t\t\tout.set(iv);\n\t\t\tout.set(data, iv.length);\n\t\t\treturn toBase64Url(out);\n\t\t},\n\t\t/** The value, or `null` when the text was not sealed with this secret and purpose. */\n\t\tasync open(text: string): Promise<unknown> {\n\t\t\ttry {\n\t\t\t\tconst bytes = fromBase64Url(text);\n\t\t\t\tif (bytes.length < 29) return null;\n\t\t\t\tconst plain = await crypto.subtle.decrypt(\n\t\t\t\t\t{ name: 'AES-GCM', iv: bytes.slice(0, 12), additionalData },\n\t\t\t\t\tawait key,\n\t\t\t\t\tbytes.slice(12),\n\t\t\t\t);\n\t\t\t\treturn JSON.parse(decoder.decode(plain));\n\t\t\t} catch {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t},\n\t};\n}\n",
|
|
7
|
+
"import type { OidcClient, OidcUser } from './oidc';\n\n/** A `fetch` that calls a resource as one signed-in user. */\nexport type DpopFetch = (\n\tinput: string | URL,\n\tinit?: RequestInit,\n) => Promise<Response>;\n\n/** The part of the relying party `dpopFetch` needs. */\nexport type DpopRefresher = Pick<OidcClient, 'refresh'>;\n\n/** Options of {@link dpopFetch}. */\nexport interface DpopFetchOptions {\n\t/**\n\t * Called with the new user each time the access token or its expiry changes\n\t * (parallel calls sharing one refresh report it once). Its `headers` hold the\n\t * `Set-Cookie` to pass with the route's answer (the last one wins: each refresh\n\t * starts from the previous user, so the cookie it sets replaces the older one).\n\t */\n\treadonly onUser?: ((user: OidcUser) => void) | undefined;\n}\n\n/**\n * `fetch` for the calls a loader or an action makes to an API as the signed-in\n * user. On a DPoP-bound session (`oidcClient`'s `dpop` option) each call carries\n * `Authorization: DPoP <token>` and a fresh proof (`htm`, `htu` without its\n * query, `ath`, `jti`), and a `401` with `WWW-Authenticate: DPoP\n * error=\"use_dpop_nonce\"` is signed again with the `DPoP-Nonce` sent and\n * retried once; the nonce is remembered per server. On a bearer session it\n * sends `Authorization: Bearer <token>` through the client's own `fetch`.\n *\n * It keeps the last user it got. Before each call it asks `oidc.refresh` for a\n * fresh one, which refreshes from that user's own tokens (never the request's\n * cookie, whose refresh token a rotation spends) only when the access token\n * ends within `refreshSkewSeconds`. A body must be a string or bytes, since a\n * stream cannot be sent twice.\n *\n * @example\n * const user = await oidc.requireOidcUser(request);\n * let latest = user;\n * const api = dpopFetch(oidc, user, { onUser: (next) => (latest = next) });\n * const orders = await (await api('https://api.example.com/orders?page=2')).json();\n * return data({ orders }, { headers: latest.headers });\n */\nexport function dpopFetch(\n\toidc: DpopRefresher,\n\tuser: OidcUser,\n\toptions: DpopFetchOptions = {},\n): DpopFetch {\n\tlet last = user;\n\treturn async (input, init) => {\n\t\tconst next = await oidc.refresh(last);\n\t\tif (\n\t\t\tnext.accessToken !== last.accessToken ||\n\t\t\tnext.expiresAt !== last.expiresAt\n\t\t) {\n\t\t\tlast = next;\n\t\t\toptions.onUser?.(next);\n\t\t}\n\t\tif (last.dpop) return last.dpop.fetch(input, init);\n\t\tconst headers = new Headers(init?.headers);\n\t\theaders.set('authorization', `Bearer ${last.accessToken}`);\n\t\treturn last.fetch(String(input), { ...init, headers });\n\t};\n}\n",
|
|
8
|
+
"import type { OidcOptions } from './oidc';\n\n/** Every start-up problem of the environment, in one error. */\nexport class OidcEnvError extends Error {\n\toverride readonly name = 'OidcEnvError';\n\tconstructor(readonly problems: readonly string[]) {\n\t\tsuper(\n\t\t\t`The OIDC environment is not usable:\\n${problems.map((p) => `- ${p}`).join('\\n')}`,\n\t\t);\n\t}\n}\n\n/** What {@link oidcFromEnv} reads. */\nexport interface OidcEnvSource {\n\t/** The variables' prefix. `'OIDC'` by default (`OIDC_ISSUER`, …). */\n\treadonly prefix?: string | undefined;\n\t/** The environment; `process.env` by default. */\n\treadonly env?: Readonly<Record<string, string | undefined>> | undefined;\n\t/** Reads a secret file; `Bun.file(path).text()` by default. */\n\treadonly readFile?: ((path: string) => Promise<string>) | undefined;\n\t/** Gives a secret file's `mode`, to refuse one that group or others can read; `Bun.file(path).stat()` by default. */\n\treadonly statFile?:\n\t\t| ((path: string) => Promise<{ readonly mode: number }>)\n\t\t| undefined;\n}\n\n/** What {@link oidcFromEnv} gives: spread it into `oidcClient`, with `secure`. */\nexport type OidcEnvOptions = Pick<\n\tOidcOptions,\n\t| 'issuer'\n\t| 'clientId'\n\t| 'clientSecret'\n\t| 'redirectUri'\n\t| 'secret'\n\t| 'name'\n\t| 'postLogoutRedirectUri'\n>;\n\n/** What the readers share: data only. */\ninterface Context {\n\treadonly env: Readonly<Record<string, string | undefined>>;\n\treadonly prefix: string;\n\treadonly problems: string[];\n\treadonly readFile: (path: string) => Promise<string>;\n\treadonly statFile: (path: string) => Promise<{ readonly mode: number }>;\n}\n\nconst LOOPBACK = new Set(['localhost', '127.0.0.1', '[::1]']);\n\nconst named = (context: Context, suffix: string) =>\n\t`${context.prefix}_${suffix}`;\n\nfunction plain(context: Context, suffix: string): string | undefined {\n\tconst value = context.env[named(context, suffix)]?.trim();\n\treturn value ? value : undefined;\n}\n\n/** A required plain value. */\nfunction required(context: Context, suffix: string): string | undefined {\n\tconst value = plain(context, suffix);\n\tif (value === undefined) {\n\t\tcontext.problems.push(`${named(context, suffix)} is not set.`);\n\t}\n\treturn value;\n}\n\n/** An absolute `https:` URL, `http:` on loopback only. */\nfunction url(\n\tcontext: Context,\n\tsuffix: string,\n\tmandatory: boolean,\n): string | undefined {\n\tconst value = mandatory ? required(context, suffix) : plain(context, suffix);\n\tif (value === undefined) return undefined;\n\tconst variable = named(context, suffix);\n\tlet parsed: URL;\n\ttry {\n\t\tparsed = new URL(value);\n\t} catch {\n\t\tcontext.problems.push(`${variable} is not an absolute URL.`);\n\t\treturn undefined;\n\t}\n\tif (\n\t\tparsed.protocol !== 'https:' &&\n\t\t!(parsed.protocol === 'http:' && LOOPBACK.has(parsed.hostname))\n\t) {\n\t\tcontext.problems.push(`${variable} must be an https: URL.`);\n\t\treturn undefined;\n\t}\n\treturn value;\n}\n\n/** A value given directly or through a `_FILE` variable, named by the one it came from. */\nasync function secret(\n\tcontext: Context,\n\tsuffix: string,\n\tmandatory: boolean,\n): Promise<{ value: string; variable: string } | undefined> {\n\tconst direct = plain(context, suffix);\n\tconst fileSuffix = `${suffix}_FILE`;\n\tconst path = plain(context, fileSuffix);\n\tif (direct !== undefined && path !== undefined) {\n\t\tcontext.problems.push(\n\t\t\t`Set ${named(context, suffix)} or ${named(context, fileSuffix)}, not both.`,\n\t\t);\n\t\treturn undefined;\n\t}\n\tif (path === undefined) {\n\t\tif (direct !== undefined) {\n\t\t\treturn { value: direct, variable: named(context, suffix) };\n\t\t}\n\t\tif (mandatory) {\n\t\t\tcontext.problems.push(\n\t\t\t\t`${named(context, fileSuffix)} (or ${named(context, suffix)}) is not set.`,\n\t\t\t);\n\t\t}\n\t\treturn undefined;\n\t}\n\tconst variable = named(context, fileSuffix);\n\tlet text: string;\n\ttry {\n\t\tconst { mode } = await context.statFile(path);\n\t\tif ((mode & 0o077) !== 0) {\n\t\t\tcontext.problems.push(\n\t\t\t\t`${variable} names a file readable by group or others (mode ${(mode & 0o777).toString(8)}); restrict it to its owner, such as chmod 600.`,\n\t\t\t);\n\t\t\treturn undefined;\n\t\t}\n\t\ttext = await context.readFile(path);\n\t} catch {\n\t\tcontext.problems.push(\n\t\t\t`${variable} names a file that cannot be read: check the path and its permissions.`,\n\t\t);\n\t\treturn undefined;\n\t}\n\tconst value = text.trim();\n\tif (value === '') {\n\t\tcontext.problems.push(`${variable} names an empty file.`);\n\t\treturn undefined;\n\t}\n\tif (/\\s/.test(value)) {\n\t\tcontext.problems.push(\n\t\t\t`${variable} names a file with whitespace inside: it must hold one value.`,\n\t\t);\n\t\treturn undefined;\n\t}\n\treturn { value, variable };\n}\n\n/**\n * The relying party's settings from the environment, checked once at start-up:\n * every missing or malformed variable is listed in one `OidcEnvError`, never a\n * secret's value. `secure` is not read from the environment: give it to\n * `oidcClient` yourself (`secure: !import.meta.env.DEV`).\n *\n * | variable (prefix `OIDC`) | |\n * | --- | --- |\n * | `OIDC_ISSUER` | required, an `https:` URL (`http:` on loopback) |\n * | `OIDC_CLIENT_ID` | required |\n * | `OIDC_CLIENT_SECRET_FILE` or `OIDC_CLIENT_SECRET` | the secret of a confidential client; none for a public one |\n * | `OIDC_REDIRECT_URI` | required, an `https:` URL (`http:` on loopback) |\n * | `OIDC_SESSION_SECRET_FILE` or `OIDC_SESSION_SECRET` | required, 32 characters or more |\n * | `OIDC_COOKIE_NAME` | `'oidc'` by default |\n * | `OIDC_POST_LOGOUT_REDIRECT_URI` | optional, an `https:` URL (`http:` on loopback) |\n *\n * A `_FILE` variable names a file whose trimmed content is the value, and\n * that only its owner can read (no group or other permission bit), with no\n * whitespace inside; a message never prints the path. Prefer it to the plain\n * variable for a secret.\n *\n * @example\n * export const oidc = oidcClient({\n * ...(await oidcFromEnv()),\n * secure: !import.meta.env.DEV,\n * scopes: ['profile', 'email', 'offline_access'],\n * });\n */\nexport async function oidcFromEnv(\n\tsource: OidcEnvSource = {},\n): Promise<OidcEnvOptions> {\n\tconst context: Context = {\n\t\tenv: source.env ?? process.env,\n\t\tprefix: source.prefix ?? 'OIDC',\n\t\tproblems: [],\n\t\treadFile: source.readFile ?? ((path) => Bun.file(path).text()),\n\t\tstatFile: source.statFile ?? ((path) => Bun.file(path).stat()),\n\t};\n\tconst issuer = url(context, 'ISSUER', true);\n\tconst clientId = required(context, 'CLIENT_ID');\n\tconst clientSecret = await secret(context, 'CLIENT_SECRET', false);\n\tconst redirectUri = url(context, 'REDIRECT_URI', true);\n\tconst postLogoutRedirectUri = url(context, 'POST_LOGOUT_REDIRECT_URI', false);\n\tconst session = await secret(context, 'SESSION_SECRET', true);\n\tif (session !== undefined && session.value.length < 32) {\n\t\tcontext.problems.push(\n\t\t\t`The session secret must be 32 characters or more (${session.variable}).`,\n\t\t);\n\t}\n\tif (\n\t\tcontext.problems.length > 0 ||\n\t\tissuer === undefined ||\n\t\tclientId === undefined ||\n\t\tredirectUri === undefined ||\n\t\tsession === undefined\n\t) {\n\t\tthrow new OidcEnvError(context.problems);\n\t}\n\treturn {\n\t\tissuer,\n\t\tclientId,\n\t\tclientSecret: clientSecret?.value,\n\t\tredirectUri,\n\t\tsecret: session.value,\n\t\tname: plain(context, 'COOKIE_NAME') ?? 'oidc',\n\t\tpostLogoutRedirectUri,\n\t};\n}\n",
|
|
7
9
|
"/** Why a relying-party step refused. */\nexport type OidcErrorCode =\n\t| 'discovery-failed'\n\t| 'missing-challenge'\n\t| 'challenge-expired'\n\t| 'provider-error'\n\t| 'issuer-mismatch'\n\t| 'state-mismatch'\n\t| 'missing-code'\n\t| 'token-exchange-failed'\n\t| 'invalid-id-token'\n\t| 'nonce-mismatch'\n\t| 'refresh-failed'\n\t| 'par-failed'\n\t| 'revoke-failed'\n\t| 'token-cookie-too-large';\n\n/**\n * What `callback` throws. `headers` holds the `Set-Cookie` that clears the\n * spent challenge: pass it when the route answers the failure, e.g.\n * `redirect('/sign-in?error=' + error.code, { headers: error.headers })`.\n */\nexport class OidcError extends Error {\n\toverride readonly name = 'OidcError';\n\tconstructor(\n\t\treadonly code: OidcErrorCode,\n\t\tmessage: string,\n\t\treadonly headers: Headers = new Headers(),\n\t\toptions?: { readonly cause?: unknown },\n\t) {\n\t\tsuper(message, options);\n\t}\n}\n",
|
|
8
|
-
"import type { JWTPayload } from 'jose';\nimport { redirect } from 'react-router';\nimport { sessionCookies } from '../session/cookies';\nimport { safeNext } from '../session/model/safe-next';\nimport {\n\ttype DpopAlgorithm,\n\ttype DpopBinding,\n\ttype DpopKey,\n\tdpopBinding,\n\tdpopThumbprint,\n\tgenerateDpopKey,\n\tnonceMemory,\n} from './dpop';\nimport { OidcError } from './errors';\nimport {\n\tdecodeJwt,\n\ttype Fetcher,\n\tissuerClient,\n\tpushRequest,\n\ttype TokenResponse,\n\ttokenRequest,\n} from './flow';\nimport { revokeTokens } from './revoke';\nimport { randomToken, s256, sameText, sealer } from './seal';\n\n/** What `oidcClient` takes. */\nexport interface OidcOptions {\n\t/** The issuer's identifier, exactly as its discovery document names it (no trailing slash needed). */\n\treadonly issuer: string;\n\treadonly clientId: string;\n\t/** The secret of a confidential client, sent as `client_secret_basic`. Omit it for a public client. */\n\treadonly clientSecret?: string | undefined;\n\t/** The absolute URL of the route that calls `callback`; registered with the issuer. */\n\treadonly redirectUri: string;\n\t/** `['openid', 'profile', 'email']` by default; `openid` is always sent. Add `offline_access` for a refresh token. */\n\treadonly scopes?: readonly string[] | undefined;\n\t/** Seals the cookies (AES-256-GCM): at least 32 characters, from the environment, never committed. Changing it signs everyone out. */\n\treadonly secret: string;\n\t/** The base name of the cookies, e.g. `'my-app_oidc'`; `__Host-` is added when `secure`. */\n\treadonly name: string;\n\t/** The app is served over HTTPS. Required, never read from the environment: pass `!import.meta.env.DEV`. */\n\treadonly secure: boolean;\n\t/** The route that starts the sign-in (it calls `signIn`). `'/sign-in'` by default. */\n\treadonly signInPath?: string | undefined;\n\t/** Where the issuer sends the browser after `logout`; it must be registered with the issuer. */\n\treadonly postLogoutRedirectUri?: string | undefined;\n\t/** How long the token cookie lives when there is a refresh token. 30 days by default; otherwise it ends with the access token. */\n\treadonly sessionSeconds?: number | undefined;\n\t/** Refresh when the access token ends within this many seconds. 60 by default. */\n\treadonly refreshSkewSeconds?: number | undefined;\n\t/** Clock difference accepted on `exp` and `iat`. 30 by default. */\n\treadonly clockToleranceSeconds?: number | undefined;\n\t/** Id token signature algorithms accepted. `RS256`, `PS256`, `ES256` and `EdDSA` by default. */\n\treadonly algorithms?: readonly string[] | undefined;\n\t/** Extra parameters of the authorization request, e.g. `{ prompt: 'login' }`. */\n\treadonly authorizationParams?: Readonly<Record<string, string>> | undefined;\n\t/**\n\t * Extra parameters of the token request, sent on the code exchange and on every refresh,\n\t * e.g. `{ resource: 'https://api.example' }` (RFC 8707). The parameters the flow owns\n\t * (`grant_type`, `code`, `redirect_uri`, `code_verifier`, `refresh_token`, `scope`) win over these, and `client_id` and `client_secret` are ignored.\n\t */\n\treadonly tokenParams?: Readonly<Record<string, string>> | undefined;\n\t/**\n\t * Pushed authorization requests (RFC 9126): the authorization request is POSTed to the issuer's\n\t * `pushed_authorization_request_endpoint` with the client's authentication, and the browser is\n\t * redirected with `client_id` and `request_uri` alone.\n\t * `'auto'` (default) pushes when discovery says `require_pushed_authorization_requests: true`;\n\t * `'always'` pushes whatever discovery says (and fails with `par-failed` without an endpoint);\n\t * `'never'` always sends the parameters in the redirect.\n\t */\n\treadonly par?: 'auto' | 'always' | 'never' | undefined;\n\t/**\n\t * Binds the tokens to a key with DPoP (RFC 9449). Off by default. A key pair per sign-in\n\t * (`ES256` by default, or `EdDSA`) is made at `signIn` and kept in the sealed cookies with the\n\t * session; the token endpoint (code and refresh) gets a proof, a `use_dpop_nonce` answer is\n\t * retried once with the nonce sent, and `OidcUser.dpop` signs the proofs of calls to a resource.\n\t */\n\treadonly dpop?: { readonly alg?: DpopAlgorithm | undefined } | undefined;\n\t/**\n\t * Revoke the refresh token and the access token at `logout` (RFC 7009). Off by default.\n\t * When on and discovery has a `revocation_endpoint`, `logout` POSTs the refresh token\n\t * (`token_type_hint=refresh_token`) then the access token (`token_type_hint=access_token`),\n\t * with the client's authentication and the DPoP proof of the token endpoint. A failure\n\t * (network error, non-2xx) never blocks the logout: the cookie is cleared and the redirect\n\t * sent, and the failure goes to `onRevokeError`.\n\t */\n\treadonly revokeOnLogout?: boolean | undefined;\n\t/** The most `logout` waits for the revocations, in ms, both together. 3000 by default. A stalled endpoint is aborted and reported as `revoke-failed`; the sign-out goes on. */\n\treadonly revokeTimeoutMs?: number | undefined;\n\t/** Called with each revocation failure at `logout` (an `OidcError` with code `revoke-failed`, or `discovery-failed`). Nothing by default. */\n\treadonly onRevokeError?: ((error: OidcError) => void) | undefined;\n\t/** The `fetch` used for discovery, the keys and the token endpoint; global `fetch` by default. */\n\treadonly fetch?: Fetcher | undefined;\n\t/** The clock, in ms; `Date.now` by default. */\n\treadonly now?: (() => number) | undefined;\n}\n\n/** The signed-in user a loader reads. */\nexport interface OidcUser {\n\t/** The id token's claims. */\n\treadonly claims: JWTPayload;\n\treadonly accessToken: string;\n\treadonly idToken: string;\n\t/** When the access token ends, in ms. */\n\treadonly expiresAt: number;\n\t/** `Set-Cookie` when the tokens were refreshed, else empty: pass it with the loader's answer. */\n\treadonly headers: Headers;\n\t/** Signs the proofs of calls to a resource when the tokens are DPoP-bound (`dpop` option, and the issuer sent `token_type: DPoP`), else `null`. */\n\treadonly dpop: DpopBinding | null;\n}\n\n/** The relying party `oidcClient` returns. */\nexport interface OidcClient {\n\t/** The route action or loader that starts the sign-in: a redirect to the issuer. `?next=` is kept, through `safeNext`. */\n\tsignIn(request: Request): Promise<Response>;\n\t/** The redirect route: checks state, exchanges the code, validates the id token, sets the token cookie and redirects to `next`. Throws `OidcError`. */\n\tcallback(request: Request): Promise<Response>;\n\t/** The signed-in user (refreshed if due), or `null`. */\n\toidcUser(request: Request): Promise<OidcUser | null>;\n\t/** Like `oidcUser`, but throws a redirect to the sign-in route (with a safe `next`) when there is none. */\n\trequireOidcUser(request: Request): Promise<OidcUser>;\n\t/** Clears the token cookie (after revoking the tokens with `revokeOnLogout`) and redirects to the issuer's `end_session_endpoint` (with `id_token_hint`), else to `postLogoutRedirectUri` or `/`. Call it from an action. */\n\tlogout(request: Request): Promise<Response>;\n\t/** The cookie names as sent, prefixes included. */\n\treadonly names: { readonly session: string; readonly challenge: string };\n}\n\ninterface Flow {\n\treadonly state: string;\n\treadonly nonce: string;\n\treadonly verifier: string;\n\treadonly next: string;\n\treadonly exp: number;\n\treadonly dpop?: DpopKey | undefined;\n}\n\ninterface Stored {\n\treadonly idToken: string;\n\treadonly accessToken: string;\n\treadonly refreshToken?: string | undefined;\n\treadonly expiresAt: number;\n\treadonly dpop?: DpopKey | undefined;\n}\n\nconst DEFAULT_ALGORITHMS = ['RS256', 'PS256', 'ES256', 'EdDSA'];\nconst CHALLENGE_SECONDS = 600;\nconst SAME_FLIGHT_MS = 10_000;\n\nconst isFlow = (value: unknown): value is Flow =>\n\ttypeof value === 'object' &&\n\tvalue !== null &&\n\t['state', 'nonce', 'verifier', 'next'].every(\n\t\t(key) => typeof (value as Record<string, unknown>)[key] === 'string',\n\t) &&\n\ttypeof (value as Record<string, unknown>)['exp'] === 'number' &&\n\t((value as Record<string, unknown>)['dpop'] === undefined ||\n\t\tisKey((value as Record<string, unknown>)['dpop']));\n\nconst isKey = (value: unknown): value is DpopKey =>\n\ttypeof value === 'object' &&\n\tvalue !== null &&\n\t['ES256', 'EdDSA'].includes(\n\t\t(value as Record<string, unknown>)['alg'] as string,\n\t) &&\n\ttypeof (value as Record<string, unknown>)['jwk'] === 'object';\n\nconst isStored = (value: unknown): value is Stored =>\n\ttypeof value === 'object' &&\n\tvalue !== null &&\n\ttypeof (value as Record<string, unknown>)['idToken'] === 'string' &&\n\ttypeof (value as Record<string, unknown>)['accessToken'] === 'string' &&\n\ttypeof (value as Record<string, unknown>)['expiresAt'] === 'number' &&\n\t((value as Record<string, unknown>)['dpop'] === undefined ||\n\t\tisKey((value as Record<string, unknown>)['dpop']));\n\n/**\n * A BFF as the relying party of an external OpenID Connect issuer:\n * authorization code with PKCE (S256), state and nonce in a short-lived\n * `__Host-` challenge cookie, discovery (cached), the code exchange, the id\n * token validated against the issuer's keys (`jose`, an optional peer), the\n * tokens in a sealed `__Host-` cookie, a single-flight refresh and\n * RP-initiated logout.\n *\n * @example\n * export const oidc = oidcClient({\n * issuer: 'https://id.example.com',\n * clientId: 'my-app',\n * clientSecret: process.env.OIDC_CLIENT_SECRET,\n * redirectUri: 'https://app.example.com/auth/callback',\n * scopes: ['openid', 'profile', 'email', 'offline_access'],\n * secret: process.env.SESSION_SECRET!,\n * name: 'my-app_oidc',\n * secure: !import.meta.env.DEV,\n * });\n * // routes/auth.callback.ts: export const loader = ({ request }) => oidc.callback(request);\n * // any loader: const { claims, headers } = await oidc.requireOidcUser(request);\n */\nexport function oidcClient(options: OidcOptions): OidcClient {\n\tconst {\n\t\tissuer,\n\t\tclientId,\n\t\tclientSecret,\n\t\tredirectUri,\n\t\tsecret,\n\t\tsignInPath = '/sign-in',\n\t\tsessionSeconds = 30 * 24 * 3600,\n\t\trefreshSkewSeconds = 60,\n\t\tclockToleranceSeconds = 30,\n\t} = options;\n\tfor (const [label, value] of [\n\t\t['issuer', issuer],\n\t\t['clientId', clientId],\n\t\t['redirectUri', redirectUri],\n\t] as const) {\n\t\tif (!value) throw new TypeError(`oidcClient(): ${label} is required.`);\n\t}\n\tif (typeof secret !== 'string' || secret.length < 32) {\n\t\tthrow new TypeError(\n\t\t\t'oidcClient(): secret must be a string of at least 32 characters.',\n\t\t);\n\t}\n\t// Client credentials travel by the client's authentication method, never as extras.\n\tconst {\n\t\tclient_id: _id,\n\t\tclient_secret: _secret,\n\t\t...extraTokenParams\n\t} = options.tokenParams ?? {};\n\tconst now = options.now ?? Date.now;\n\tconst scopes = [\n\t\t...new Set(['openid', ...(options.scopes ?? ['profile', 'email'])]),\n\t];\n\tconst cookies = sessionCookies({\n\t\tsession: options.name,\n\t\tchallenge: `${options.name}_flow`,\n\t\tchallengePath: '/',\n\t\tchallengeHostPrefix: true,\n\t\tchallengeSeconds: CHALLENGE_SECONDS,\n\t\tsecure: options.secure,\n\t\tsameSite: 'lax',\n\t});\n\tconst flowSeal = sealer(secret, 'flow');\n\tconst tokenSeal = sealer(secret, 'tokens');\n\tconst issuerApi = issuerClient({\n\t\tissuer,\n\t\tfetch: options.fetch ?? ((input, init) => fetch(input, init)),\n\t\tnow,\n\t\talgorithms: [...(options.algorithms ?? DEFAULT_ALGORITHMS)],\n\t\tclockToleranceSeconds,\n\t});\n\tconst fetcher: Fetcher =\n\t\toptions.fetch ?? ((input, init) => fetch(input, init));\n\tconst client = { id: clientId, secret: clientSecret };\n\tconst par = options.par ?? 'auto';\n\tif (!['auto', 'always', 'never'].includes(par)) {\n\t\tthrow new TypeError(\n\t\t\t\"oidcClient(): par must be 'auto', 'always' or 'never'.\",\n\t\t);\n\t}\n\tconst dpopAlg = options.dpop ? (options.dpop.alg ?? 'ES256') : undefined;\n\tif (dpopAlg !== undefined && !['ES256', 'EdDSA'].includes(dpopAlg)) {\n\t\tthrow new TypeError(\"oidcClient(): dpop.alg must be 'ES256' or 'EdDSA'.\");\n\t}\n\tif (\n\t\toptions.revokeTimeoutMs !== undefined &&\n\t\t!(Number.isFinite(options.revokeTimeoutMs) && options.revokeTimeoutMs > 0)\n\t) {\n\t\tthrow new TypeError(\n\t\t\t'oidcClient(): revokeTimeoutMs must be a positive finite number of milliseconds.',\n\t\t);\n\t}\n\tconst nonces = nonceMemory();\n\tconst signing = (key: DpopKey | undefined) =>\n\t\tkey ? { key, nonces, now } : undefined;\n\n\tconst flights = new Map<string, Promise<Stored>>();\n\n\tconst setCookie = (headers: Headers, value: string) =>\n\t\theaders.append('Set-Cookie', value);\n\n\tasync function toStored(\n\t\tresponse: TokenResponse,\n\t\tnonce: string | undefined,\n\t\tprevious?: Stored,\n\t\tkey?: DpopKey,\n\t): Promise<{ stored: Stored; claims: JWTPayload }> {\n\t\t// Only a token the issuer says is DPoP-bound keeps the key.\n\t\tconst dpop =\n\t\t\tkey &&\n\t\t\t(String(response.token_type).toLowerCase() === 'dpop' ||\n\t\t\t\t(previous?.dpop !== undefined && response.token_type === undefined))\n\t\t\t\t? key\n\t\t\t\t: undefined;\n\t\tif (!response.id_token && previous) {\n\t\t\t// A refresh may omit the id token (OIDC Core 12.2): keep the one verified\n\t\t\t// at sign-in, in the sealed cookie, though it has expired since.\n\t\t\tconst kept = decodeJwt(previous.idToken);\n\t\t\treturn {\n\t\t\t\tclaims: kept,\n\t\t\t\tstored: {\n\t\t\t\t\tidToken: previous.idToken,\n\t\t\t\t\tdpop,\n\t\t\t\t\taccessToken: response.access_token,\n\t\t\t\t\trefreshToken: response.refresh_token ?? previous.refreshToken,\n\t\t\t\t\texpiresAt:\n\t\t\t\t\t\ttypeof response.expires_in === 'number'\n\t\t\t\t\t\t\t? now() + response.expires_in * 1000\n\t\t\t\t\t\t\t: now() + 300_000,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tconst idToken = response.id_token;\n\t\tif (!idToken) {\n\t\t\tthrow new OidcError(\n\t\t\t\t'invalid-id-token',\n\t\t\t\t'The token endpoint sent no id token.',\n\t\t\t);\n\t\t}\n\t\tconst claims = await issuerApi.verifyIdToken(idToken, clientId, nonce);\n\t\tif (previous && decodeJwt(previous.idToken).sub !== claims.sub) {\n\t\t\tthrow new OidcError('invalid-id-token', 'A refresh changed the user.');\n\t\t}\n\t\tconst expiresAt =\n\t\t\ttypeof response.expires_in === 'number'\n\t\t\t\t? now() + response.expires_in * 1000\n\t\t\t\t: (claims['exp'] ?? 0) * 1000;\n\t\treturn {\n\t\t\tclaims,\n\t\t\tstored: {\n\t\t\t\tidToken,\n\t\t\t\tdpop,\n\t\t\t\taccessToken: response.access_token,\n\t\t\t\trefreshToken: response.refresh_token ?? previous?.refreshToken,\n\t\t\t\texpiresAt,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync function commit(headers: Headers, stored: Stored): Promise<void> {\n\t\tconst lifetime = stored.refreshToken\n\t\t\t? sessionSeconds\n\t\t\t: Math.max(0, (stored.expiresAt - now()) / 1000);\n\t\tconst cookie = cookies.commit(\n\t\t\tawait tokenSeal.seal(stored),\n\t\t\tnew Date(now() + lifetime * 1000),\n\t\t\tnow(),\n\t\t);\n\t\t// A browser silently drops a cookie over 4096 bytes: fail loudly instead.\n\t\tif (cookie.length > 4096) {\n\t\t\tthrow new OidcError(\n\t\t\t\t'token-cookie-too-large',\n\t\t\t\t`The token cookie is ${cookie.length} bytes, over the 4096 a browser keeps. Ask the issuer for fewer claims or a shorter access token.`,\n\t\t\t);\n\t\t}\n\t\tsetCookie(headers, cookie);\n\t}\n\n\tconst toSignIn = (request: Request, headers: Headers): never => {\n\t\tconst url = new URL(request.url);\n\t\tconst next = safeNext(`${url.pathname}${url.search}`);\n\t\tconst target = new URL(signInPath, url);\n\t\ttarget.searchParams.set('next', next);\n\t\tthrow redirect(`${target.pathname}${target.search}`, { headers });\n\t};\n\n\tfunction refreshing(stored: Stored): Promise<Stored> {\n\t\tconst key = stored.refreshToken as string;\n\t\tconst flying = flights.get(key);\n\t\tif (flying) return flying;\n\t\tconst flight = (async () => {\n\t\t\tconst document = await issuerApi.discover();\n\t\t\tconst answer = await tokenRequest(\n\t\t\t\tfetcher,\n\t\t\t\tdocument.token_endpoint,\n\t\t\t\tclient,\n\t\t\t\t{\n\t\t\t\t\t...extraTokenParams,\n\t\t\t\t\tgrant_type: 'refresh_token',\n\t\t\t\t\trefresh_token: key,\n\t\t\t\t\tscope: scopes.join(' '),\n\t\t\t\t},\n\t\t\t\t'refresh-failed',\n\t\t\t\tsigning(stored.dpop),\n\t\t\t);\n\t\t\treturn (await toStored(answer, undefined, stored, stored.dpop)).stored;\n\t\t})();\n\t\tflights.set(key, flight);\n\t\t// Rotation: parallel requests still carry the spent refresh token for a moment.\n\t\tconst forget = () => setTimeout(() => flights.delete(key), SAME_FLIGHT_MS);\n\t\tflight.then(forget, () => flights.delete(key));\n\t\treturn flight;\n\t}\n\n\tasync function oidcUser(request: Request): Promise<OidcUser | null> {\n\t\tconst headers = new Headers();\n\t\tconst sealed = cookies.token(request);\n\t\tif (!sealed) return null;\n\t\tconst opened = await tokenSeal.open(sealed);\n\t\tif (!isStored(opened)) {\n\t\t\tsetCookie(headers, cookies.destroy());\n\t\t\treturn null;\n\t\t}\n\t\tlet stored: Stored = opened;\n\t\tif (stored.expiresAt - refreshSkewSeconds * 1000 <= now()) {\n\t\t\ttry {\n\t\t\t\tif (!stored.refreshToken) throw new Error('no refresh token');\n\t\t\t\tstored = await refreshing(stored);\n\t\t\t\tawait commit(headers, stored);\n\t\t\t} catch {\n\t\t\t\t// A transient failure keeps a still-valid access token going.\n\t\t\t\tif (stored.expiresAt <= now()) return null;\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tclaims: decodeJwt(stored.idToken),\n\t\t\taccessToken: stored.accessToken,\n\t\t\tidToken: stored.idToken,\n\t\t\texpiresAt: stored.expiresAt,\n\t\t\theaders,\n\t\t\tdpop: stored.dpop\n\t\t\t\t? dpopBinding({\n\t\t\t\t\t\tkey: stored.dpop,\n\t\t\t\t\t\tthumbprint: await dpopThumbprint(stored.dpop),\n\t\t\t\t\t\taccessToken: stored.accessToken,\n\t\t\t\t\t\tnonces,\n\t\t\t\t\t\tfetch: fetcher,\n\t\t\t\t\t\tnow,\n\t\t\t\t\t})\n\t\t\t\t: null,\n\t\t};\n\t}\n\n\treturn {\n\t\tnames: cookies.names,\n\t\toidcUser,\n\t\tasync requireOidcUser(request) {\n\t\t\tconst user = await oidcUser(request);\n\t\t\tif (user) return user;\n\t\t\tconst headers = new Headers();\n\t\t\tif (cookies.token(request)) setCookie(headers, cookies.destroy());\n\t\t\treturn toSignIn(request, headers);\n\t\t},\n\t\tasync signIn(request) {\n\t\t\tconst document = await issuerApi.discover();\n\t\t\tconst url = new URL(request.url);\n\t\t\tconst flow: Flow = {\n\t\t\t\tstate: randomToken(),\n\t\t\t\tnonce: randomToken(),\n\t\t\t\tverifier: randomToken(48),\n\t\t\t\tnext: safeNext(url.searchParams.get('next')),\n\t\t\t\texp: now() + CHALLENGE_SECONDS * 1000,\n\t\t\t\tdpop: dpopAlg ? await generateDpopKey(dpopAlg) : undefined,\n\t\t\t};\n\t\t\tconst authRequest: Record<string, string> = {\n\t\t\t\t...options.authorizationParams,\n\t\t\t\tresponse_type: 'code',\n\t\t\t\tclient_id: clientId,\n\t\t\t\tredirect_uri: redirectUri,\n\t\t\t\tscope: scopes.join(' '),\n\t\t\t\tstate: flow.state,\n\t\t\t\tnonce: flow.nonce,\n\t\t\t\tcode_challenge: await s256(flow.verifier),\n\t\t\t\tcode_challenge_method: 'S256',\n\t\t\t\t...(flow.dpop && { dpop_jkt: await dpopThumbprint(flow.dpop) }),\n\t\t\t};\n\t\t\tconst endpoint = document.pushed_authorization_request_endpoint;\n\t\t\tconst push =\n\t\t\t\tpar === 'always' ||\n\t\t\t\t(par === 'auto' &&\n\t\t\t\t\tdocument.require_pushed_authorization_requests === true);\n\t\t\tconst target = new URL(document.authorization_endpoint);\n\t\t\tif (push) {\n\t\t\t\tif (!endpoint) {\n\t\t\t\t\tthrow new OidcError(\n\t\t\t\t\t\t'par-failed',\n\t\t\t\t\t\t'Pushed authorization requests are required but the issuer publishes no pushed_authorization_request_endpoint.',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst requestUri = await pushRequest(\n\t\t\t\t\tfetcher,\n\t\t\t\t\tendpoint,\n\t\t\t\t\tclient,\n\t\t\t\t\tauthRequest,\n\t\t\t\t\tsigning(flow.dpop),\n\t\t\t\t);\n\t\t\t\ttarget.searchParams.set('client_id', clientId);\n\t\t\t\ttarget.searchParams.set('request_uri', requestUri);\n\t\t\t} else {\n\t\t\t\tfor (const [key, value] of Object.entries(authRequest)) {\n\t\t\t\t\ttarget.searchParams.set(key, value);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst headers = new Headers({ 'Cache-Control': 'no-store' });\n\t\t\tsetCookie(\n\t\t\t\theaders,\n\t\t\t\tcookies.commitChallenge(await flowSeal.seal(flow), null, now()),\n\t\t\t);\n\t\t\theaders.set('Location', target.toString());\n\t\t\treturn new Response(null, { status: 302, headers });\n\t\t},\n\t\tasync callback(request) {\n\t\t\tconst cleared = () => {\n\t\t\t\tconst headers = new Headers();\n\t\t\t\tsetCookie(headers, cookies.destroyChallenge());\n\t\t\t\treturn headers;\n\t\t\t};\n\t\t\tconst fail = (\n\t\t\t\tcode: ConstructorParameters<typeof OidcError>[0],\n\t\t\t\tmessage: string,\n\t\t\t) => new OidcError(code, message, cleared());\n\t\t\tconst url = new URL(request.url);\n\t\t\tconst sealed = cookies.challengeOf(request);\n\t\t\tconst flow = sealed ? await flowSeal.open(sealed) : null;\n\t\t\tif (!isFlow(flow)) {\n\t\t\t\tthrow fail(\n\t\t\t\t\t'missing-challenge',\n\t\t\t\t\t'The sign-in challenge cookie is missing or unreadable (a second tab, an expired page or a blocked cookie).',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (flow.exp <= now()) {\n\t\t\t\tthrow fail(\n\t\t\t\t\t'challenge-expired',\n\t\t\t\t\t'The sign-in took too long; start again.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst returned = url.searchParams.get('state');\n\t\t\tif (returned === null || !sameText(returned, flow.state)) {\n\t\t\t\tthrow fail(\n\t\t\t\t\t'state-mismatch',\n\t\t\t\t\t'The returned state is not the one this sign-in sent.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst failure = url.searchParams.get('error');\n\t\t\tif (failure) {\n\t\t\t\tconst description = url.searchParams.get('error_description');\n\t\t\t\tthrow fail(\n\t\t\t\t\t'provider-error',\n\t\t\t\t\t`The issuer refused: ${failure}${description ? ` (${description})` : ''}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst claimedIssuer = url.searchParams.get('iss');\n\t\t\tif (claimedIssuer !== null && claimedIssuer !== issuer) {\n\t\t\t\tthrow fail('issuer-mismatch', 'The callback names another issuer.');\n\t\t\t}\n\t\t\tconst code = url.searchParams.get('code');\n\t\t\tif (!code) throw fail('missing-code', 'The callback carries no code.');\n\t\t\ttry {\n\t\t\t\tconst document = await issuerApi.discover();\n\t\t\t\tconst answer = await tokenRequest(\n\t\t\t\t\tfetcher,\n\t\t\t\t\tdocument.token_endpoint,\n\t\t\t\t\tclient,\n\t\t\t\t\t{\n\t\t\t\t\t\t...extraTokenParams,\n\t\t\t\t\t\tgrant_type: 'authorization_code',\n\t\t\t\t\t\tcode,\n\t\t\t\t\t\tredirect_uri: redirectUri,\n\t\t\t\t\t\tcode_verifier: flow.verifier,\n\t\t\t\t\t},\n\t\t\t\t\t'token-exchange-failed',\n\t\t\t\t\tsigning(flow.dpop),\n\t\t\t\t);\n\t\t\t\tconst { stored } = await toStored(\n\t\t\t\t\tanswer,\n\t\t\t\t\tflow.nonce,\n\t\t\t\t\tundefined,\n\t\t\t\t\tflow.dpop,\n\t\t\t\t);\n\t\t\t\tconst headers = cleared();\n\t\t\t\tawait commit(headers, stored);\n\t\t\t\theaders.set('Location', safeNext(flow.next));\n\t\t\t\theaders.set('Cache-Control', 'no-store');\n\t\t\t\treturn new Response(null, { status: 302, headers });\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof OidcError) {\n\t\t\t\t\tfor (const value of cleared().getSetCookie()) {\n\t\t\t\t\t\terror.headers.append('Set-Cookie', value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tasync logout(request) {\n\t\t\tconst report = (error: OidcError): void => {\n\t\t\t\ttry {\n\t\t\t\t\toptions.onRevokeError?.(error);\n\t\t\t\t} catch {\n\t\t\t\t\t// A failing hook never blocks the logout.\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst headers = new Headers({ 'Cache-Control': 'no-store' });\n\t\t\tsetCookie(headers, cookies.destroy());\n\t\t\tconst sealed = cookies.token(request);\n\t\t\tconst opened = sealed ? await tokenSeal.open(sealed) : null;\n\t\t\tconst document = await issuerApi.discover().catch((cause) => {\n\t\t\t\tif (options.revokeOnLogout) {\n\t\t\t\t\treport(\n\t\t\t\t\t\tnew OidcError(\n\t\t\t\t\t\t\t'discovery-failed',\n\t\t\t\t\t\t\t'Discovery failed at logout, so the tokens were not revoked.',\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t{ cause },\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn null;\n\t\t\t});\n\t\t\tif (\n\t\t\t\toptions.revokeOnLogout &&\n\t\t\t\tdocument?.revocation_endpoint &&\n\t\t\t\tisStored(opened)\n\t\t\t) {\n\t\t\t\tawait revokeTokens({\n\t\t\t\t\tfetcher,\n\t\t\t\t\tclient,\n\t\t\t\t\tendpoint: document.revocation_endpoint,\n\t\t\t\t\tstored: opened,\n\t\t\t\t\tsigning,\n\t\t\t\t\ttimeoutMs: options.revokeTimeoutMs ?? 3000,\n\t\t\t\t\treport,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst endpoint = document?.end_session_endpoint;\n\t\t\tif (!endpoint) {\n\t\t\t\theaders.set('Location', options.postLogoutRedirectUri ?? '/');\n\t\t\t\treturn new Response(null, { status: 302, headers });\n\t\t\t}\n\t\t\tconst target = new URL(endpoint);\n\t\t\tif (isStored(opened))\n\t\t\t\ttarget.searchParams.set('id_token_hint', opened.idToken);\n\t\t\ttarget.searchParams.set('client_id', clientId);\n\t\t\tif (options.postLogoutRedirectUri) {\n\t\t\t\ttarget.searchParams.set(\n\t\t\t\t\t'post_logout_redirect_uri',\n\t\t\t\t\toptions.postLogoutRedirectUri,\n\t\t\t\t);\n\t\t\t}\n\t\t\theaders.set('Location', target.toString());\n\t\t\treturn new Response(null, { status: 302, headers });\n\t\t},\n\t};\n}\n",
|
|
10
|
+
"import type { JWTPayload } from 'jose';\nimport { redirect } from 'react-router';\nimport { sessionCookies } from '../session/cookies';\nimport { safeNext } from '../session/model/safe-next';\nimport {\n\ttype DpopAlgorithm,\n\ttype DpopBinding,\n\ttype DpopKey,\n\tdpopBinding,\n\tdpopThumbprint,\n\tgenerateDpopKey,\n\tnonceMemory,\n} from './dpop';\nimport { OidcError } from './errors';\nimport {\n\tdecodeJwt,\n\ttype Fetcher,\n\tissuerClient,\n\tpushRequest,\n\ttype TokenResponse,\n\ttokenRequest,\n} from './flow';\nimport { revokeTokens } from './revoke';\nimport { randomToken, s256, sameText, sealer } from './seal';\n\n/** What `oidcClient` takes. */\nexport interface OidcOptions {\n\t/** The issuer's identifier, exactly as its discovery document names it (no trailing slash needed). */\n\treadonly issuer: string;\n\treadonly clientId: string;\n\t/** The secret of a confidential client, sent as `client_secret_basic`. Omit it for a public client. */\n\treadonly clientSecret?: string | undefined;\n\t/** The absolute URL of the route that calls `callback`; registered with the issuer. */\n\treadonly redirectUri: string;\n\t/** `['openid', 'profile', 'email']` by default; `openid` is always sent. Add `offline_access` for a refresh token. */\n\treadonly scopes?: readonly string[] | undefined;\n\t/** Seals the cookies (AES-256-GCM): at least 32 characters, from the environment, never committed. Changing it signs everyone out. */\n\treadonly secret: string;\n\t/** The base name of the cookies, e.g. `'my-app_oidc'`; `__Host-` is added when `secure`. */\n\treadonly name: string;\n\t/** The app is served over HTTPS. Required, never read from the environment: pass `!import.meta.env.DEV`. */\n\treadonly secure: boolean;\n\t/** The route that starts the sign-in (it calls `signIn`). `'/sign-in'` by default. */\n\treadonly signInPath?: string | undefined;\n\t/** Where the issuer sends the browser after `logout`; it must be registered with the issuer. */\n\treadonly postLogoutRedirectUri?: string | undefined;\n\t/** How long the token cookie lives when there is a refresh token. 30 days by default; otherwise it ends with the access token. */\n\treadonly sessionSeconds?: number | undefined;\n\t/** Refresh when the access token ends within this many seconds. 60 by default. */\n\treadonly refreshSkewSeconds?: number | undefined;\n\t/** How long, in ms, parallel refreshes with one refresh token share one flight, so a rotating issuer sees it once. 10000 by default; from 0 to 2147483647, and well under the access token's lifetime. */\n\treadonly refreshFlightMs?: number | undefined;\n\t/** Clock difference accepted on `exp` and `iat`. 30 by default. */\n\treadonly clockToleranceSeconds?: number | undefined;\n\t/** Id token signature algorithms accepted. `RS256`, `PS256`, `ES256` and `EdDSA` by default. */\n\treadonly algorithms?: readonly string[] | undefined;\n\t/** Extra parameters of the authorization request, e.g. `{ prompt: 'login' }`. */\n\treadonly authorizationParams?: Readonly<Record<string, string>> | undefined;\n\t/**\n\t * Extra parameters of the token request, sent on the code exchange and on every refresh,\n\t * e.g. `{ resource: 'https://api.example' }` (RFC 8707). The parameters the flow owns\n\t * (`grant_type`, `code`, `redirect_uri`, `code_verifier`, `refresh_token`, `scope`) win over these, and `client_id` and `client_secret` are ignored.\n\t */\n\treadonly tokenParams?: Readonly<Record<string, string>> | undefined;\n\t/**\n\t * Pushed authorization requests (RFC 9126): the authorization request is POSTed to the issuer's\n\t * `pushed_authorization_request_endpoint` with the client's authentication, and the browser is\n\t * redirected with `client_id` and `request_uri` alone.\n\t * `'auto'` (default) pushes when discovery says `require_pushed_authorization_requests: true`;\n\t * `'always'` pushes whatever discovery says (and fails with `par-failed` without an endpoint);\n\t * `'never'` always sends the parameters in the redirect.\n\t */\n\treadonly par?: 'auto' | 'always' | 'never' | undefined;\n\t/**\n\t * Binds the tokens to a key with DPoP (RFC 9449). Off by default. A key pair per sign-in\n\t * (`ES256` by default, or `EdDSA`) is made at `signIn` and kept in the sealed cookies with the\n\t * session; the token endpoint (code and refresh) gets a proof, a `use_dpop_nonce` answer is\n\t * retried once with the nonce sent, and `OidcUser.dpop` signs the proofs of calls to a resource.\n\t */\n\treadonly dpop?: { readonly alg?: DpopAlgorithm | undefined } | undefined;\n\t/**\n\t * Revoke the refresh token and the access token at `logout` (RFC 7009). Off by default.\n\t * When on and discovery has a `revocation_endpoint`, `logout` POSTs the refresh token\n\t * (`token_type_hint=refresh_token`) then the access token (`token_type_hint=access_token`),\n\t * with the client's authentication and the DPoP proof of the token endpoint. A failure\n\t * (network error, non-2xx) never blocks the logout: the cookie is cleared and the redirect\n\t * sent, and the failure goes to `onRevokeError`.\n\t */\n\treadonly revokeOnLogout?: boolean | undefined;\n\t/** The most `logout` waits for the revocations, in ms, both together. 3000 by default. A stalled endpoint is aborted and reported as `revoke-failed`; the sign-out goes on. */\n\treadonly revokeTimeoutMs?: number | undefined;\n\t/** Called with each revocation failure at `logout` (an `OidcError` with code `revoke-failed`, or `discovery-failed`). Nothing by default. */\n\treadonly onRevokeError?: ((error: OidcError) => void) | undefined;\n\t/** The `fetch` used for discovery, the keys and the token endpoint; global `fetch` by default. */\n\treadonly fetch?: Fetcher | undefined;\n\t/** The clock, in ms; `Date.now` by default. */\n\treadonly now?: (() => number) | undefined;\n}\n\n/** The signed-in user a loader reads. */\nexport interface OidcUser {\n\t/** The id token's claims. */\n\treadonly claims: JWTPayload;\n\treadonly accessToken: string;\n\treadonly idToken: string;\n\t/** When the access token ends, in ms. */\n\treadonly expiresAt: number;\n\t/** `Set-Cookie` when the tokens were refreshed, else empty: pass it with the loader's answer. */\n\treadonly headers: Headers;\n\t/** Signs the proofs of calls to a resource when the tokens are DPoP-bound (`dpop` option, and the issuer sent `token_type: DPoP`), else `null`. */\n\treadonly dpop: DpopBinding | null;\n\t/** The `fetch` the client was given (global `fetch` by default): `dpopFetch` sends a bearer call through it. */\n\treadonly fetch: Fetcher;\n}\n\n/** The relying party `oidcClient` returns. */\nexport interface OidcClient {\n\t/** The route action or loader that starts the sign-in: a redirect to the issuer. `?next=` is kept, through `safeNext`. */\n\tsignIn(request: Request): Promise<Response>;\n\t/** The redirect route: checks state, exchanges the code, validates the id token, sets the token cookie and redirects to `next`. Throws `OidcError`. */\n\tcallback(request: Request): Promise<Response>;\n\t/** The signed-in user (refreshed if due), or `null`. */\n\toidcUser(request: Request): Promise<OidcUser | null>;\n\t/**\n\t * Refreshes `user` from its own tokens (not the request's cookie, which a rotation\n\t * leaves behind) when its access token ends within `refreshSkewSeconds`, and returns\n\t * the new user, whose `headers` hold the `Set-Cookie` to send; `user` itself when\n\t * nothing is due, or with `{ force: true }` always. A forced refresh inside the\n\t * flight window of `refreshFlightMs` shares that flight's tokens; with no refresh\n\t * token it returns `user` while its access token is valid. A refresh that fails\n\t * throws `OidcError` (`refresh-failed`) when the access token has ended, else\n\t * returns `user`. Only a user this client returned can be refreshed (else\n\t * `TypeError`).\n\t */\n\trefresh(\n\t\tuser: OidcUser,\n\t\toptions?: { readonly force?: boolean | undefined },\n\t): Promise<OidcUser>;\n\t/** Like `oidcUser`, but throws a redirect to the sign-in route (with a safe `next`) when there is none. */\n\trequireOidcUser(request: Request): Promise<OidcUser>;\n\t/** Clears the token cookie (after revoking the tokens with `revokeOnLogout`) and redirects to the issuer's `end_session_endpoint` (with `id_token_hint`), else to `postLogoutRedirectUri` or `/`. Call it from an action. */\n\tlogout(request: Request): Promise<Response>;\n\t/** The cookie names as sent, prefixes included. */\n\treadonly names: { readonly session: string; readonly challenge: string };\n}\n\ninterface Flow {\n\treadonly state: string;\n\treadonly nonce: string;\n\treadonly verifier: string;\n\treadonly next: string;\n\treadonly exp: number;\n\treadonly dpop?: DpopKey | undefined;\n}\n\ninterface Stored {\n\treadonly idToken: string;\n\treadonly accessToken: string;\n\treadonly refreshToken?: string | undefined;\n\treadonly expiresAt: number;\n\treadonly dpop?: DpopKey | undefined;\n}\n\nconst DEFAULT_ALGORITHMS = ['RS256', 'PS256', 'ES256', 'EdDSA'];\nconst CHALLENGE_SECONDS = 600;\nconst MAX_TIMER_MS = 2_147_483_647;\n\nconst isFlow = (value: unknown): value is Flow =>\n\ttypeof value === 'object' &&\n\tvalue !== null &&\n\t['state', 'nonce', 'verifier', 'next'].every(\n\t\t(key) => typeof (value as Record<string, unknown>)[key] === 'string',\n\t) &&\n\ttypeof (value as Record<string, unknown>)['exp'] === 'number' &&\n\t((value as Record<string, unknown>)['dpop'] === undefined ||\n\t\tisKey((value as Record<string, unknown>)['dpop']));\n\nconst isKey = (value: unknown): value is DpopKey =>\n\ttypeof value === 'object' &&\n\tvalue !== null &&\n\t['ES256', 'EdDSA'].includes(\n\t\t(value as Record<string, unknown>)['alg'] as string,\n\t) &&\n\ttypeof (value as Record<string, unknown>)['jwk'] === 'object';\n\nconst isStored = (value: unknown): value is Stored =>\n\ttypeof value === 'object' &&\n\tvalue !== null &&\n\ttypeof (value as Record<string, unknown>)['idToken'] === 'string' &&\n\ttypeof (value as Record<string, unknown>)['accessToken'] === 'string' &&\n\ttypeof (value as Record<string, unknown>)['expiresAt'] === 'number' &&\n\t((value as Record<string, unknown>)['dpop'] === undefined ||\n\t\tisKey((value as Record<string, unknown>)['dpop']));\n\n/**\n * A BFF as the relying party of an external OpenID Connect issuer:\n * authorization code with PKCE (S256), state and nonce in a short-lived\n * `__Host-` challenge cookie, discovery (cached), the code exchange, the id\n * token validated against the issuer's keys (`jose`, an optional peer), the\n * tokens in a sealed `__Host-` cookie, a single-flight refresh and\n * RP-initiated logout.\n *\n * @example\n * export const oidc = oidcClient({\n * issuer: 'https://id.example.com',\n * clientId: 'my-app',\n * clientSecret: process.env.OIDC_CLIENT_SECRET,\n * redirectUri: 'https://app.example.com/auth/callback',\n * scopes: ['openid', 'profile', 'email', 'offline_access'],\n * secret: process.env.SESSION_SECRET!,\n * name: 'my-app_oidc',\n * secure: !import.meta.env.DEV,\n * });\n * // routes/auth.callback.ts: export const loader = ({ request }) => oidc.callback(request);\n * // any loader: const { claims, headers } = await oidc.requireOidcUser(request);\n */\nexport function oidcClient(options: OidcOptions): OidcClient {\n\tconst {\n\t\tissuer,\n\t\tclientId,\n\t\tclientSecret,\n\t\tredirectUri,\n\t\tsecret,\n\t\tsignInPath = '/sign-in',\n\t\tsessionSeconds = 30 * 24 * 3600,\n\t\trefreshSkewSeconds = 60,\n\t\trefreshFlightMs = 10_000,\n\t\tclockToleranceSeconds = 30,\n\t} = options;\n\tfor (const [label, value] of [\n\t\t['issuer', issuer],\n\t\t['clientId', clientId],\n\t\t['redirectUri', redirectUri],\n\t] as const) {\n\t\tif (!value) throw new TypeError(`oidcClient(): ${label} is required.`);\n\t}\n\tif (typeof secret !== 'string' || secret.length < 32) {\n\t\tthrow new TypeError(\n\t\t\t'oidcClient(): secret must be a string of at least 32 characters.',\n\t\t);\n\t}\n\t// Client credentials travel by the client's authentication method, never as extras.\n\tconst {\n\t\tclient_id: _id,\n\t\tclient_secret: _secret,\n\t\t...extraTokenParams\n\t} = options.tokenParams ?? {};\n\tconst now = options.now ?? Date.now;\n\tconst scopes = [\n\t\t...new Set(['openid', ...(options.scopes ?? ['profile', 'email'])]),\n\t];\n\tconst cookies = sessionCookies({\n\t\tsession: options.name,\n\t\tchallenge: `${options.name}_flow`,\n\t\tchallengePath: '/',\n\t\tchallengeHostPrefix: true,\n\t\tchallengeSeconds: CHALLENGE_SECONDS,\n\t\tsecure: options.secure,\n\t\tsameSite: 'lax',\n\t});\n\tconst flowSeal = sealer(secret, 'flow');\n\tconst tokenSeal = sealer(secret, 'tokens');\n\tconst issuerApi = issuerClient({\n\t\tissuer,\n\t\tfetch: options.fetch ?? ((input, init) => fetch(input, init)),\n\t\tnow,\n\t\talgorithms: [...(options.algorithms ?? DEFAULT_ALGORITHMS)],\n\t\tclockToleranceSeconds,\n\t});\n\tconst fetcher: Fetcher =\n\t\toptions.fetch ?? ((input, init) => fetch(input, init));\n\tconst client = { id: clientId, secret: clientSecret };\n\tconst par = options.par ?? 'auto';\n\tif (!['auto', 'always', 'never'].includes(par)) {\n\t\tthrow new TypeError(\n\t\t\t\"oidcClient(): par must be 'auto', 'always' or 'never'.\",\n\t\t);\n\t}\n\tconst dpopAlg = options.dpop ? (options.dpop.alg ?? 'ES256') : undefined;\n\tif (dpopAlg !== undefined && !['ES256', 'EdDSA'].includes(dpopAlg)) {\n\t\tthrow new TypeError(\"oidcClient(): dpop.alg must be 'ES256' or 'EdDSA'.\");\n\t}\n\tif (\n\t\toptions.revokeTimeoutMs !== undefined &&\n\t\t!(Number.isFinite(options.revokeTimeoutMs) && options.revokeTimeoutMs > 0)\n\t) {\n\t\tthrow new TypeError(\n\t\t\t'oidcClient(): revokeTimeoutMs must be a positive finite number of milliseconds.',\n\t\t);\n\t}\n\tif (\n\t\t!(\n\t\t\tNumber.isFinite(refreshFlightMs) &&\n\t\t\trefreshFlightMs >= 0 &&\n\t\t\trefreshFlightMs <= MAX_TIMER_MS\n\t\t)\n\t) {\n\t\tthrow new TypeError(\n\t\t\t'oidcClient(): refreshFlightMs must be a finite number of milliseconds, from 0 to 2147483647.',\n\t\t);\n\t}\n\tconst nonces = nonceMemory();\n\tconst signing = (key: DpopKey | undefined) =>\n\t\tkey ? { key, nonces, now } : undefined;\n\n\tconst flights = new Map<string, Promise<Stored>>();\n\n\tconst setCookie = (headers: Headers, value: string) =>\n\t\theaders.append('Set-Cookie', value);\n\n\tasync function toStored(\n\t\tresponse: TokenResponse,\n\t\tnonce: string | undefined,\n\t\tprevious?: Stored,\n\t\tkey?: DpopKey,\n\t): Promise<{ stored: Stored; claims: JWTPayload }> {\n\t\t// Only a token the issuer says is DPoP-bound keeps the key.\n\t\tconst dpop =\n\t\t\tkey &&\n\t\t\t(String(response.token_type).toLowerCase() === 'dpop' ||\n\t\t\t\t(previous?.dpop !== undefined && response.token_type === undefined))\n\t\t\t\t? key\n\t\t\t\t: undefined;\n\t\tif (!response.id_token && previous) {\n\t\t\t// A refresh may omit the id token (OIDC Core 12.2): keep the one verified\n\t\t\t// at sign-in, in the sealed cookie, though it has expired since.\n\t\t\tconst kept = decodeJwt(previous.idToken);\n\t\t\treturn {\n\t\t\t\tclaims: kept,\n\t\t\t\tstored: {\n\t\t\t\t\tidToken: previous.idToken,\n\t\t\t\t\tdpop,\n\t\t\t\t\taccessToken: response.access_token,\n\t\t\t\t\trefreshToken: response.refresh_token ?? previous.refreshToken,\n\t\t\t\t\texpiresAt:\n\t\t\t\t\t\ttypeof response.expires_in === 'number'\n\t\t\t\t\t\t\t? now() + response.expires_in * 1000\n\t\t\t\t\t\t\t: now() + 300_000,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tconst idToken = response.id_token;\n\t\tif (!idToken) {\n\t\t\tthrow new OidcError(\n\t\t\t\t'invalid-id-token',\n\t\t\t\t'The token endpoint sent no id token.',\n\t\t\t);\n\t\t}\n\t\tconst claims = await issuerApi.verifyIdToken(idToken, clientId, nonce);\n\t\tif (previous && decodeJwt(previous.idToken).sub !== claims.sub) {\n\t\t\tthrow new OidcError('invalid-id-token', 'A refresh changed the user.');\n\t\t}\n\t\tconst expiresAt =\n\t\t\ttypeof response.expires_in === 'number'\n\t\t\t\t? now() + response.expires_in * 1000\n\t\t\t\t: (claims['exp'] ?? 0) * 1000;\n\t\treturn {\n\t\t\tclaims,\n\t\t\tstored: {\n\t\t\t\tidToken,\n\t\t\t\tdpop,\n\t\t\t\taccessToken: response.access_token,\n\t\t\t\trefreshToken: response.refresh_token ?? previous?.refreshToken,\n\t\t\t\texpiresAt,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync function commit(headers: Headers, stored: Stored): Promise<void> {\n\t\tconst lifetime = stored.refreshToken\n\t\t\t? sessionSeconds\n\t\t\t: Math.max(0, (stored.expiresAt - now()) / 1000);\n\t\tconst cookie = cookies.commit(\n\t\t\tawait tokenSeal.seal(stored),\n\t\t\tnew Date(now() + lifetime * 1000),\n\t\t\tnow(),\n\t\t);\n\t\t// A browser silently drops a cookie over 4096 bytes: fail loudly instead.\n\t\tif (cookie.length > 4096) {\n\t\t\tthrow new OidcError(\n\t\t\t\t'token-cookie-too-large',\n\t\t\t\t`The token cookie is ${cookie.length} bytes, over the 4096 a browser keeps. Ask the issuer for fewer claims or a shorter access token.`,\n\t\t\t);\n\t\t}\n\t\tsetCookie(headers, cookie);\n\t}\n\n\tconst toSignIn = (request: Request, headers: Headers): never => {\n\t\tconst url = new URL(request.url);\n\t\tconst next = safeNext(`${url.pathname}${url.search}`);\n\t\tconst target = new URL(signInPath, url);\n\t\ttarget.searchParams.set('next', next);\n\t\tthrow redirect(`${target.pathname}${target.search}`, { headers });\n\t};\n\n\tfunction refreshing(stored: Stored, key: string): Promise<Stored> {\n\t\tconst flying = flights.get(key);\n\t\tif (flying) return flying;\n\t\tconst flight = (async () => {\n\t\t\tconst document = await issuerApi.discover();\n\t\t\tconst answer = await tokenRequest(\n\t\t\t\tfetcher,\n\t\t\t\tdocument.token_endpoint,\n\t\t\t\tclient,\n\t\t\t\t{\n\t\t\t\t\t...extraTokenParams,\n\t\t\t\t\tgrant_type: 'refresh_token',\n\t\t\t\t\trefresh_token: key,\n\t\t\t\t\tscope: scopes.join(' '),\n\t\t\t\t},\n\t\t\t\t'refresh-failed',\n\t\t\t\tsigning(stored.dpop),\n\t\t\t);\n\t\t\treturn (await toStored(answer, undefined, stored, stored.dpop)).stored;\n\t\t})();\n\t\tflights.set(key, flight);\n\t\t// Rotation: parallel requests still carry the spent refresh token for a moment.\n\t\tconst forget = () => {\n\t\t\tconst timer = setTimeout(() => flights.delete(key), refreshFlightMs);\n\t\t\t// A pending forget never keeps the process alive.\n\t\t\tif (typeof timer === 'object') timer.unref();\n\t\t};\n\t\tflight.then(forget, () => flights.delete(key));\n\t\treturn flight;\n\t}\n\n\tconst stores = new WeakMap<OidcUser, Stored>();\n\n\tasync function toUser(stored: Stored, headers: Headers): Promise<OidcUser> {\n\t\tconst user: OidcUser = {\n\t\t\tclaims: decodeJwt(stored.idToken),\n\t\t\taccessToken: stored.accessToken,\n\t\t\tidToken: stored.idToken,\n\t\t\texpiresAt: stored.expiresAt,\n\t\t\theaders,\n\t\t\tdpop: stored.dpop\n\t\t\t\t? dpopBinding({\n\t\t\t\t\t\tkey: stored.dpop,\n\t\t\t\t\t\tthumbprint: await dpopThumbprint(stored.dpop),\n\t\t\t\t\t\taccessToken: stored.accessToken,\n\t\t\t\t\t\tnonces,\n\t\t\t\t\t\tfetch: fetcher,\n\t\t\t\t\t\tnow,\n\t\t\t\t\t})\n\t\t\t\t: null,\n\t\t\tfetch: fetcher,\n\t\t};\n\t\tstores.set(user, stored);\n\t\treturn user;\n\t}\n\n\tasync function refresh(\n\t\tuser: OidcUser,\n\t\trefreshOptions: { readonly force?: boolean | undefined } = {},\n\t): Promise<OidcUser> {\n\t\tconst stored = stores.get(user);\n\t\tif (!stored) {\n\t\t\tthrow new TypeError(\n\t\t\t\t'oidc.refresh(): the user was not returned by this client.',\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\t!refreshOptions.force &&\n\t\t\tstored.expiresAt - refreshSkewSeconds * 1000 > now()\n\t\t) {\n\t\t\treturn user;\n\t\t}\n\t\tconst headers = new Headers();\n\t\ttry {\n\t\t\tif (!stored.refreshToken) throw new Error('no refresh token');\n\t\t\tconst next = await refreshing(stored, stored.refreshToken);\n\t\t\tawait commit(headers, next);\n\t\t\treturn toUser(next, headers);\n\t\t} catch (cause) {\n\t\t\t// A transient failure keeps a still-valid access token going.\n\t\t\tif (stored.expiresAt > now()) return user;\n\t\t\tthrow cause instanceof OidcError\n\t\t\t\t? cause\n\t\t\t\t: new OidcError('refresh-failed', 'The refresh failed.', undefined, {\n\t\t\t\t\t\tcause,\n\t\t\t\t\t});\n\t\t}\n\t}\n\n\tasync function oidcUser(request: Request): Promise<OidcUser | null> {\n\t\tconst headers = new Headers();\n\t\tconst sealed = cookies.token(request);\n\t\tif (!sealed) return null;\n\t\tconst opened = await tokenSeal.open(sealed);\n\t\tif (!isStored(opened)) {\n\t\t\tsetCookie(headers, cookies.destroy());\n\t\t\treturn null;\n\t\t}\n\t\tlet stored: Stored = opened;\n\t\tif (stored.expiresAt - refreshSkewSeconds * 1000 <= now()) {\n\t\t\ttry {\n\t\t\t\tif (!stored.refreshToken) throw new Error('no refresh token');\n\t\t\t\tstored = await refreshing(stored, stored.refreshToken);\n\t\t\t\tawait commit(headers, stored);\n\t\t\t} catch {\n\t\t\t\t// A transient failure keeps a still-valid access token going.\n\t\t\t\tif (stored.expiresAt <= now()) return null;\n\t\t\t}\n\t\t}\n\t\treturn toUser(stored, headers);\n\t}\n\n\treturn {\n\t\tnames: cookies.names,\n\t\toidcUser,\n\t\trefresh,\n\t\tasync requireOidcUser(request) {\n\t\t\tconst user = await oidcUser(request);\n\t\t\tif (user) return user;\n\t\t\tconst headers = new Headers();\n\t\t\tif (cookies.token(request)) setCookie(headers, cookies.destroy());\n\t\t\treturn toSignIn(request, headers);\n\t\t},\n\t\tasync signIn(request) {\n\t\t\tconst document = await issuerApi.discover();\n\t\t\tconst url = new URL(request.url);\n\t\t\tconst flow: Flow = {\n\t\t\t\tstate: randomToken(),\n\t\t\t\tnonce: randomToken(),\n\t\t\t\tverifier: randomToken(48),\n\t\t\t\tnext: safeNext(url.searchParams.get('next')),\n\t\t\t\texp: now() + CHALLENGE_SECONDS * 1000,\n\t\t\t\tdpop: dpopAlg ? await generateDpopKey(dpopAlg) : undefined,\n\t\t\t};\n\t\t\tconst authRequest: Record<string, string> = {\n\t\t\t\t...options.authorizationParams,\n\t\t\t\tresponse_type: 'code',\n\t\t\t\tclient_id: clientId,\n\t\t\t\tredirect_uri: redirectUri,\n\t\t\t\tscope: scopes.join(' '),\n\t\t\t\tstate: flow.state,\n\t\t\t\tnonce: flow.nonce,\n\t\t\t\tcode_challenge: await s256(flow.verifier),\n\t\t\t\tcode_challenge_method: 'S256',\n\t\t\t\t...(flow.dpop && { dpop_jkt: await dpopThumbprint(flow.dpop) }),\n\t\t\t};\n\t\t\tconst endpoint = document.pushed_authorization_request_endpoint;\n\t\t\tconst push =\n\t\t\t\tpar === 'always' ||\n\t\t\t\t(par === 'auto' &&\n\t\t\t\t\tdocument.require_pushed_authorization_requests === true);\n\t\t\tconst target = new URL(document.authorization_endpoint);\n\t\t\tif (push) {\n\t\t\t\tif (!endpoint) {\n\t\t\t\t\tthrow new OidcError(\n\t\t\t\t\t\t'par-failed',\n\t\t\t\t\t\t'Pushed authorization requests are required but the issuer publishes no pushed_authorization_request_endpoint.',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst requestUri = await pushRequest(\n\t\t\t\t\tfetcher,\n\t\t\t\t\tendpoint,\n\t\t\t\t\tclient,\n\t\t\t\t\tauthRequest,\n\t\t\t\t\tsigning(flow.dpop),\n\t\t\t\t);\n\t\t\t\ttarget.searchParams.set('client_id', clientId);\n\t\t\t\ttarget.searchParams.set('request_uri', requestUri);\n\t\t\t} else {\n\t\t\t\tfor (const [key, value] of Object.entries(authRequest)) {\n\t\t\t\t\ttarget.searchParams.set(key, value);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst headers = new Headers({ 'Cache-Control': 'no-store' });\n\t\t\tsetCookie(\n\t\t\t\theaders,\n\t\t\t\tcookies.commitChallenge(await flowSeal.seal(flow), null, now()),\n\t\t\t);\n\t\t\theaders.set('Location', target.toString());\n\t\t\treturn new Response(null, { status: 302, headers });\n\t\t},\n\t\tasync callback(request) {\n\t\t\tconst cleared = () => {\n\t\t\t\tconst headers = new Headers();\n\t\t\t\tsetCookie(headers, cookies.destroyChallenge());\n\t\t\t\treturn headers;\n\t\t\t};\n\t\t\tconst fail = (\n\t\t\t\tcode: ConstructorParameters<typeof OidcError>[0],\n\t\t\t\tmessage: string,\n\t\t\t) => new OidcError(code, message, cleared());\n\t\t\tconst url = new URL(request.url);\n\t\t\tconst sealed = cookies.challengeOf(request);\n\t\t\tconst flow = sealed ? await flowSeal.open(sealed) : null;\n\t\t\tif (!isFlow(flow)) {\n\t\t\t\tthrow fail(\n\t\t\t\t\t'missing-challenge',\n\t\t\t\t\t'The sign-in challenge cookie is missing or unreadable (a second tab, an expired page or a blocked cookie).',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (flow.exp <= now()) {\n\t\t\t\tthrow fail(\n\t\t\t\t\t'challenge-expired',\n\t\t\t\t\t'The sign-in took too long; start again.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst returned = url.searchParams.get('state');\n\t\t\tif (returned === null || !sameText(returned, flow.state)) {\n\t\t\t\tthrow fail(\n\t\t\t\t\t'state-mismatch',\n\t\t\t\t\t'The returned state is not the one this sign-in sent.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst failure = url.searchParams.get('error');\n\t\t\tif (failure) {\n\t\t\t\tconst description = url.searchParams.get('error_description');\n\t\t\t\tthrow fail(\n\t\t\t\t\t'provider-error',\n\t\t\t\t\t`The issuer refused: ${failure}${description ? ` (${description})` : ''}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst claimedIssuer = url.searchParams.get('iss');\n\t\t\tif (claimedIssuer !== null && claimedIssuer !== issuer) {\n\t\t\t\tthrow fail('issuer-mismatch', 'The callback names another issuer.');\n\t\t\t}\n\t\t\tconst code = url.searchParams.get('code');\n\t\t\tif (!code) throw fail('missing-code', 'The callback carries no code.');\n\t\t\ttry {\n\t\t\t\tconst document = await issuerApi.discover();\n\t\t\t\tconst answer = await tokenRequest(\n\t\t\t\t\tfetcher,\n\t\t\t\t\tdocument.token_endpoint,\n\t\t\t\t\tclient,\n\t\t\t\t\t{\n\t\t\t\t\t\t...extraTokenParams,\n\t\t\t\t\t\tgrant_type: 'authorization_code',\n\t\t\t\t\t\tcode,\n\t\t\t\t\t\tredirect_uri: redirectUri,\n\t\t\t\t\t\tcode_verifier: flow.verifier,\n\t\t\t\t\t},\n\t\t\t\t\t'token-exchange-failed',\n\t\t\t\t\tsigning(flow.dpop),\n\t\t\t\t);\n\t\t\t\tconst { stored } = await toStored(\n\t\t\t\t\tanswer,\n\t\t\t\t\tflow.nonce,\n\t\t\t\t\tundefined,\n\t\t\t\t\tflow.dpop,\n\t\t\t\t);\n\t\t\t\tconst headers = cleared();\n\t\t\t\tawait commit(headers, stored);\n\t\t\t\theaders.set('Location', safeNext(flow.next));\n\t\t\t\theaders.set('Cache-Control', 'no-store');\n\t\t\t\treturn new Response(null, { status: 302, headers });\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof OidcError) {\n\t\t\t\t\tfor (const value of cleared().getSetCookie()) {\n\t\t\t\t\t\terror.headers.append('Set-Cookie', value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tasync logout(request) {\n\t\t\tconst report = (error: OidcError): void => {\n\t\t\t\ttry {\n\t\t\t\t\toptions.onRevokeError?.(error);\n\t\t\t\t} catch {\n\t\t\t\t\t// A failing hook never blocks the logout.\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst headers = new Headers({ 'Cache-Control': 'no-store' });\n\t\t\tsetCookie(headers, cookies.destroy());\n\t\t\tconst sealed = cookies.token(request);\n\t\t\tconst opened = sealed ? await tokenSeal.open(sealed) : null;\n\t\t\tconst document = await issuerApi.discover().catch((cause) => {\n\t\t\t\tif (options.revokeOnLogout) {\n\t\t\t\t\treport(\n\t\t\t\t\t\tnew OidcError(\n\t\t\t\t\t\t\t'discovery-failed',\n\t\t\t\t\t\t\t'Discovery failed at logout, so the tokens were not revoked.',\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t{ cause },\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn null;\n\t\t\t});\n\t\t\tif (\n\t\t\t\toptions.revokeOnLogout &&\n\t\t\t\tdocument?.revocation_endpoint &&\n\t\t\t\tisStored(opened)\n\t\t\t) {\n\t\t\t\tawait revokeTokens({\n\t\t\t\t\tfetcher,\n\t\t\t\t\tclient,\n\t\t\t\t\tendpoint: document.revocation_endpoint,\n\t\t\t\t\tstored: opened,\n\t\t\t\t\tsigning,\n\t\t\t\t\ttimeoutMs: options.revokeTimeoutMs ?? 3000,\n\t\t\t\t\treport,\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst endpoint = document?.end_session_endpoint;\n\t\t\tif (!endpoint) {\n\t\t\t\theaders.set('Location', options.postLogoutRedirectUri ?? '/');\n\t\t\t\treturn new Response(null, { status: 302, headers });\n\t\t\t}\n\t\t\tconst target = new URL(endpoint);\n\t\t\tif (isStored(opened))\n\t\t\t\ttarget.searchParams.set('id_token_hint', opened.idToken);\n\t\t\ttarget.searchParams.set('client_id', clientId);\n\t\t\tif (options.postLogoutRedirectUri) {\n\t\t\t\ttarget.searchParams.set(\n\t\t\t\t\t'post_logout_redirect_uri',\n\t\t\t\t\toptions.postLogoutRedirectUri,\n\t\t\t\t);\n\t\t\t}\n\t\t\theaders.set('Location', target.toString());\n\t\t\treturn new Response(null, { status: 302, headers });\n\t\t},\n\t};\n}\n",
|
|
9
11
|
"import {\n\tcreateLocalJWKSet,\n\tdecodeJwt,\n\ttype JSONWebKeySet,\n\ttype JWTPayload,\n\terrors as joseErrors,\n\tjwtVerify,\n} from 'jose';\nimport {\n\ttype DpopKey,\n\ttype NonceMemory,\n\tsignDpopProof,\n\twantsNonce,\n} from './dpop';\nimport { OidcError, type OidcErrorCode } from './errors';\n\n/** The fields of the issuer's discovery document the flow reads. */\nexport interface DiscoveryDocument {\n\treadonly issuer: string;\n\treadonly authorization_endpoint: string;\n\treadonly token_endpoint: string;\n\treadonly jwks_uri: string;\n\treadonly end_session_endpoint?: string;\n\treadonly revocation_endpoint?: string;\n\treadonly pushed_authorization_request_endpoint?: string;\n\treadonly require_pushed_authorization_requests?: boolean;\n}\n\n/** What the issuer's token endpoint answers. */\nexport interface TokenResponse {\n\treadonly access_token: string;\n\treadonly id_token?: string;\n\treadonly refresh_token?: string;\n\treadonly expires_in?: number;\n\treadonly token_type?: string;\n}\n\nexport type Fetcher = (input: string, init?: RequestInit) => Promise<Response>;\n\nconst DISCOVERY_TTL = 60 * 60 * 1000;\nconst JWKS_TTL = 10 * 60 * 1000;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === 'object' && value !== null;\n\nconst text = (value: unknown): value is string =>\n\ttypeof value === 'string' && value !== '';\n\n/** Discovery and the issuer's keys, cached; one per relying party. */\nexport function issuerClient(config: {\n\treadonly issuer: string;\n\treadonly fetch: Fetcher;\n\treadonly now: () => number;\n\treadonly algorithms: string[];\n\treadonly clockToleranceSeconds: number;\n}) {\n\tconst { issuer, now } = config;\n\tlet discovery: { at: number; value: Promise<DiscoveryDocument> } | undefined;\n\tlet keys: { at: number; value: Promise<JSONWebKeySet> } | undefined;\n\n\tasync function getJson(url: string, code: OidcErrorCode): Promise<unknown> {\n\t\tlet response: Response;\n\t\ttry {\n\t\t\tresponse = await config.fetch(url, {\n\t\t\t\theaders: { accept: 'application/json' },\n\t\t\t});\n\t\t} catch (cause) {\n\t\t\tthrow new OidcError(code, `Could not reach ${url}.`, undefined, {\n\t\t\t\tcause,\n\t\t\t});\n\t\t}\n\t\tif (!response.ok) {\n\t\t\tthrow new OidcError(code, `${url} answered ${response.status}.`);\n\t\t}\n\t\treturn response.json().catch(() => {\n\t\t\tthrow new OidcError(code, `${url} did not answer JSON.`);\n\t\t});\n\t}\n\n\tasync function loadDiscovery(): Promise<DiscoveryDocument> {\n\t\tconst url = `${issuer.replace(/\\/$/, '')}/.well-known/openid-configuration`;\n\t\tconst body = await getJson(url, 'discovery-failed');\n\t\tif (\n\t\t\t!isRecord(body) ||\n\t\t\t!text(body['authorization_endpoint']) ||\n\t\t\t!text(body['token_endpoint']) ||\n\t\t\t!text(body['jwks_uri'])\n\t\t) {\n\t\t\tthrow new OidcError(\n\t\t\t\t'discovery-failed',\n\t\t\t\t`${url} lacks authorization_endpoint, token_endpoint or jwks_uri.`,\n\t\t\t);\n\t\t}\n\t\tfor (const key of [\n\t\t\t'authorization_endpoint',\n\t\t\t'token_endpoint',\n\t\t\t'jwks_uri',\n\t\t]) {\n\t\t\tconst endpoint = new URL(String(body[key]));\n\t\t\tconst loopback = ['localhost', '127.0.0.1', '[::1]'].includes(\n\t\t\t\tendpoint.hostname,\n\t\t\t);\n\t\t\tif (\n\t\t\t\tendpoint.protocol !== 'https:' &&\n\t\t\t\t!(loopback && endpoint.protocol === 'http:')\n\t\t\t) {\n\t\t\t\tthrow new OidcError(\n\t\t\t\t\t'discovery-failed',\n\t\t\t\t\t`${url} gives a ${key} that is not https.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (body['issuer'] !== issuer) {\n\t\t\tthrow new OidcError(\n\t\t\t\t'issuer-mismatch',\n\t\t\t\t`${url} names the issuer ${JSON.stringify(body['issuer'])}, not ${JSON.stringify(issuer)}.`,\n\t\t\t);\n\t\t}\n\t\treturn body as unknown as DiscoveryDocument;\n\t}\n\n\tconst discover = (): Promise<DiscoveryDocument> => {\n\t\tif (!discovery || now() - discovery.at > DISCOVERY_TTL) {\n\t\t\tconst value = loadDiscovery();\n\t\t\tconst entry = { at: now(), value };\n\t\t\tdiscovery = entry;\n\t\t\tvalue.catch(() => {\n\t\t\t\tif (discovery === entry) discovery = undefined;\n\t\t\t});\n\t\t}\n\t\treturn discovery.value;\n\t};\n\n\tasync function jwks(force: boolean): Promise<JSONWebKeySet> {\n\t\tif (force || !keys || now() - keys.at > JWKS_TTL) {\n\t\t\tconst value = discover().then(\n\t\t\t\tasync (document) =>\n\t\t\t\t\t(await getJson(\n\t\t\t\t\t\tdocument.jwks_uri,\n\t\t\t\t\t\t'invalid-id-token',\n\t\t\t\t\t)) as JSONWebKeySet,\n\t\t\t);\n\t\t\tconst entry = { at: now(), value };\n\t\t\tkeys = entry;\n\t\t\tvalue.catch(() => {\n\t\t\t\tif (keys === entry) keys = undefined;\n\t\t\t});\n\t\t}\n\t\treturn keys.value;\n\t}\n\n\t/**\n\t * Verify an id token: signature against the issuer's keys (refetched once\n\t * when the `kid` is unknown), `iss`, `aud` (and `azp` when several), `exp`.\n\t * `nonce` is checked when given (the code exchange, not a refresh).\n\t */\n\tasync function verifyIdToken(\n\t\tidToken: string,\n\t\tclientId: string,\n\t\tnonce?: string,\n\t): Promise<JWTPayload> {\n\t\tconst document = await discover();\n\t\tconst check = async (force: boolean) =>\n\t\t\tjwtVerify(idToken, createLocalJWKSet(await jwks(force)), {\n\t\t\t\tissuer: document.issuer,\n\t\t\t\taudience: clientId,\n\t\t\t\talgorithms: config.algorithms,\n\t\t\t\tclockTolerance: config.clockToleranceSeconds,\n\t\t\t\tcurrentDate: new Date(now()),\n\t\t\t\trequiredClaims: ['exp', 'iat', 'sub'],\n\t\t\t});\n\t\tlet payload: JWTPayload;\n\t\ttry {\n\t\t\ttry {\n\t\t\t\t({ payload } = await check(false));\n\t\t\t} catch (error) {\n\t\t\t\tif (!(error instanceof joseErrors.JWKSNoMatchingKey)) throw error;\n\t\t\t\t({ payload } = await check(true));\n\t\t\t}\n\t\t} catch (cause) {\n\t\t\tif (cause instanceof OidcError) throw cause;\n\t\t\tthrow new OidcError(\n\t\t\t\t'invalid-id-token',\n\t\t\t\t`The id token was refused: ${cause instanceof Error ? cause.message : String(cause)}`,\n\t\t\t\tundefined,\n\t\t\t\t{ cause },\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\tArray.isArray(payload.aud) &&\n\t\t\tpayload.aud.length > 1 &&\n\t\t\tpayload['azp'] !== clientId\n\t\t) {\n\t\t\tthrow new OidcError(\n\t\t\t\t'invalid-id-token',\n\t\t\t\t'The id token has several audiences and its azp is not this client.',\n\t\t\t);\n\t\t}\n\t\tif (nonce !== undefined && payload['nonce'] !== nonce) {\n\t\t\tthrow new OidcError(\n\t\t\t\t'nonce-mismatch',\n\t\t\t\t'The id token nonce is not the one this sign-in sent.',\n\t\t\t);\n\t\t}\n\t\treturn payload;\n\t}\n\n\treturn { discover, verifyIdToken };\n}\n\n/** What a request to the issuer needs to carry a DPoP proof: the session's key and the nonces seen. */\nexport interface DpopSigning {\n\treadonly key: DpopKey;\n\treadonly nonces: NonceMemory;\n\treadonly now: () => number;\n}\n\ntype Client = { readonly id: string; readonly secret?: string | undefined };\n\n/**\n * POST a form to the issuer with the client's authentication (basic for a\n * confidential client, `client_id` in the body for a public one) and, with\n * `dpop`, a DPoP proof; a `use_dpop_nonce` answer is retried once with the\n * nonce the issuer sent, which is remembered for the next call.\n */\nasync function postForm(\n\tfetcher: Fetcher,\n\tendpoint: string,\n\tclient: Client,\n\tparams: Record<string, string>,\n\tcode: OidcErrorCode,\n\twhat: string,\n\tdpop?: DpopSigning,\n\tsignal?: AbortSignal,\n): Promise<{ response: Response; answer: unknown }> {\n\tconst body = new URLSearchParams(params);\n\tconst headers: Record<string, string> = {\n\t\t'content-type': 'application/x-www-form-urlencoded',\n\t\taccept: 'application/json',\n\t};\n\tif (client.secret === undefined) {\n\t\tbody.set('client_id', client.id);\n\t} else {\n\t\t// client_secret_basic: both parts form-urlencoded first (RFC 6749 2.3.1).\n\t\tconst pair = `${encodeURIComponent(client.id)}:${encodeURIComponent(client.secret)}`;\n\t\theaders['authorization'] = `Basic ${btoa(pair)}`;\n\t}\n\tconst send = async (nonce: string | undefined): Promise<Response> => {\n\t\tconst sent = dpop\n\t\t\t? {\n\t\t\t\t\t...headers,\n\t\t\t\t\tdpop: await signDpopProof(dpop.key, {\n\t\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\t\turl: endpoint,\n\t\t\t\t\t\tnonce,\n\t\t\t\t\t\tnow: dpop.now,\n\t\t\t\t\t}),\n\t\t\t\t}\n\t\t\t: headers;\n\t\ttry {\n\t\t\tconst response = await fetcher(endpoint, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: sent,\n\t\t\t\tbody,\n\t\t\t\t...(signal && { signal }),\n\t\t\t});\n\t\t\tconst given = response.headers.get('dpop-nonce');\n\t\t\tif (dpop && given) dpop.nonces.set(endpoint, given);\n\t\t\treturn response;\n\t\t} catch (cause) {\n\t\t\tthrow new OidcError(\n\t\t\t\tcode,\n\t\t\t\t`The ${what} could not be reached.`,\n\t\t\t\tundefined,\n\t\t\t\t{ cause },\n\t\t\t);\n\t\t}\n\t};\n\tlet response = await send(dpop?.nonces.get(endpoint));\n\tif (dpop && (await wantsNonce(response))) {\n\t\tawait response.body?.cancel().catch(() => undefined);\n\t\tresponse = await send(response.headers.get('dpop-nonce') ?? undefined);\n\t}\n\tconst answer: unknown = await response.json().catch(() => null);\n\treturn { response, answer };\n}\n\nconst detailOf = (answer: unknown): string =>\n\tisRecord(answer)\n\t\t? [answer['error'], answer['error_description']].filter(text).join(': ')\n\t\t: '';\n\n/** POST to the token endpoint; `error` and `description` come from the issuer. */\nexport async function tokenRequest(\n\tfetcher: Fetcher,\n\tendpoint: string,\n\tclient: Client,\n\tparams: Record<string, string>,\n\tcode: OidcErrorCode,\n\tdpop?: DpopSigning,\n): Promise<TokenResponse> {\n\tconst { response, answer } = await postForm(\n\t\tfetcher,\n\t\tendpoint,\n\t\tclient,\n\t\tparams,\n\t\tcode,\n\t\t'token endpoint',\n\t\tdpop,\n\t);\n\tif (!response.ok || !isRecord(answer) || !text(answer['access_token'])) {\n\t\tconst detail = detailOf(answer);\n\t\tthrow new OidcError(\n\t\t\tcode,\n\t\t\t`The token endpoint answered ${response.status}${detail ? ` (${detail})` : ''}.`,\n\t\t);\n\t}\n\tconst type = String(answer['token_type'] ?? 'bearer').toLowerCase();\n\tif (type !== 'bearer' && !(dpop && type === 'dpop')) {\n\t\tthrow new OidcError(\n\t\t\tcode,\n\t\t\t'The token endpoint did not issue a bearer token.',\n\t\t);\n\t}\n\treturn answer as unknown as TokenResponse;\n}\n\n/**\n * POST one token to the revocation endpoint (RFC 7009), with the client's authentication\n * and the DPoP proof when the tokens are bound. Throws `OidcError('revoke-failed')` on a\n * network error or a non-2xx answer.\n */\nexport async function revokeRequest(\n\tfetcher: Fetcher,\n\tendpoint: string,\n\tclient: Client,\n\tparams: { readonly token: string; readonly token_type_hint: string },\n\tdpop?: DpopSigning,\n\tsignal?: AbortSignal,\n): Promise<void> {\n\tconst { response, answer } = await postForm(\n\t\tfetcher,\n\t\tendpoint,\n\t\tclient,\n\t\tparams,\n\t\t'revoke-failed',\n\t\t'revocation endpoint',\n\t\tdpop,\n\t\tsignal,\n\t);\n\tif (!response.ok) {\n\t\tconst detail = detailOf(answer);\n\t\tthrow new OidcError(\n\t\t\t'revoke-failed',\n\t\t\t`The revocation endpoint answered ${response.status}${detail ? ` (${detail})` : ''}.`,\n\t\t);\n\t}\n}\n\n/** POST the authorization request to the pushed authorization request endpoint (RFC 9126): the `request_uri` to redirect with. */\nexport async function pushRequest(\n\tfetcher: Fetcher,\n\tendpoint: string,\n\tclient: Client,\n\tparams: Record<string, string>,\n\tdpop?: DpopSigning,\n): Promise<string> {\n\tconst { response, answer } = await postForm(\n\t\tfetcher,\n\t\tendpoint,\n\t\tclient,\n\t\tparams,\n\t\t'par-failed',\n\t\t'pushed authorization request endpoint',\n\t\tdpop,\n\t);\n\tif (!response.ok || !isRecord(answer) || !text(answer['request_uri'])) {\n\t\tconst detail = detailOf(answer);\n\t\tthrow new OidcError(\n\t\t\t'par-failed',\n\t\t\t`The pushed authorization request endpoint answered ${response.status}${detail ? ` (${detail})` : ''}.`,\n\t\t);\n\t}\n\treturn answer['request_uri'];\n}\n\nexport { decodeJwt };\n",
|
|
10
|
-
"import type { DpopKey } from './dpop';\nimport { OidcError } from './errors';\nimport type { DpopSigning, Fetcher } from './flow';\nimport { revokeRequest } from './flow';\n\n/** What `revokeTokens` needs: the sealed session's tokens and, when bound, its DPoP key. */\ninterface Revocable {\n\treadonly accessToken: string;\n\treadonly refreshToken?: string | undefined;\n\treadonly dpop?: DpopKey | undefined;\n}\n\n/**\n * Revoke the refresh token, then the access token (RFC 7009). Each failure is passed to\n * `report`, none is thrown. `timeoutMs` bounds both calls together: past it, the pending\n * call is aborted and reported as `revoke-failed`, and the other is not attempted.\n */\nexport async function revokeTokens(input: {\n\treadonly fetcher: Fetcher;\n\treadonly client: {\n\t\treadonly id: string;\n\t\treadonly secret?: string | undefined;\n\t};\n\treadonly endpoint: string;\n\treadonly stored: Revocable;\n\treadonly signing: (key: DpopKey | undefined) => DpopSigning | undefined;\n\treadonly timeoutMs: number;\n\treadonly report: (error: OidcError) => void;\n}): Promise<void> {\n\tconst { stored } = input;\n\tconst signal = AbortSignal.timeout(input.timeoutMs);\n\tconst timedOut = new Promise<never>((_, reject) => {\n\t\tsignal.addEventListener(\n\t\t\t'abort',\n\t\t\t() =>\n\t\t\t\treject(\n\t\t\t\t\tnew OidcError(\n\t\t\t\t\t\t'revoke-failed',\n\t\t\t\t\t\t`The revocation endpoint did not answer within ${input.timeoutMs} ms.`,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t{ once: true },\n\t\t);\n\t});\n\ttimedOut.catch(() => undefined);\n\tconst tokens = [\n\t\t...(stored.refreshToken\n\t\t\t? ([[stored.refreshToken, 'refresh_token']] as const)\n\t\t\t: []),\n\t\t[stored.accessToken, 'access_token'] as const,\n\t];\n\tfor (const [token, hint] of tokens) {\n\t\ttry {\n\t\t\t// The race also ends a fetcher that ignores the signal.\n\t\t\tawait Promise.race([\n\t\t\t\trevokeRequest(\n\t\t\t\t\tinput.fetcher,\n\t\t\t\t\tinput.endpoint,\n\t\t\t\t\tinput.client,\n\t\t\t\t\t{ token, token_type_hint: hint },\n\t\t\t\t\tinput.signing(stored.dpop),\n\t\t\t\t\tsignal,\n\t\t\t\t),\n\t\t\t\ttimedOut,\n\t\t\t]);\n\t\t} catch (error) {\n\t\t\tinput.report(\n\t\t\t\terror instanceof OidcError\n\t\t\t\t\t? error\n\t\t\t\t\t: new OidcError('revoke-failed', 'Revocation failed.', undefined, {\n\t\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\t}),\n\t\t\t);\n\t\t\tif (signal.aborted) return;\n\t\t}\n\t}\n}\n"
|
|
12
|
+
"import type { DpopKey } from './dpop';\nimport { OidcError } from './errors';\nimport type { DpopSigning, Fetcher } from './flow';\nimport { revokeRequest } from './flow';\n\n/** What `revokeTokens` needs: the sealed session's tokens and, when bound, its DPoP key. */\ninterface Revocable {\n\treadonly accessToken: string;\n\treadonly refreshToken?: string | undefined;\n\treadonly dpop?: DpopKey | undefined;\n}\n\n/**\n * Revoke the refresh token, then the access token (RFC 7009). Each failure is passed to\n * `report`, none is thrown. `timeoutMs` bounds both calls together: past it, the pending\n * call is aborted and reported as `revoke-failed`, and the other is not attempted.\n */\nexport async function revokeTokens(input: {\n\treadonly fetcher: Fetcher;\n\treadonly client: {\n\t\treadonly id: string;\n\t\treadonly secret?: string | undefined;\n\t};\n\treadonly endpoint: string;\n\treadonly stored: Revocable;\n\treadonly signing: (key: DpopKey | undefined) => DpopSigning | undefined;\n\treadonly timeoutMs: number;\n\treadonly report: (error: OidcError) => void;\n}): Promise<void> {\n\tconst { stored } = input;\n\tconst signal = AbortSignal.timeout(input.timeoutMs);\n\tconst timedOut = new Promise<never>((_, reject) => {\n\t\tsignal.addEventListener(\n\t\t\t'abort',\n\t\t\t() =>\n\t\t\t\treject(\n\t\t\t\t\tnew OidcError(\n\t\t\t\t\t\t'revoke-failed',\n\t\t\t\t\t\t`The revocation endpoint did not answer within ${input.timeoutMs} ms.`,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t{ once: true },\n\t\t);\n\t});\n\ttimedOut.catch(() => undefined);\n\tconst tokens = [\n\t\t...(stored.refreshToken\n\t\t\t? ([[stored.refreshToken, 'refresh_token']] as const)\n\t\t\t: []),\n\t\t[stored.accessToken, 'access_token'] as const,\n\t];\n\tfor (const [token, hint] of tokens) {\n\t\ttry {\n\t\t\t// The race also ends a fetcher that ignores the signal.\n\t\t\tawait Promise.race([\n\t\t\t\trevokeRequest(\n\t\t\t\t\tinput.fetcher,\n\t\t\t\t\tinput.endpoint,\n\t\t\t\t\tinput.client,\n\t\t\t\t\t{ token, token_type_hint: hint },\n\t\t\t\t\tinput.signing(stored.dpop),\n\t\t\t\t\tsignal,\n\t\t\t\t),\n\t\t\t\ttimedOut,\n\t\t\t]);\n\t\t} catch (error) {\n\t\t\tinput.report(\n\t\t\t\terror instanceof OidcError\n\t\t\t\t\t? error\n\t\t\t\t\t: new OidcError('revoke-failed', 'Revocation failed.', undefined, {\n\t\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\t}),\n\t\t\t);\n\t\t\tif (signal.aborted) return;\n\t\t}\n\t}\n}\n",
|
|
13
|
+
"import { redirect } from 'react-router';\nimport { siteCheck } from '../errors/same-site';\nimport { sitePath } from '../session/model/site-path';\nimport { OidcError } from './errors';\nimport type { OidcClient } from './oidc';\n\ntype Args = { readonly request: Request };\n\n/** Runs before a route does its work: throw a `Response` or `data()` to refuse. */\ntype Guard = (request: Request) => void | Promise<void>;\n\n/** Options of {@link signInRoute}. */\nexport interface SignInRouteOptions {\n\t/** Runs first, e.g. to refuse a host the sign-in must not be served on. */\n\treadonly guard?: Guard | undefined;\n}\n\n/**\n * The sign-in route module: a `loader` that redirects to the issuer (`?next=`\n * is kept, through `safeNext`).\n *\n * @example\n * // app/routes/sign-in.ts\n * export const { loader } = signInRoute(oidc);\n */\nexport function signInRoute(\n\toidc: Pick<OidcClient, 'signIn'>,\n\toptions: SignInRouteOptions = {},\n): { loader: (args: Args) => Promise<Response> } {\n\treturn {\n\t\tasync loader({ request }) {\n\t\t\tawait options.guard?.(request);\n\t\t\treturn oidc.signIn(request);\n\t\t},\n\t};\n}\n\n/** Options of {@link callbackRoute}. */\nexport interface CallbackRouteOptions {\n\t/** Runs first. */\n\treadonly guard?: Guard | undefined;\n\t/**\n\t * Answers a refused sign-in. It gets the `OidcError` and must put its\n\t * `headers` on the response (they clear the spent challenge cookie).\n\t * By default the browser is redirected to `errorPath` with `?sign-in-error=<code>`.\n\t */\n\treadonly onError?:\n\t\t| ((error: OidcError) => Response | Promise<Response>)\n\t\t| undefined;\n\t/** Where the default answer redirects: a path of this site with no query or fragment (`TypeError` otherwise). `'/'` by default. */\n\treadonly errorPath?: string | undefined;\n}\n\n/**\n * The redirect route: a `loader` that finishes the sign-in (302 to `next`, token\n * cookie set). An `OidcError` is answered, never thrown, with the cookie that\n * clears the spent challenge; any other error is thrown.\n *\n * @example\n * // app/routes/auth.callback.ts\n * export const { loader } = callbackRoute(oidc, { errorPath: '/sign-in/failed' });\n */\nexport function callbackRoute(\n\toidc: Pick<OidcClient, 'callback'>,\n\toptions: CallbackRouteOptions = {},\n): { loader: (args: Args) => Promise<Response> } {\n\tconst errorPath = sitePath(options.errorPath ?? '/', {\n\t\tlabel: 'callbackRoute(): errorPath',\n\t});\n\treturn {\n\t\tasync loader({ request }) {\n\t\t\tawait options.guard?.(request);\n\t\t\ttry {\n\t\t\t\treturn await oidc.callback(request);\n\t\t\t} catch (error) {\n\t\t\t\tif (!(error instanceof OidcError)) throw error;\n\t\t\t\tif (options.onError) return options.onError(error);\n\t\t\t\treturn redirect(\n\t\t\t\t\t`${errorPath}?${new URLSearchParams({ 'sign-in-error': error.code })}`,\n\t\t\t\t\t{ headers: error.headers },\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t};\n}\n\n/** Options of {@link signOutRoute}. */\nexport interface SignOutRouteOptions {\n\t/** Runs first, on the action and on the loader. */\n\treadonly guard?: Guard | undefined;\n\t/** The app's own origin, required behind a TLS-terminating proxy (see `requireSameSite`). */\n\treadonly origin?: string | (() => string | undefined) | undefined;\n\t/** Where a GET on the route goes: a path of this site (`TypeError` otherwise). `'/'` by default. */\n\treadonly redirectTo?: string | undefined;\n}\n\n/**\n * The sign-out route module: an `action` that refuses a cross-site request,\n * then calls `logout`: the cookie is cleared (and the tokens revoked with\n * `revokeOnLogout`), then the browser goes to the issuer's\n * `end_session_endpoint` (with `id_token_hint` and `post_logout_redirect_uri`)\n * when discovery announces one, else to `postLogoutRedirectUri` or `/`: the\n * local session alone ends. A GET only redirects, so a link or an image cannot\n * sign the user out.\n *\n * @example\n * // app/routes/sign-out.ts\n * export const { action, loader } = signOutRoute(oidc);\n */\nexport function signOutRoute(\n\toidc: Pick<OidcClient, 'logout'>,\n\toptions: SignOutRouteOptions = {},\n): {\n\taction: (args: Args) => Promise<Response>;\n\tloader: (args: Args) => Promise<Response>;\n} {\n\tconst sameSite = siteCheck(options.origin);\n\tconst redirectTo = sitePath(options.redirectTo ?? '/', {\n\t\tlabel: 'signOutRoute(): redirectTo',\n\t\tquery: true,\n\t});\n\treturn {\n\t\tasync action({ request }) {\n\t\t\tawait options.guard?.(request);\n\t\t\tsameSite(request);\n\t\t\treturn oidc.logout(request);\n\t\t},\n\t\tasync loader({ request }) {\n\t\t\tawait options.guard?.(request);\n\t\t\treturn redirect(redirectTo);\n\t\t},\n\t};\n}\n"
|
|
11
14
|
],
|
|
12
|
-
"mappings": ";;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAM,UAAU,IAAI;AACpB,IAAM,UAAU,IAAI;AAGb,IAAM,cAAc,CAAC,UAA8B;AAAA,EACzD,IAAI,SAAS;AAAA,EACb,WAAW,QAAQ;AAAA,IAAO,UAAU,OAAO,aAAa,IAAI;AAAA,EAC5D,OAAO,KAAK,MAAM,EAChB,WAAW,KAAK,GAAG,EACnB,WAAW,KAAK,GAAG,EACnB,WAAW,KAAK,EAAE;AAAA;AAGrB,IAAM,gBAAgB,CAAC,SAA0C;AAAA,EAChE,MAAM,SAAS,KAAK,WAAW,KAAK,GAAG,EAAE,WAAW,KAAK,GAAG;AAAA,EAC5D,MAAM,SAAS,KAAK,SAAS,IAAI,QAAQ,IAAK,OAAO,SAAS,KAAM,CAAC,CAAC;AAAA,EACtE,OAAO,WAAW,KAAK,QAAQ,CAAC,SAAS,KAA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AAS,QAAQ,cAAc,KAAK;AAAA,IACtD,OAAO;AAAA,IACP,OAAO;AAAA,EACR,CAAC;AAAA,EACD,OAAO;AAAA,UACA,MAAM,GAAG,WAAW;AAAA,MACzB,MAAM,QAAQ,QAAQ,OAAO;AAAA,MAC7B,SAAS,OAAO;AAAA,MAChB,OAAO,KAAK,OAAO,OAAO;AAAA;AAAA,UAErB,MAAM,GAAG,WAAW;AAAA,MACzB,MAAM,QAAQ,QAAQ,OAAO;AAAA,MAC7B,OAAO,UAAS,UAAU;AAAA;AAAA,EAE5B;AAAA;",
|
|
16
|
+
"debugId": "B7DF2BEADD6B2F6B64756E2164756E21",
|
|
14
17
|
"names": []
|
|
15
18
|
}
|
package/dist/oidc/oidc.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export interface OidcOptions {
|
|
|
27
27
|
readonly sessionSeconds?: number | undefined;
|
|
28
28
|
/** Refresh when the access token ends within this many seconds. 60 by default. */
|
|
29
29
|
readonly refreshSkewSeconds?: number | undefined;
|
|
30
|
+
/** How long, in ms, parallel refreshes with one refresh token share one flight, so a rotating issuer sees it once. 10000 by default; from 0 to 2147483647, and well under the access token's lifetime. */
|
|
31
|
+
readonly refreshFlightMs?: number | undefined;
|
|
30
32
|
/** Clock difference accepted on `exp` and `iat`. 30 by default. */
|
|
31
33
|
readonly clockToleranceSeconds?: number | undefined;
|
|
32
34
|
/** Id token signature algorithms accepted. `RS256`, `PS256`, `ES256` and `EdDSA` by default. */
|
|
@@ -87,6 +89,8 @@ export interface OidcUser {
|
|
|
87
89
|
readonly headers: Headers;
|
|
88
90
|
/** Signs the proofs of calls to a resource when the tokens are DPoP-bound (`dpop` option, and the issuer sent `token_type: DPoP`), else `null`. */
|
|
89
91
|
readonly dpop: DpopBinding | null;
|
|
92
|
+
/** The `fetch` the client was given (global `fetch` by default): `dpopFetch` sends a bearer call through it. */
|
|
93
|
+
readonly fetch: Fetcher;
|
|
90
94
|
}
|
|
91
95
|
/** The relying party `oidcClient` returns. */
|
|
92
96
|
export interface OidcClient {
|
|
@@ -96,6 +100,20 @@ export interface OidcClient {
|
|
|
96
100
|
callback(request: Request): Promise<Response>;
|
|
97
101
|
/** The signed-in user (refreshed if due), or `null`. */
|
|
98
102
|
oidcUser(request: Request): Promise<OidcUser | null>;
|
|
103
|
+
/**
|
|
104
|
+
* Refreshes `user` from its own tokens (not the request's cookie, which a rotation
|
|
105
|
+
* leaves behind) when its access token ends within `refreshSkewSeconds`, and returns
|
|
106
|
+
* the new user, whose `headers` hold the `Set-Cookie` to send; `user` itself when
|
|
107
|
+
* nothing is due, or with `{ force: true }` always. A forced refresh inside the
|
|
108
|
+
* flight window of `refreshFlightMs` shares that flight's tokens; with no refresh
|
|
109
|
+
* token it returns `user` while its access token is valid. A refresh that fails
|
|
110
|
+
* throws `OidcError` (`refresh-failed`) when the access token has ended, else
|
|
111
|
+
* returns `user`. Only a user this client returned can be refreshed (else
|
|
112
|
+
* `TypeError`).
|
|
113
|
+
*/
|
|
114
|
+
refresh(user: OidcUser, options?: {
|
|
115
|
+
readonly force?: boolean | undefined;
|
|
116
|
+
}): Promise<OidcUser>;
|
|
99
117
|
/** Like `oidcUser`, but throws a redirect to the sign-in route (with a safe `next`) when there is none. */
|
|
100
118
|
requireOidcUser(request: Request): Promise<OidcUser>;
|
|
101
119
|
/** Clears the token cookie (after revoking the tokens with `revokeOnLogout`) and redirects to the issuer's `end_session_endpoint` (with `id_token_hint`), else to `postLogoutRedirectUri` or `/`. Call it from an action. */
|
package/dist/oidc/oidc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oidc.d.ts","sourceRoot":"","sources":["../../src/oidc/oidc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAIvC,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,WAAW,EAMhB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CA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}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { OidcError } from './errors';
|
|
2
|
+
import type { OidcClient } from './oidc';
|
|
3
|
+
type Args = {
|
|
4
|
+
readonly request: Request;
|
|
5
|
+
};
|
|
6
|
+
/** Runs before a route does its work: throw a `Response` or `data()` to refuse. */
|
|
7
|
+
type Guard = (request: Request) => void | Promise<void>;
|
|
8
|
+
/** Options of {@link signInRoute}. */
|
|
9
|
+
export interface SignInRouteOptions {
|
|
10
|
+
/** Runs first, e.g. to refuse a host the sign-in must not be served on. */
|
|
11
|
+
readonly guard?: Guard | undefined;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The sign-in route module: a `loader` that redirects to the issuer (`?next=`
|
|
15
|
+
* is kept, through `safeNext`).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // app/routes/sign-in.ts
|
|
19
|
+
* export const { loader } = signInRoute(oidc);
|
|
20
|
+
*/
|
|
21
|
+
export declare function signInRoute(oidc: Pick<OidcClient, 'signIn'>, options?: SignInRouteOptions): {
|
|
22
|
+
loader: (args: Args) => Promise<Response>;
|
|
23
|
+
};
|
|
24
|
+
/** Options of {@link callbackRoute}. */
|
|
25
|
+
export interface CallbackRouteOptions {
|
|
26
|
+
/** Runs first. */
|
|
27
|
+
readonly guard?: Guard | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Answers a refused sign-in. It gets the `OidcError` and must put its
|
|
30
|
+
* `headers` on the response (they clear the spent challenge cookie).
|
|
31
|
+
* By default the browser is redirected to `errorPath` with `?sign-in-error=<code>`.
|
|
32
|
+
*/
|
|
33
|
+
readonly onError?: ((error: OidcError) => Response | Promise<Response>) | undefined;
|
|
34
|
+
/** Where the default answer redirects: a path of this site with no query or fragment (`TypeError` otherwise). `'/'` by default. */
|
|
35
|
+
readonly errorPath?: string | undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The redirect route: a `loader` that finishes the sign-in (302 to `next`, token
|
|
39
|
+
* cookie set). An `OidcError` is answered, never thrown, with the cookie that
|
|
40
|
+
* clears the spent challenge; any other error is thrown.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // app/routes/auth.callback.ts
|
|
44
|
+
* export const { loader } = callbackRoute(oidc, { errorPath: '/sign-in/failed' });
|
|
45
|
+
*/
|
|
46
|
+
export declare function callbackRoute(oidc: Pick<OidcClient, 'callback'>, options?: CallbackRouteOptions): {
|
|
47
|
+
loader: (args: Args) => Promise<Response>;
|
|
48
|
+
};
|
|
49
|
+
/** Options of {@link signOutRoute}. */
|
|
50
|
+
export interface SignOutRouteOptions {
|
|
51
|
+
/** Runs first, on the action and on the loader. */
|
|
52
|
+
readonly guard?: Guard | undefined;
|
|
53
|
+
/** The app's own origin, required behind a TLS-terminating proxy (see `requireSameSite`). */
|
|
54
|
+
readonly origin?: string | (() => string | undefined) | undefined;
|
|
55
|
+
/** Where a GET on the route goes: a path of this site (`TypeError` otherwise). `'/'` by default. */
|
|
56
|
+
readonly redirectTo?: string | undefined;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The sign-out route module: an `action` that refuses a cross-site request,
|
|
60
|
+
* then calls `logout`: the cookie is cleared (and the tokens revoked with
|
|
61
|
+
* `revokeOnLogout`), then the browser goes to the issuer's
|
|
62
|
+
* `end_session_endpoint` (with `id_token_hint` and `post_logout_redirect_uri`)
|
|
63
|
+
* when discovery announces one, else to `postLogoutRedirectUri` or `/`: the
|
|
64
|
+
* local session alone ends. A GET only redirects, so a link or an image cannot
|
|
65
|
+
* sign the user out.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* // app/routes/sign-out.ts
|
|
69
|
+
* export const { action, loader } = signOutRoute(oidc);
|
|
70
|
+
*/
|
|
71
|
+
export declare function signOutRoute(oidc: Pick<OidcClient, 'logout'>, options?: SignOutRouteOptions): {
|
|
72
|
+
action: (args: Args) => Promise<Response>;
|
|
73
|
+
loader: (args: Args) => Promise<Response>;
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U,EAAE,UAAU,CAAC,EAClC,OAAO,GAAE,oBAAyB,GAChC;IAAE,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAAE,CAmB/C;AAED,uCAAuC;AACvC,MAAM,WAAW,mBAAmB;IACnC,mDAAmD;IACnD,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;IACnC,6FAA6F;IAC7F,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC;IAClE,oGAAoG;IACpG,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACzC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAC3B,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,EAChC,OAAO,GAAE,mBAAwB,GAC/B;IACF,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC1C,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC1C,CAiBA"}
|
package/dist/session/index.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
nextOf2,
|
|
3
2
|
hasSiteCheck,
|
|
4
3
|
requireSameSite2
|
|
5
|
-
} from "../chunks/index-
|
|
4
|
+
} from "../chunks/index-6zx9dfvs.js";
|
|
6
5
|
import {
|
|
7
6
|
LINK_JSON_HEADER2,
|
|
8
|
-
sitePath,
|
|
9
7
|
SIGN_IN_PATHS2,
|
|
10
8
|
signInPath2,
|
|
11
9
|
secondFactorPath2
|
|
12
|
-
} from "../chunks/index-
|
|
10
|
+
} from "../chunks/index-5hjhzztk.js";
|
|
13
11
|
import {
|
|
14
12
|
isApiErrorLike2,
|
|
15
13
|
retryAfterOf2,
|
|
@@ -35,13 +33,17 @@ import {
|
|
|
35
33
|
sessionCookies2,
|
|
36
34
|
challengeCleared
|
|
37
35
|
} from "../chunks/index-1nw5yeek.js";
|
|
36
|
+
import {
|
|
37
|
+
nextOf2
|
|
38
|
+
} from "../chunks/index-njfh26ez.js";
|
|
38
39
|
import {
|
|
39
40
|
isCrossSite
|
|
40
41
|
} from "../chunks/index-mscfme4r.js";
|
|
41
42
|
import {
|
|
42
43
|
HOME2,
|
|
43
|
-
safeNext2
|
|
44
|
-
|
|
44
|
+
safeNext2,
|
|
45
|
+
sitePath
|
|
46
|
+
} from "../chunks/index-t68hwhz1.js";
|
|
45
47
|
// src/session/link-json.ts
|
|
46
48
|
function handOver(response) {
|
|
47
49
|
const location = response.headers.get("location");
|
|
@@ -1086,5 +1088,5 @@ export {
|
|
|
1086
1088
|
stepUpSteps
|
|
1087
1089
|
};
|
|
1088
1090
|
|
|
1089
|
-
//# debugId=
|
|
1091
|
+
//# debugId=46FE61F7C071D16264756E2164756E21
|
|
1090
1092
|
//# sourceMappingURL=index.js.map
|