axiam-sdk 1.3.0 → 1.4.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.
Files changed (58) hide show
  1. package/README.md +130 -14
  2. package/dist/amqp/index.d.cts +384 -17
  3. package/dist/amqp/index.d.ts +384 -17
  4. package/dist/amqp/index.js +639 -66
  5. package/dist/amqp/index.js.map +1 -1
  6. package/dist/amqp/index.mjs +631 -67
  7. package/dist/amqp/index.mjs.map +1 -1
  8. package/dist/{authzCore-D-hquWSI.d.ts → authzCore-Ced9zDIV.d.ts} +49 -12
  9. package/dist/{authzCore-CqXzLNmT.d.cts → authzCore-Des2NcKA.d.cts} +49 -12
  10. package/dist/browser/index.d.cts +1 -1
  11. package/dist/browser/index.d.ts +1 -1
  12. package/dist/{client-CaurIxje.d.ts → client-C1kRISf8.d.ts} +15 -1
  13. package/dist/{client-Bp7riC4k.d.cts → client-Dpd864N9.d.cts} +15 -1
  14. package/dist/{cookieJar-oKazfbN1.d.cts → cookieJar-CeH2FZIT.d.cts} +3 -3
  15. package/dist/{cookieJar-DC4GLKrJ.d.ts → cookieJar-DPx9Qtcf.d.ts} +3 -3
  16. package/dist/grpc/index.d.cts +5 -5
  17. package/dist/grpc/index.d.ts +5 -5
  18. package/dist/grpc/index.js +249 -18
  19. package/dist/grpc/index.js.map +1 -1
  20. package/dist/grpc/index.mjs +249 -18
  21. package/dist/grpc/index.mjs.map +1 -1
  22. package/dist/index.d.cts +2 -2
  23. package/dist/index.d.ts +2 -2
  24. package/dist/index.js +29 -3
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.mjs +29 -3
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/{jwks-CTVpOWzI.d.cts → jwks-CQtWokVd.d.cts} +62 -7
  29. package/dist/{jwks-CTVpOWzI.d.ts → jwks-CQtWokVd.d.ts} +62 -7
  30. package/dist/middleware/index.d.cts +220 -43
  31. package/dist/middleware/index.d.ts +220 -43
  32. package/dist/middleware/index.js +587 -149
  33. package/dist/middleware/index.js.map +1 -1
  34. package/dist/middleware/index.mjs +579 -150
  35. package/dist/middleware/index.mjs.map +1 -1
  36. package/dist/nestjs/index.d.cts +18 -4
  37. package/dist/nestjs/index.d.ts +18 -4
  38. package/dist/nestjs/index.js +20 -1
  39. package/dist/nestjs/index.js.map +1 -1
  40. package/dist/nestjs/index.mjs +19 -2
  41. package/dist/nestjs/index.mjs.map +1 -1
  42. package/dist/node/index.d.cts +5 -5
  43. package/dist/node/index.d.ts +5 -5
  44. package/dist/node/index.js +351 -66
  45. package/dist/node/index.js.map +1 -1
  46. package/dist/node/index.mjs +348 -67
  47. package/dist/node/index.mjs.map +1 -1
  48. package/dist/{oidcState-CZhj0MBP.d.ts → oidcState-CzpXPAHF.d.ts} +54 -14
  49. package/dist/{oidcState-EnEJmoF5.d.cts → oidcState-XOYEMQP6.d.cts} +54 -14
  50. package/dist/rest/index.d.cts +3 -3
  51. package/dist/rest/index.d.ts +3 -3
  52. package/dist/rest/index.js +29 -3
  53. package/dist/rest/index.js.map +1 -1
  54. package/dist/rest/index.mjs +29 -3
  55. package/dist/rest/index.mjs.map +1 -1
  56. package/dist/{session-CeIUXgpE.d.cts → session-DoQzoChX.d.cts} +1 -1
  57. package/dist/{session-Beo11VT_.d.ts → session-Z-6IyaSU.d.ts} +1 -1
  58. package/package.json +10 -10
@@ -239,6 +239,20 @@ declare function verifyTokenBinding(claims: Pick<AxiamClaims, 'cnf'>, proofs?: P
239
239
  declare function certificateThumbprintS256(der: Uint8Array): Promise<string>;
240
240
  /** Path (relative to the client base URL) of the org-wide JWKS endpoint. */
241
241
  declare const JWKS_PATH = "/oauth2/jwks";
242
+ /**
243
+ * The TLS material the JWKS fetch presents, the same material the REST client
244
+ * uses (CONTRACT.md §6 `customCa`, §6.1 client identity): `ca` extends server
245
+ * trust, `cert`/`key` are the client identity. There is deliberately no
246
+ * verification switch; strict server verification stays at its default.
247
+ */
248
+ interface JwksTlsOptions {
249
+ /** PEM bundle trusted in addition to the default roots (§6). */
250
+ ca?: string;
251
+ /** PEM client-certificate chain (§6.1). */
252
+ cert?: string;
253
+ /** PEM private key for `cert` (§6.1). Secret: never logged or retained. */
254
+ key?: string;
255
+ }
242
256
  /**
243
257
  * Clock-skew leeway applied to the `exp` and `nbf` checks (CONTRACT.md §10.1
244
258
  * rule 7).
@@ -291,6 +305,9 @@ interface Verifier {
291
305
  * | 6 | `aud` | checked only when `expectedAudience` is supplied. |
292
306
  * | 7 | clock skew | {@link CLOCK_SKEW_LEEWAY_SEC}, passed as `clockTolerance`. |
293
307
  * | 9 | `cnf` | (contract 1.51 fix) `proofs` defaults to `{}` — no evidence — so a token carrying `cnf` is refused unless the caller supplies matching evidence. Enforced by handing the verified claims and `proofs` to {@link verifyTokenBinding}, the same function {@link verifyCertificateBinding}, `authenticateRequest` and a hand-rolled guard share, so local verification never disagrees with itself about whether a token is a bearer token. An unbound token is unaffected whether or not `proofs` is supplied. |
308
+ * | 10 | `typ` | (contract 1.68) a header `typ` that is present must be `at+jwt` (case-insensitive, `application/` allowed); `JWT`, `logout+jwt`, `secevent+jwt` and every `axiam-…+jwt` purpose type are refused. No `typ` is not refused by this rule. See `isAccessTokenTyp` (exported from `axiam-sdk/node`). |
309
+ * | 11 | `purpose` | (contract 1.68) a payload carrying a `purpose` member is refused, whatever its value. |
310
+ * | 12 | `kid` | (contract 1.68) a header with no `kid` is refused before any key lookup — there is no "only key in the set" fallback on this path. An unknown `kid` follows the §12.4 rule 2 re-fetch window. |
294
311
  *
295
312
  * **`proofs` and which entry point to call.** This method is the SDK's
296
313
  * documented §10 guard entry point (see {@link verifySignatureOnlyUnchecked}),
@@ -365,23 +382,61 @@ interface JwksVerifier extends Verifier, IdTokenVerifier {
365
382
  * Build a verifier bound to `{baseUrl}/oauth2/jwks`.
366
383
  *
367
384
  * `jose` is loaded lazily via dynamic `import()` (Pitfall 1 — CJS-safe); the
368
- * remote JWKS itself is also fetched/cached lazily by `jose`, not eagerly
369
- * here.
385
+ * remote JWKS itself is fetched/cached lazily by {@link JwksCache}, not
386
+ * eagerly here.
370
387
  *
371
388
  * For the relying-party (§12) flow use {@link createJwksVerifier} with the
372
389
  * `jwks_uri` the discovery document advertises instead of hardcoding
373
390
  * {@link JWKS_PATH} — §12.3 rule 6 requires reading the URI from the document.
374
391
  */
375
- declare function createVerifier(baseUrl: string): JwksVerifier;
392
+ declare function createVerifier(baseUrl: string, tlsOptions?: JwksTlsOptions): JwksVerifier;
376
393
  /**
377
394
  * Build a verifier bound to an explicit, absolute JWKS URI — the `jwks_uri`
378
395
  * value taken from the OIDC discovery document (CONTRACT.md §12.3 rule 6).
379
396
  *
380
397
  * Identical machinery to {@link createVerifier}: one lazily-resolved
381
- * `createRemoteJWKSet` singleton per verifier instance, shared by
398
+ * key-set cache per verifier instance, shared by
382
399
  * `verifyAccessToken` and `verifyIdToken`.
400
+ *
401
+ * `tlsOptions` (Node only) is the {@link JwksTlsOptions} the key-set fetch
402
+ * presents — pass the client's `customCa` / client identity so a private-CA
403
+ * server's JWKS is reachable (#175). Omitted, the platform defaults apply.
404
+ * A client identity (`cert`/`key`) given here is presented to WHATEVER origin
405
+ * `jwksUri` names; the SDK's own callers withhold it from a `jwks_uri` on a
406
+ * different origin than the client's base URL, a direct caller must do the same.
407
+ */
408
+ declare function createJwksVerifier(jwksUri: string, tlsOptions?: JwksTlsOptions): JwksVerifier;
409
+ /**
410
+ * CONTRACT.md §10.1 rules 10 and 12 (contract 1.68; N14) — the header half of
411
+ * "this token is an access token": the JOSE header MUST carry a non-empty
412
+ * `kid` (no single-key fallback), and a `typ` that is present MUST satisfy
413
+ * {@link isAccessTokenTyp}.
414
+ *
415
+ * Exported so the §10 guard (`authenticateRequest`) re-asserts it on its own
416
+ * side, as it does rule 4, without trusting a caller-supplied {@link Verifier}
417
+ * to have applied it. Decodes the header without verifying anything else.
418
+ *
419
+ * @throws AuthError when the token is not a three-segment JWS with a JSON
420
+ * header, carries no `kid`, or carries a `typ` other than `at+jwt`.
421
+ */
422
+ declare function assertAccessTokenHeader(token: string): void;
423
+ /**
424
+ * CONTRACT.md §10.1 rule 11 (contract 1.68; N14): a claim set carrying a
425
+ * `purpose` member is a purpose token (MFA challenge, MFA setup, WebAuthn
426
+ * state), never an access token — whatever the value, `null` included, and
427
+ * whatever `typ` said. Pass the verified payload itself, not a claims model
428
+ * that may drop unknown members.
429
+ *
430
+ * @throws AuthError when `payload` has an own `purpose` member.
431
+ */
432
+ declare function assertNoPurposeClaim(payload: object): void;
433
+ /**
434
+ * CONTRACT.md §10.1 rule 10 (contract 1.68): whether a JOSE `typ` names an
435
+ * access token — `at+jwt` (RFC 9068 §2.1), compared ASCII case-insensitively,
436
+ * with or without the `application/` media-type prefix (RFC 7515 §4.1.9),
437
+ * exactly as the server compares it. A non-string `typ` is not one.
383
438
  */
384
- declare function createJwksVerifier(jwksUri: string): JwksVerifier;
439
+ declare function isAccessTokenTyp(typ: unknown): boolean;
385
440
  /**
386
441
  * CONTRACT.md §10.1 rule 4 — assert the token's `tenant_id` claim against the
387
442
  * tenant the relying party is configured for.
@@ -397,5 +452,5 @@ declare function createJwksVerifier(jwksUri: string): JwksVerifier;
397
452
  */
398
453
  declare function assertTenantClaim(claim: unknown, expected: string | undefined): void;
399
454
 
400
- export { JWKS_PATH as J, MAX_CLOCK_SKEW_SEC as M, CLOCK_SKEW_LEEWAY_SEC as b, createVerifier as c, ID_TOKEN_ALG as d, assertTenantClaim as h, certificateThumbprintS256 as i, createJwksVerifier as j, verifyTokenBinding as k, verifyCertificateBinding as v };
401
- export type { AxiamClaims as A, CnfClaim as C, IdTokenClaims as I, PresentedProofs as P, Verifier as V, AccessTokenExpectations as a, IdTokenExpectations as e, IdTokenVerifier as f, JwksVerifier as g };
455
+ export { JWKS_PATH as J, MAX_CLOCK_SKEW_SEC as M, CLOCK_SKEW_LEEWAY_SEC as b, createVerifier as c, ID_TOKEN_ALG as d, assertAccessTokenHeader as i, assertNoPurposeClaim as j, assertTenantClaim as k, certificateThumbprintS256 as l, createJwksVerifier as m, isAccessTokenTyp as n, verifyTokenBinding as o, verifyCertificateBinding as v };
456
+ export type { AxiamClaims as A, CnfClaim as C, IdTokenClaims as I, PresentedProofs as P, Verifier as V, AccessTokenExpectations as a, IdTokenExpectations as e, IdTokenVerifier as f, JwksTlsOptions as g, JwksVerifier as h };
@@ -239,6 +239,20 @@ declare function verifyTokenBinding(claims: Pick<AxiamClaims, 'cnf'>, proofs?: P
239
239
  declare function certificateThumbprintS256(der: Uint8Array): Promise<string>;
240
240
  /** Path (relative to the client base URL) of the org-wide JWKS endpoint. */
241
241
  declare const JWKS_PATH = "/oauth2/jwks";
242
+ /**
243
+ * The TLS material the JWKS fetch presents, the same material the REST client
244
+ * uses (CONTRACT.md §6 `customCa`, §6.1 client identity): `ca` extends server
245
+ * trust, `cert`/`key` are the client identity. There is deliberately no
246
+ * verification switch; strict server verification stays at its default.
247
+ */
248
+ interface JwksTlsOptions {
249
+ /** PEM bundle trusted in addition to the default roots (§6). */
250
+ ca?: string;
251
+ /** PEM client-certificate chain (§6.1). */
252
+ cert?: string;
253
+ /** PEM private key for `cert` (§6.1). Secret: never logged or retained. */
254
+ key?: string;
255
+ }
242
256
  /**
243
257
  * Clock-skew leeway applied to the `exp` and `nbf` checks (CONTRACT.md §10.1
244
258
  * rule 7).
@@ -291,6 +305,9 @@ interface Verifier {
291
305
  * | 6 | `aud` | checked only when `expectedAudience` is supplied. |
292
306
  * | 7 | clock skew | {@link CLOCK_SKEW_LEEWAY_SEC}, passed as `clockTolerance`. |
293
307
  * | 9 | `cnf` | (contract 1.51 fix) `proofs` defaults to `{}` — no evidence — so a token carrying `cnf` is refused unless the caller supplies matching evidence. Enforced by handing the verified claims and `proofs` to {@link verifyTokenBinding}, the same function {@link verifyCertificateBinding}, `authenticateRequest` and a hand-rolled guard share, so local verification never disagrees with itself about whether a token is a bearer token. An unbound token is unaffected whether or not `proofs` is supplied. |
308
+ * | 10 | `typ` | (contract 1.68) a header `typ` that is present must be `at+jwt` (case-insensitive, `application/` allowed); `JWT`, `logout+jwt`, `secevent+jwt` and every `axiam-…+jwt` purpose type are refused. No `typ` is not refused by this rule. See `isAccessTokenTyp` (exported from `axiam-sdk/node`). |
309
+ * | 11 | `purpose` | (contract 1.68) a payload carrying a `purpose` member is refused, whatever its value. |
310
+ * | 12 | `kid` | (contract 1.68) a header with no `kid` is refused before any key lookup — there is no "only key in the set" fallback on this path. An unknown `kid` follows the §12.4 rule 2 re-fetch window. |
294
311
  *
295
312
  * **`proofs` and which entry point to call.** This method is the SDK's
296
313
  * documented §10 guard entry point (see {@link verifySignatureOnlyUnchecked}),
@@ -365,23 +382,61 @@ interface JwksVerifier extends Verifier, IdTokenVerifier {
365
382
  * Build a verifier bound to `{baseUrl}/oauth2/jwks`.
366
383
  *
367
384
  * `jose` is loaded lazily via dynamic `import()` (Pitfall 1 — CJS-safe); the
368
- * remote JWKS itself is also fetched/cached lazily by `jose`, not eagerly
369
- * here.
385
+ * remote JWKS itself is fetched/cached lazily by {@link JwksCache}, not
386
+ * eagerly here.
370
387
  *
371
388
  * For the relying-party (§12) flow use {@link createJwksVerifier} with the
372
389
  * `jwks_uri` the discovery document advertises instead of hardcoding
373
390
  * {@link JWKS_PATH} — §12.3 rule 6 requires reading the URI from the document.
374
391
  */
375
- declare function createVerifier(baseUrl: string): JwksVerifier;
392
+ declare function createVerifier(baseUrl: string, tlsOptions?: JwksTlsOptions): JwksVerifier;
376
393
  /**
377
394
  * Build a verifier bound to an explicit, absolute JWKS URI — the `jwks_uri`
378
395
  * value taken from the OIDC discovery document (CONTRACT.md §12.3 rule 6).
379
396
  *
380
397
  * Identical machinery to {@link createVerifier}: one lazily-resolved
381
- * `createRemoteJWKSet` singleton per verifier instance, shared by
398
+ * key-set cache per verifier instance, shared by
382
399
  * `verifyAccessToken` and `verifyIdToken`.
400
+ *
401
+ * `tlsOptions` (Node only) is the {@link JwksTlsOptions} the key-set fetch
402
+ * presents — pass the client's `customCa` / client identity so a private-CA
403
+ * server's JWKS is reachable (#175). Omitted, the platform defaults apply.
404
+ * A client identity (`cert`/`key`) given here is presented to WHATEVER origin
405
+ * `jwksUri` names; the SDK's own callers withhold it from a `jwks_uri` on a
406
+ * different origin than the client's base URL, a direct caller must do the same.
407
+ */
408
+ declare function createJwksVerifier(jwksUri: string, tlsOptions?: JwksTlsOptions): JwksVerifier;
409
+ /**
410
+ * CONTRACT.md §10.1 rules 10 and 12 (contract 1.68; N14) — the header half of
411
+ * "this token is an access token": the JOSE header MUST carry a non-empty
412
+ * `kid` (no single-key fallback), and a `typ` that is present MUST satisfy
413
+ * {@link isAccessTokenTyp}.
414
+ *
415
+ * Exported so the §10 guard (`authenticateRequest`) re-asserts it on its own
416
+ * side, as it does rule 4, without trusting a caller-supplied {@link Verifier}
417
+ * to have applied it. Decodes the header without verifying anything else.
418
+ *
419
+ * @throws AuthError when the token is not a three-segment JWS with a JSON
420
+ * header, carries no `kid`, or carries a `typ` other than `at+jwt`.
421
+ */
422
+ declare function assertAccessTokenHeader(token: string): void;
423
+ /**
424
+ * CONTRACT.md §10.1 rule 11 (contract 1.68; N14): a claim set carrying a
425
+ * `purpose` member is a purpose token (MFA challenge, MFA setup, WebAuthn
426
+ * state), never an access token — whatever the value, `null` included, and
427
+ * whatever `typ` said. Pass the verified payload itself, not a claims model
428
+ * that may drop unknown members.
429
+ *
430
+ * @throws AuthError when `payload` has an own `purpose` member.
431
+ */
432
+ declare function assertNoPurposeClaim(payload: object): void;
433
+ /**
434
+ * CONTRACT.md §10.1 rule 10 (contract 1.68): whether a JOSE `typ` names an
435
+ * access token — `at+jwt` (RFC 9068 §2.1), compared ASCII case-insensitively,
436
+ * with or without the `application/` media-type prefix (RFC 7515 §4.1.9),
437
+ * exactly as the server compares it. A non-string `typ` is not one.
383
438
  */
384
- declare function createJwksVerifier(jwksUri: string): JwksVerifier;
439
+ declare function isAccessTokenTyp(typ: unknown): boolean;
385
440
  /**
386
441
  * CONTRACT.md §10.1 rule 4 — assert the token's `tenant_id` claim against the
387
442
  * tenant the relying party is configured for.
@@ -397,5 +452,5 @@ declare function createJwksVerifier(jwksUri: string): JwksVerifier;
397
452
  */
398
453
  declare function assertTenantClaim(claim: unknown, expected: string | undefined): void;
399
454
 
400
- export { JWKS_PATH as J, MAX_CLOCK_SKEW_SEC as M, CLOCK_SKEW_LEEWAY_SEC as b, createVerifier as c, ID_TOKEN_ALG as d, assertTenantClaim as h, certificateThumbprintS256 as i, createJwksVerifier as j, verifyTokenBinding as k, verifyCertificateBinding as v };
401
- export type { AxiamClaims as A, CnfClaim as C, IdTokenClaims as I, PresentedProofs as P, Verifier as V, AccessTokenExpectations as a, IdTokenExpectations as e, IdTokenVerifier as f, JwksVerifier as g };
455
+ export { JWKS_PATH as J, MAX_CLOCK_SKEW_SEC as M, CLOCK_SKEW_LEEWAY_SEC as b, createVerifier as c, ID_TOKEN_ALG as d, assertAccessTokenHeader as i, assertNoPurposeClaim as j, assertTenantClaim as k, certificateThumbprintS256 as l, createJwksVerifier as m, isAccessTokenTyp as n, verifyTokenBinding as o, verifyCertificateBinding as v };
456
+ export type { AxiamClaims as A, CnfClaim as C, IdTokenClaims as I, PresentedProofs as P, Verifier as V, AccessTokenExpectations as a, IdTokenExpectations as e, IdTokenVerifier as f, JwksTlsOptions as g, JwksVerifier as h };
@@ -1,41 +1,71 @@
1
1
  import { Request, RequestHandler, Router } from 'express';
2
- import { a as AuthzLogger, E as ErrorBody, b as AxiamIdentity, V as VerifiableSession, A as AuthzVerifiableSession, c as ResourceSpec, R as RequireAccessOptions } from '../authzCore-CqXzLNmT.cjs';
3
- export { d as AuthzChecker, C as CheckOutcome, e as ResourceParamRef, f as ResourceResolutionError, g as ResourceResolver, U as UmaChallenger, h as UmaTicketMinter, i as assertAuthzClient, j as authenticateRequest, k as evaluateAccess, l as fromParam, m as hasAnyRole, r as resolveResourceId } from '../authzCore-CqXzLNmT.cjs';
4
- import { R as OidcClient, Y as OidcStateStore, Z as OidcTokenSet, X as OidcStateEntry } from '../oidcState-EnEJmoF5.cjs';
5
- export { a as AuthorizationRequest, c as CibaAwaitParams, d as CibaClock, e as CibaDelivery, f as CibaInitiateParams, g as CibaInitiateResponse, h as CibaPingHeaders, i as CibaPollParams, j as CibaRequestSigner, k as CibaSignerDescription, l as CibaSigningAlg, m as CibaSigningKey, n as CibaUserHint, r as DeviceAuthorization, s as DeviceAuthorizeParams, t as DeviceLoginParams, u as DevicePollParams, E as ExchangedToken, F as FederationProvider, v as FederationProviderList, H as HANDOFF_CODE_TTL_SECS, w as HANDOFF_QUERY_PARAM, I as IntrospectParams, x as IntrospectionResult, L as LoginClientCredentialsParams, y as LoginWithProviderIdTokenOptions, z as LogoutUrlParams, G as MIN_DISCOVERY_TTL_MS, K as MemoryOidcStateStore, N as MtlsEndpointAliases, O as OIDC_STATE_TTL_MS, Q as OidcBeginParams, S as OidcClientOptions, T as OidcConfiguration, U as OidcExchangeParams, V as OidcParParams, W as OidcRefreshParams, _ as PROTOCOL_OAUTH2, $ as PROTOCOL_OIDC_CONNECT, a0 as PROTOCOL_SAML, a3 as PushedAuthorizationRequest, a4 as RequestedPermission, a5 as RequestingPartyToken, a6 as ResourceSet, a7 as RevokeParams, ah as SsoCompleteHandoffParams, ai as SsoCompleteOauth2Params, aj as SsoCompleteParams, ak as SsoCompleteResult, al as SsoProvidersParams, am as SsoStartOauth2Params, an as SsoStartParams, ao as SsoStartResult, aq as TokenExchangeParams, av as UmaExchangeTicketParams, aw as VerifiedLogoutToken, ax as createOidcClient, ay as isAccessDenied, az as isExpiredToken } from '../oidcState-EnEJmoF5.cjs';
2
+ import { a as AuthzLogger, E as ErrorBody, b as AxiamIdentity, V as VerifiableSession, A as AuthzVerifiableSession, c as ResourceSpec, R as RequireAccessOptions } from '../authzCore-Des2NcKA.cjs';
3
+ export { d as AuthzChecker, C as CheckOutcome, e as ResourceParamRef, f as ResourceResolutionError, g as ResourceResolver, U as UmaChallenger, h as UmaTicketMinter, i as assertAuthzClient, j as authenticateRequest, k as evaluateAccess, l as fromParam, m as hasAnyRole, n as hasAnyScope, r as resolveResourceId } from '../authzCore-Des2NcKA.cjs';
4
+ import { S as OidcClient, Z as OidcStateStore, _ as OidcTokenSet, Y as OidcStateEntry } from '../oidcState-XOYEMQP6.cjs';
5
+ export { a as AuthorizationRequest, c as CibaAwaitParams, d as CibaClock, e as CibaDelivery, f as CibaInitiateParams, g as CibaInitiateResponse, h as CibaPingHeaders, i as CibaPollParams, j as CibaRequestSigner, k as CibaSignerDescription, l as CibaSigningAlg, m as CibaSigningKey, n as CibaUserHint, r as DeviceAuthorization, s as DeviceAuthorizeParams, t as DeviceLoginParams, u as DevicePollParams, E as ExchangedToken, F as FederationProvider, v as FederationProviderList, H as HANDOFF_CODE_TTL_SECS, w as HANDOFF_QUERY_PARAM, I as IntrospectParams, x as IntrospectionResult, L as LoginClientCredentialsParams, y as LoginWithProviderIdTokenOptions, z as LogoutUrlParams, G as MIN_DISCOVERY_TTL_MS, K as MemoryOidcStateStore, N as MtlsEndpointAliases, O as OIDC_STATE_MAX_ENTRIES, Q as OIDC_STATE_TTL_MS, R as OidcBeginParams, T as OidcClientOptions, U as OidcConfiguration, V as OidcExchangeParams, W as OidcParParams, X as OidcRefreshParams, $ as PROTOCOL_OAUTH2, a0 as PROTOCOL_OIDC_CONNECT, a1 as PROTOCOL_SAML, a4 as PushedAuthorizationRequest, a5 as RequestedPermission, a6 as RequestingPartyToken, a7 as ResourceSet, a8 as RevokeParams, ai as SsoCompleteHandoffParams, aj as SsoCompleteOauth2Params, ak as SsoCompleteParams, al as SsoCompleteResult, am as SsoProvidersParams, an as SsoStartOauth2Params, ao as SsoStartParams, ap as SsoStartResult, ar as TokenExchangeParams, aw as UmaExchangeTicketParams, ax as VerifiedLogoutToken, ay as createOidcClient, az as isAccessDenied, aA as isExpiredToken } from '../oidcState-XOYEMQP6.cjs';
6
6
  import { FastifyRequest, FastifyReply, FastifyPluginAsync, FastifyInstance } from 'fastify';
7
7
  export { F as FieldError, V as ValidationError } from '../errors-DHauOsqx.cjs';
8
- import { P as PresentedProofs } from '../jwks-CTVpOWzI.cjs';
9
- export { a as AccessTokenExpectations, A as AxiamClaims, b as CLOCK_SKEW_LEEWAY_SEC, C as CnfClaim, I as IdTokenClaims, V as Verifier, h as assertTenantClaim, i as certificateThumbprintS256, v as verifyCertificateBinding, k as verifyTokenBinding } from '../jwks-CTVpOWzI.cjs';
8
+ import { P as PresentedProofs } from '../jwks-CQtWokVd.cjs';
9
+ export { a as AccessTokenExpectations, A as AxiamClaims, b as CLOCK_SKEW_LEEWAY_SEC, C as CnfClaim, I as IdTokenClaims, V as Verifier, k as assertTenantClaim, l as certificateThumbprintS256, v as verifyCertificateBinding, o as verifyTokenBinding } from '../jwks-CQtWokVd.cjs';
10
10
  export { D as DEFAULT_POLL_INTERVAL_MS, M as MAX_ENTRIES, a as MIN_POLL_INTERVAL_MS, R as RevocationFeed, b as RevocationFeedOptions } from '../revocationFeed-KQhvMMl8.cjs';
11
11
  import '../sensitive-BC_s7Rrd.cjs';
12
12
  import '../types-zXSpiQM-.cjs';
13
13
  import 'node:crypto';
14
14
  import '../errors-CWlh-wcm.cjs';
15
- import '../session-CeIUXgpE.cjs';
15
+ import '../session-DoQzoChX.cjs';
16
16
  import 'axios';
17
17
  import '../telemetry-Du0-zS5f.cjs';
18
18
 
19
- /** Configuration shared by the login and callback handlers (CONTRACT.md §12). */
20
- interface OidcLoginOptions {
19
+ /**
20
+ * Configuration shared by the login and callback handlers (CONTRACT.md §12).
21
+ *
22
+ * @typeParam TRequest - the framework's request type, handed to
23
+ * {@link OidcLoginOptions.onSuccess} (§12.8 rule 2). Express's
24
+ * `oidcLoginHandlers` fixes it to Express's `Request`, Fastify's
25
+ * `oidcLoginPlugin` to `FastifyRequest`. A plain `OidcLoginOptions` (the
26
+ * default, `unknown`) is accepted by both.
27
+ */
28
+ interface OidcLoginOptions<TRequest = unknown> {
21
29
  /** The relying-party client driving the flow (built with `createOidcClient`). */
22
30
  client: OidcClient;
23
31
  /**
24
32
  * Where in-flight login state is parked between the login redirect and the
25
33
  * callback. {@link MemoryOidcStateStore} is a ready single-process
26
- * implementation; a multi-instance deployment needs a shared one.
34
+ * implementation; a multi-instance deployment needs a shared one, and that
35
+ * store MUST persist and return {@link OidcStateEntry.bindingDigest}
36
+ * unchanged (§12.3 rule 1) or every callback is refused.
27
37
  */
28
38
  store: OidcStateStore;
29
39
  /**
30
40
  * The relying party's redirect URI — must be the public URL of the callback
31
41
  * route, and is replayed verbatim on the token exchange (the server compares
32
42
  * the two).
43
+ *
44
+ * It also selects the browser-binding cookie's name (§12.8 rule 1 (b)):
45
+ * `__Host-axiam_oidc_bind` everywhere, except `axiam_oidc_bind` (without
46
+ * `Secure`) when it is plain `http:` on a loopback host (`localhost`,
47
+ * `127.0.0.1`, `[::1]`), where a browser would not store a `Secure` cookie.
33
48
  */
34
49
  redirectUri: string;
35
50
  /** Requested scope. `openid` is added automatically when absent (§12.1 rule 4). */
36
51
  scope?: string | string[];
37
- /** Where to send the browser after a successful login. Falls back to the `returnTo` captured at login time, then to a JSON summary. */
52
+ /**
53
+ * Where to send the browser after a successful login. Falls back to the
54
+ * `returnTo` captured at login time — only when it passes the §12.8 rule 3
55
+ * check — then to a JSON summary.
56
+ */
38
57
  successRedirect?: string;
58
+ /**
59
+ * Optional widening of the `returnTo` rule (CONTRACT.md §12.8 rule 3).
60
+ *
61
+ * By default a `returnTo` is followed only when it is a same-origin relative
62
+ * path ({@link isSafeReturnTo}). This predicate is consulted — at login and
63
+ * again before the redirect — **only** for a value the default rule refuses,
64
+ * and the value is honoured only when it returns `true`: for example an
65
+ * allowlist of the application's other origins. Never pass a predicate that
66
+ * accepts arbitrary absolute URLs; that reopens the open redirect.
67
+ */
68
+ allowReturnTo?: (value: string) => boolean;
39
69
  /**
40
70
  * Called with the validated token set once the exchange succeeds — the hook
41
71
  * where an application establishes its OWN session (sign a cookie, write a
@@ -43,12 +73,31 @@ interface OidcLoginOptions {
43
73
  * session means is the application's decision.
44
74
  *
45
75
  * Receives the consumed state entry too, so `returnTo` and any other
46
- * application data captured at login time is available.
76
+ * application data captured at login time is available, and (contract 1.68,
77
+ * §12.8 rule 2) the framework request that completed the sign-in, so the
78
+ * session can be created on it without ambient context. It runs only after
79
+ * the browser binding and every §12.4 ID-token check have passed.
47
80
  */
48
- onSuccess?: (tokens: OidcTokenSet, entry: OidcStateEntry) => void | Promise<void>;
49
- /** Debug-only logger. Receives failure reasons, never token material, `state`, `nonce` or the verifier. */
81
+ onSuccess?: (tokens: OidcTokenSet, entry: OidcStateEntry, request: TRequest) => void | Promise<void>;
82
+ /** Debug-only logger. Receives failure reasons, never token material, `state`, `nonce`, the verifier or the binding cookie. */
50
83
  logger?: AuthzLogger;
51
84
  }
85
+ /**
86
+ * What the callback adapter hands {@link completeOidcLogin} besides the query:
87
+ * the request-side inputs the framework-neutral core cannot read itself
88
+ * (CONTRACT.md §12.8 rule 1 (f)).
89
+ */
90
+ interface OidcCallbackContext<TRequest = unknown> {
91
+ /**
92
+ * The value of the browser-binding cookie the callback request presented —
93
+ * the cookie named by {@link oidcBindingCookieName} for the configured
94
+ * `redirectUri`, and only that name. Absent means no cookie: the callback is
95
+ * refused with the uniform 401.
96
+ */
97
+ bindingCookie?: string;
98
+ /** The framework request, passed through to `onSuccess` (§12.8 rule 2). */
99
+ request?: TRequest;
100
+ }
52
101
  /**
53
102
  * What a login/callback handler should do next — one arm per response shape.
54
103
  * Adapters translate this into their framework's API and add nothing of their
@@ -59,11 +108,15 @@ type OidcLoginOutcome = {
59
108
  kind: 'redirect';
60
109
  /** Target of the redirect: the IdP authorization URL, or the post-login destination. */
61
110
  url: string;
111
+ /** A complete `Set-Cookie` header value the adapter MUST send with this response (§12.8 rule 1). */
112
+ setCookie?: string;
62
113
  } | {
63
114
  /** Reply `200` with {@link body} — the fallback when no post-login redirect is configured. */
64
115
  kind: 'json';
65
116
  /** A token-free summary of the established login. */
66
117
  body: OidcLoginSuccessBody;
118
+ /** A complete `Set-Cookie` header value the adapter MUST send with this response (§12.8 rule 1). */
119
+ setCookie?: string;
67
120
  } | {
68
121
  /** Reply {@link status} with the standardized `{ error, message }` body. */
69
122
  kind: 'error';
@@ -71,6 +124,8 @@ type OidcLoginOutcome = {
71
124
  status: number;
72
125
  /** Standardized error body (§10/§11 shape). */
73
126
  body: ErrorBody;
127
+ /** A complete `Set-Cookie` header value the adapter MUST send with this response (§12.8 rule 1). */
128
+ setCookie?: string;
74
129
  };
75
130
  /** The token-free success summary returned when no post-login redirect is configured. */
76
131
  interface OidcLoginSuccessBody {
@@ -92,6 +147,52 @@ interface OidcCallbackQuery {
92
147
  /** The IdP's description of {@link error}. */
93
148
  error_description?: string;
94
149
  }
150
+ /**
151
+ * The browser-binding cookie name on every `https:` redirect URI, and on plain
152
+ * HTTP to any host that is not loopback (CONTRACT.md §12.8 rule 1 (a)).
153
+ */
154
+ declare const OIDC_BINDING_COOKIE_NAME = "__Host-axiam_oidc_bind";
155
+ /**
156
+ * The browser-binding cookie name used ONLY for a plain-HTTP loopback
157
+ * `redirectUri` (`http://localhost`, `http://127.0.0.1`, `http://[::1]`), where
158
+ * a browser will not store the `Secure` cookie the `__Host-` prefix requires
159
+ * (CONTRACT.md §12.8 rule 1 (b)). Never selected off loopback.
160
+ */
161
+ declare const OIDC_BINDING_COOKIE_NAME_LOOPBACK = "axiam_oidc_bind";
162
+ /**
163
+ * The browser-binding cookie name for `redirectUri` (CONTRACT.md §12.8 rule 1
164
+ * (b)): {@link OIDC_BINDING_COOKIE_NAME_LOOPBACK} for plain HTTP on a loopback
165
+ * host, {@link OIDC_BINDING_COOKIE_NAME} everywhere else. The login sets, and
166
+ * the callback reads, the name this returns — and only that name.
167
+ */
168
+ declare function oidcBindingCookieName(redirectUri: string): string;
169
+ /**
170
+ * The clearing `Set-Cookie` header value every callback response carries
171
+ * (§12.8 rule 1 (d)): the binding cookie's name for `redirectUri`, an empty
172
+ * value, `Max-Age=0`, and the same `Path=/`, `HttpOnly`, `SameSite=Lax` and
173
+ * (except on a plain-HTTP loopback `redirectUri`) `Secure` attributes it was
174
+ * set with, and no `Domain`. A browser honours a clear only when the name and
175
+ * those attributes repeat exactly, so a direct caller of {@link completeOidcLogin}
176
+ * must send this value rather than build one by hand.
177
+ *
178
+ * The Express and Fastify adapters send it themselves when
179
+ * {@link completeOidcLogin} throws (the store or `onSuccess` failed), so the
180
+ * error response clears the cookie too.
181
+ */
182
+ declare function oidcBindingClearCookie(redirectUri: string): string;
183
+ /**
184
+ * The default `returnTo` rule (CONTRACT.md §12.8 rule 3; C6): `true` only for
185
+ * a same-origin relative path — it starts with a single `/`, does not start
186
+ * with `//` or `/\`, and contains no `\` anywhere and no control character
187
+ * (U+0000–U+001F, U+007F). Absolute URLs (`https://…`), scheme-relative ones
188
+ * (`//host/…`) and backslash forms (`/\host`, `/a\b`) are all refused.
189
+ *
190
+ * Both framework adapters reach it through {@link beginOidcLogin} (which drops
191
+ * a refused value before storing) and {@link completeOidcLogin} (which checks
192
+ * the stored value again before redirecting), so Express and Fastify share one
193
+ * implementation.
194
+ */
195
+ declare function isSafeReturnTo(value: string): boolean;
95
196
  /**
96
197
  * Step 1 — build the authorization request, park its state, and hand back the
97
198
  * redirect (CONTRACT.md §12.1 `oidc_begin`).
@@ -100,26 +201,54 @@ interface OidcCallbackQuery {
100
201
  * single-flight de-duplication apply and a busy login route does not hammer
101
202
  * the discovery endpoint (§12.3 rule 6).
102
203
  *
204
+ * **Browser binding (contract 1.68, §12.8 rule 1 (a)).** Every login draws a
205
+ * fresh 32-byte CSPRNG value, stores its SHA-256 on the entry as
206
+ * {@link OidcStateEntry.bindingDigest}, and returns the value in the redirect
207
+ * outcome's `setCookie`, which the adapter MUST send. A cookie the request
208
+ * already presents is never reused.
209
+ *
103
210
  * @param options the shared login configuration.
104
- * @param returnTo optional application destination to restore after login;
105
- * stored with the state entry and used as the post-login redirect when
106
- * `successRedirect` is unset.
211
+ * @param returnTo optional application destination to restore after login.
212
+ * Stored only when it passes {@link isSafeReturnTo} (or
213
+ * {@link OidcLoginOptions.allowReturnTo}); any other value is dropped, as if
214
+ * none had been given (§12.8 rule 3).
107
215
  */
108
- declare function beginOidcLogin(options: OidcLoginOptions, returnTo?: string): Promise<OidcLoginOutcome>;
216
+ declare function beginOidcLogin<TRequest = unknown>(options: OidcLoginOptions<TRequest>, returnTo?: string): Promise<OidcLoginOutcome>;
109
217
  /**
110
- * Step 2 — validate the callback, consume the stored state, exchange the code,
111
- * and hand back the post-login response (CONTRACT.md §12.1 `oidc_exchange`).
218
+ * Step 2 — validate the callback, consume the stored state, check the browser
219
+ * binding, exchange the code, and hand back the post-login response
220
+ * (CONTRACT.md §12.1 `oidc_exchange`, §12.8).
221
+ *
222
+ * Order (§12.8 rule 1 (c)): the entry is consumed FIRST, so `state` stays
223
+ * single-use whatever happens next; then the presented binding cookie's
224
+ * SHA-256 is compared in constant time with the entry's digest; only then is
225
+ * the code exchanged and `onSuccess` called. Every outcome carries a
226
+ * `setCookie` that clears the binding cookie (rule 1 (d)).
112
227
  *
113
228
  * Failure mapping:
114
229
  * - IdP returned `error=…` instead of a code → `401 authentication_failed`;
115
230
  * - `state` or `code` missing → `400 invalid_request`;
116
- * - `state` unknown, already consumed, or expired → `401 authentication_failed`
117
- * (all three are deliberately indistinguishable to the client);
231
+ * - `state` unknown, already consumed, or expired; no binding cookie; an entry
232
+ * with no `bindingDigest`; or a different cookie → `401
233
+ * authentication_failed` with ONE body, so the refusal does not say which
234
+ * check failed, and with no request to the token endpoint;
118
235
  * - any §12.4 ID-token failure or `OAuthProtocolError` (an `AuthError`
119
236
  * sub-type) → `401 authentication_failed`;
120
237
  * - `NetworkError` → `503 oidc_unavailable`, never a silent success.
238
+ *
239
+ * Errors that are not a login outcome — `options.store.consume` rejects, or
240
+ * `options.onSuccess` throws — propagate unchanged to the caller, so the
241
+ * application's own error handling sees them. The state is already consumed
242
+ * by then. The caller MUST still clear the binding cookie on the error
243
+ * response it sends (rule 1 (d), "and any other error"), with the
244
+ * `Set-Cookie` value {@link oidcBindingClearCookie} returns for the same
245
+ * `redirectUri`; the Express and Fastify adapters append it before re-throwing.
246
+ *
247
+ * @param context the presented binding cookie and the framework request. A
248
+ * caller that passes no `bindingCookie` has every callback refused (rule 1
249
+ * (f)).
121
250
  */
122
- declare function completeOidcLogin(options: OidcLoginOptions, query: OidcCallbackQuery): Promise<OidcLoginOutcome>;
251
+ declare function completeOidcLogin<TRequest = unknown>(options: OidcLoginOptions<TRequest>, query: OidcCallbackQuery, context?: OidcCallbackContext<TRequest>): Promise<OidcLoginOutcome>;
123
252
 
124
253
  /** An Express `Request` augmented with the AXIAM identity that `axiamMiddleware` injects after §10 verification. */
125
254
  interface AxiamRequest extends Request {
@@ -175,11 +304,21 @@ declare function requireAuth(session: VerifiableSession): RequestHandler;
175
304
  */
176
305
  declare function requireAccess(session: AuthzVerifiableSession, action: string, resource: ResourceSpec<Request>, opts?: RequireAccessOptions): RequestHandler;
177
306
  /**
178
- * `requireRole(session, ...roles)` (CONTRACT.md §11.1, MAY) — a local
179
- * (no server round-trip) check that the authenticated identity's `roles`
180
- * (from `req.axiamUser`, itself derived from the verified token's `scope`
181
- * claim) contain at least one of `roles`. Cheaper but coarser than
182
- * `requireAccess`; NOT a substitute for a resource-level check.
307
+ * `requireRole(session, ...roles)` (CONTRACT.md §11.1, MAY; §11.2 rule 11) —
308
+ * a local (no server round-trip) check that the verified token's **`roles`
309
+ * claim** (`req.axiamUser.roles`) contains at least one of `roles`, by exact,
310
+ * case-sensitive equality. Cheaper but coarser than `requireAccess`; NOT a
311
+ * substitute for a resource-level check.
312
+ *
313
+ * **Request the `roles` scope (contract 1.68).** The server puts a `roles`
314
+ * claim — the subject's global role names in the tenant — in an access token
315
+ * only when the client requested, and is registered for, the `roles` scope.
316
+ * Without it the token has no `roles` claim and every `requireRole` answers
317
+ * 403: the check fails closed and never reads `scope`. Through 1.3.x this
318
+ * helper matched OAuth2 scopes (N15); a route that relied on that should use
319
+ * {@link requireScope}. The claim is a snapshot taken when the token was
320
+ * minted (stale for at most one access-token lifetime); `requireAccess`
321
+ * evaluates live and stays the authoritative check.
183
322
  *
184
323
  * `session` is taken first for signature parity with
185
324
  * `requireAuth`/`requireAccess` (every §11 helper does). The role check itself
@@ -187,6 +326,18 @@ declare function requireAccess(session: AuthzVerifiableSession, action: string,
187
326
  * guard's own 401 carries the same challenge every other 401 does.
188
327
  */
189
328
  declare function requireRole(session: VerifiableSession, ...roles: string[]): RequestHandler;
329
+ /**
330
+ * `requireScope(session, ...scopes)` (CONTRACT.md §11.1, contract 1.68; §11.2
331
+ * rule 11 (d)) — a local (no server round-trip) check that the verified
332
+ * token's `scope` claim (`req.axiamUser.scopes`) contains at least one of
333
+ * `scopes`, each compared as a whole entry by exact, case-sensitive equality.
334
+ * A route that needs several stacks the helper. 401 when no identity is
335
+ * present (mount `axiamMiddleware`/`requireAuth` first), 403 on failure and
336
+ * when the token has no `scope` claim. A scope says what the *client* was
337
+ * granted, not what the user holds — use {@link requireRole} or
338
+ * `requireAccess` for that.
339
+ */
340
+ declare function requireScope(session: VerifiableSession, ...scopes: string[]): RequestHandler;
190
341
  /**
191
342
  * `oidcLoginHandlers(options)` (CONTRACT.md §12) — the two Express route
192
343
  * handlers an application needs for "Login with AXIAM": a `login` handler that
@@ -200,15 +351,28 @@ declare function requireRole(session: VerifiableSession, ...roles: string[]): Re
200
351
  * (`oidcLoginPlugin`) also uses — so the two frameworks cannot drift on flow
201
352
  * semantics or error mapping.
202
353
  *
354
+ * **Browser binding (CONTRACT.md §12.8, contract 1.68).** The `login` handler
355
+ * sets the `__Host-axiam_oidc_bind` cookie (`axiam_oidc_bind` on a plain-HTTP
356
+ * loopback `redirectUri`) and the `callback` handler completes the sign-in only
357
+ * for a request presenting that same cookie, so a callback link replayed into
358
+ * another browser — login CSRF — answers the uniform 401 without exchanging the
359
+ * code or calling `onSuccess`. Every callback response clears the cookie. Two
360
+ * sign-ins started at once in one browser: the later one wins and the earlier
361
+ * callback is refused. The routes must be served over HTTPS (or plain HTTP on
362
+ * loopback in development) for the browser to keep the cookie.
363
+ *
203
364
  * The `login` handler reads an optional `?returnTo=` query parameter and
204
- * stores it with the login state, so the callback can send the user back where
205
- * they started. **Validate or allowlist that value in your own application if
206
- * you accept it from user input** — an unchecked `returnTo` is an open-redirect
207
- * vector, and the SDK cannot know which destinations your app considers safe.
365
+ * stores it with the login state **only when it is a same-origin relative
366
+ * path** (one leading `/`, not `//` or `/\`, no backslash or control
367
+ * character); the callback checks it again before redirecting. Anything else —
368
+ * an absolute URL, a scheme-relative `//host` — is dropped, and the callback
369
+ * falls back to `successRedirect` or the JSON summary. Widen the rule, for
370
+ * example to an allowlist of your other origins, with `allowReturnTo`.
208
371
  *
209
372
  * Establishing your application's own session is the `onSuccess` hook's job:
210
- * the SDK validates the login and hands you the token set, but what a session
211
- * means (a signed cookie, a database row, a JWT of your own) is your decision.
373
+ * the SDK validates the login and hands you the token set, the consumed entry
374
+ * and the Express `Request` that completed it, but what a session means (a
375
+ * signed cookie, a database row, a JWT of your own) is your decision.
212
376
  *
213
377
  * @example
214
378
  * ```ts
@@ -219,14 +383,14 @@ declare function requireRole(session: VerifiableSession, ...roles: string[]): Re
219
383
  * store,
220
384
  * redirectUri: 'https://app.example.com/auth/callback',
221
385
  * scope: 'openid profile email',
222
- * onSuccess: (tokens) => { myAppSession.establish(tokens.idClaims!.sub); },
386
+ * onSuccess: (tokens, _entry, req) => { myAppSession.establish(req, tokens.idClaims!.sub); },
223
387
  * });
224
388
  *
225
389
  * app.get('/auth/login', login);
226
390
  * app.get('/auth/callback', callback);
227
391
  * ```
228
392
  */
229
- declare function oidcLoginHandlers(options: OidcLoginOptions): {
393
+ declare function oidcLoginHandlers(options: OidcLoginOptions<Request>): {
230
394
  /** `GET` handler that redirects the browser to the AXIAM authorization endpoint. */
231
395
  login: RequestHandler;
232
396
  /** `GET` handler for the redirect URI: consumes `state`, exchanges `code`, validates the ID token. */
@@ -272,12 +436,23 @@ declare function requireAccessHook(session: AuthzVerifiableSession, action: stri
272
436
  /**
273
437
  * `requireRoleHook(session, ...roles)` (CONTRACT.md §11.1, MAY) — the
274
438
  * Fastify `preHandler` counterpart to `requireRole`; see that function's
275
- * doc for the full semantics (local-only check, no server round-trip).
439
+ * doc for the full semantics (local-only check, no server round-trip). It
440
+ * reads only the token's `roles` claim and fails closed (403) when the token
441
+ * has none — the application must request the `roles` scope (contract 1.68,
442
+ * §11.2 rule 11); it never reads `scope`, for which see `requireScopeHook`.
276
443
  * `session` is taken first for signature parity with
277
444
  * `requireAuthHook`/`requireAccessHook`; the role check reads nothing from it,
278
445
  * and §28.5 is the only thing that does.
279
446
  */
280
447
  declare function requireRoleHook(session: VerifiableSession, ...roles: string[]): PreHandlerHook;
448
+ /**
449
+ * `requireScopeHook(session, ...scopes)` (CONTRACT.md §11.1, contract 1.68) —
450
+ * the Fastify `preHandler` counterpart to `requireScope`: a local check that
451
+ * the verified token's `scope` claim contains at least one of `scopes` (whole
452
+ * entries, exact and case-sensitive). 401 without an identity, 403 on failure
453
+ * and when the token has no `scope` claim.
454
+ */
455
+ declare function requireScopeHook(session: VerifiableSession, ...scopes: string[]): PreHandlerHook;
281
456
  /** Route paths the {@link oidcLoginPlugin} registers, relative to where it is registered. */
282
457
  interface OidcLoginRoutePaths {
283
458
  /** Path of the login-redirect route. Defaults to `/auth/login`. */
@@ -295,8 +470,10 @@ interface OidcLoginRoutePaths {
295
470
  * The Fastify counterpart of Express's `oidcLoginHandlers`, built on the same
296
471
  * {@link beginOidcLogin} / {@link completeOidcLogin} core, so the two
297
472
  * frameworks cannot drift on flow semantics or error mapping. See
298
- * `oidcLoginHandlers` for the `returnTo` open-redirect caveat and the
299
- * `onSuccess` session-establishment contract, which apply identically here.
473
+ * `oidcLoginHandlers` for the browser binding (`__Host-axiam_oidc_bind`,
474
+ * CONTRACT.md §12.8), the same-origin `returnTo` rule and `allowReturnTo`, and
475
+ * the `onSuccess` session-establishment contract, which apply identically
476
+ * here — `onSuccess` receives the `FastifyRequest` that completed the sign-in.
300
477
  *
301
478
  * Unlike `axiamPlugin` this plugin is deliberately **encapsulated** (no
302
479
  * `skip-override` marker): it registers routes rather than a hook, so there is
@@ -308,11 +485,11 @@ interface OidcLoginRoutePaths {
308
485
  * client: oidc,
309
486
  * store: new MemoryOidcStateStore(),
310
487
  * redirectUri: 'https://app.example.com/auth/callback',
311
- * onSuccess: (tokens) => { myAppSession.establish(tokens.idClaims!.sub); },
488
+ * onSuccess: (tokens, _entry, request) => { myAppSession.establish(request, tokens.idClaims!.sub); },
312
489
  * }));
313
490
  * ```
314
491
  */
315
- declare const oidcLoginPlugin: (options: OidcLoginOptions & OidcLoginRoutePaths) => FastifyPluginAsync;
492
+ declare const oidcLoginPlugin: (options: OidcLoginOptions<FastifyRequest> & OidcLoginRoutePaths) => FastifyPluginAsync;
316
493
 
317
494
  /**
318
495
  * RFC 9728 §3.1's well-known prefix — the segment inserted between a
@@ -662,5 +839,5 @@ declare function isSafeMethod(method: string | undefined): boolean;
662
839
  */
663
840
  declare function isCsrfValid(cookieHeader: string | undefined, csrfHeaderValue: string | undefined): boolean;
664
841
 
665
- export { ACCESS_COOKIE_NAME, AuthzLogger, AuthzVerifiableSession, AxiamIdentity, CSRF_COOKIE_NAME, CSRF_HEADER_NAME, ErrorBody, OidcClient, OidcStateEntry, OidcStateStore, OidcTokenSet, PROTECTED_RESOURCE_METADATA_PREFIX, PresentedProofs, RequireAccessOptions, ResourceSpec, VerifiableSession, axiamMiddleware, axiamPlugin, bearerChallenge, beginOidcLogin, certificateProofFromSocket, completeOidcLogin, extractCredential, extractToken, isCsrfValid, isSafeMethod, oidcLoginHandlers, oidcLoginPlugin, parseCookieHeader, protectedResourceMetadata, requireAccess, requireAccessHook, requireAuth, requireAuthHook, requireRole, requireRoleHook, serveProtectedResourceMetadata };
666
- export type { AxiamFastifyRequest, AxiamRequest, BearerChallengeError, BearerChallengeOptions, CredentialSource, ExtractedCredential, McpGuardConfig, McpMetadataApp, OidcCallbackQuery, OidcLoginOptions, OidcLoginOutcome, OidcLoginRoutePaths, OidcLoginSuccessBody, PeerCertificateLike, PeerCertificateSocket, PreHandlerHook, ProtectedResourceMetadata, ProtectedResourceMetadataDocument, ProtectedResourceMetadataOptions };
842
+ export { ACCESS_COOKIE_NAME, AuthzLogger, AuthzVerifiableSession, AxiamIdentity, CSRF_COOKIE_NAME, CSRF_HEADER_NAME, ErrorBody, OIDC_BINDING_COOKIE_NAME, OIDC_BINDING_COOKIE_NAME_LOOPBACK, OidcClient, OidcStateEntry, OidcStateStore, OidcTokenSet, PROTECTED_RESOURCE_METADATA_PREFIX, PresentedProofs, RequireAccessOptions, ResourceSpec, VerifiableSession, axiamMiddleware, axiamPlugin, bearerChallenge, beginOidcLogin, certificateProofFromSocket, completeOidcLogin, extractCredential, extractToken, isCsrfValid, isSafeMethod, isSafeReturnTo, oidcBindingClearCookie, oidcBindingCookieName, oidcLoginHandlers, oidcLoginPlugin, parseCookieHeader, protectedResourceMetadata, requireAccess, requireAccessHook, requireAuth, requireAuthHook, requireRole, requireRoleHook, requireScope, requireScopeHook, serveProtectedResourceMetadata };
843
+ export type { AxiamFastifyRequest, AxiamRequest, BearerChallengeError, BearerChallengeOptions, CredentialSource, ExtractedCredential, McpGuardConfig, McpMetadataApp, OidcCallbackContext, OidcCallbackQuery, OidcLoginOptions, OidcLoginOutcome, OidcLoginRoutePaths, OidcLoginSuccessBody, PeerCertificateLike, PeerCertificateSocket, PreHandlerHook, ProtectedResourceMetadata, ProtectedResourceMetadataDocument, ProtectedResourceMetadataOptions };