axiam-sdk 1.0.0-alpha19 → 1.0.0-alpha21

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 (62) hide show
  1. package/README.md +155 -4
  2. package/dist/amqp/index.d.cts +1 -1
  3. package/dist/amqp/index.d.ts +1 -1
  4. package/dist/amqp/index.js +4 -0
  5. package/dist/amqp/index.js.map +1 -1
  6. package/dist/amqp/index.mjs +4 -0
  7. package/dist/amqp/index.mjs.map +1 -1
  8. package/dist/{authzCore-CcTdIf78.d.ts → authzCore-DtSN59if.d.ts} +2 -2
  9. package/dist/{authzCore-B7GSd3-t.d.cts → authzCore-DuRI1aJf.d.cts} +2 -2
  10. package/dist/client-B_FqmZ0i.d.cts +72 -0
  11. package/dist/client-Dn1fs5MH.d.ts +72 -0
  12. package/dist/cookieJar-BTDnjjbL.d.cts +122 -0
  13. package/dist/cookieJar-Cl8Lq9dL.d.ts +122 -0
  14. package/dist/grpc/index.d.cts +6 -5
  15. package/dist/grpc/index.d.ts +6 -5
  16. package/dist/grpc/index.js +178 -4
  17. package/dist/grpc/index.js.map +1 -1
  18. package/dist/grpc/index.mjs +178 -4
  19. package/dist/grpc/index.mjs.map +1 -1
  20. package/dist/index.d.cts +4 -2
  21. package/dist/index.d.ts +4 -2
  22. package/dist/index.js +76 -3
  23. package/dist/index.js.map +1 -1
  24. package/dist/index.mjs +71 -4
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/jwks-BgojMGC5.d.cts +152 -0
  27. package/dist/jwks-BgojMGC5.d.ts +152 -0
  28. package/dist/middleware/index.d.cts +194 -4
  29. package/dist/middleware/index.d.ts +194 -4
  30. package/dist/middleware/index.js +1107 -1
  31. package/dist/middleware/index.js.map +1 -1
  32. package/dist/middleware/index.mjs +1100 -3
  33. package/dist/middleware/index.mjs.map +1 -1
  34. package/dist/nestjs/index.d.cts +2 -2
  35. package/dist/nestjs/index.d.ts +2 -2
  36. package/dist/nestjs/index.js +3 -0
  37. package/dist/nestjs/index.js.map +1 -1
  38. package/dist/nestjs/index.mjs +3 -0
  39. package/dist/nestjs/index.mjs.map +1 -1
  40. package/dist/node/index.d.cts +50 -113
  41. package/dist/node/index.d.ts +50 -113
  42. package/dist/node/index.js +873 -4
  43. package/dist/node/index.js.map +1 -1
  44. package/dist/node/index.mjs +857 -5
  45. package/dist/node/index.mjs.map +1 -1
  46. package/dist/oidcState-BGxqWUun.d.cts +598 -0
  47. package/dist/oidcState-CkFuCjpM.d.ts +598 -0
  48. package/dist/rest/index.d.cts +107 -5
  49. package/dist/rest/index.d.ts +107 -5
  50. package/dist/rest/index.js +76 -3
  51. package/dist/rest/index.js.map +1 -1
  52. package/dist/rest/index.mjs +71 -4
  53. package/dist/rest/index.mjs.map +1 -1
  54. package/dist/sensitive-BC_s7Rrd.d.cts +39 -0
  55. package/dist/sensitive-BC_s7Rrd.d.ts +39 -0
  56. package/dist/{client-Co_baHgU.d.ts → session-BWUWhhyB.d.cts} +1 -70
  57. package/dist/{client-CzhzwRGg.d.cts → session-BWUWhhyB.d.ts} +1 -70
  58. package/package.json +2 -2
  59. package/dist/jwks-B8dPy2c6.d.cts +0 -36
  60. package/dist/jwks-B8dPy2c6.d.ts +0 -36
  61. package/dist/sensitive-CWBH_tHr.d.cts +0 -12
  62. package/dist/sensitive-CWBH_tHr.d.ts +0 -12
@@ -0,0 +1,152 @@
1
+ /**
2
+ * The decoded, **already-validated** ID-token claim set carried by
3
+ * {@link OidcTokenSet.idClaims} (CONTRACT.md §12.1).
4
+ *
5
+ * @remarks
6
+ * Claim names are kept verbatim in their JWT/OIDC spelling (`iss`, `sub`,
7
+ * `aud`, …) rather than camelCased: they are protocol identifiers a caller
8
+ * cross-references against OIDC Core, exactly as {@link AxiamClaims} already
9
+ * does for access-token claims. The open index signature is mandated by
10
+ * §12.1 — the ID token's full claim set is not enumerated by `openapi.json`,
11
+ * so unknown claims MUST be preserved and MUST NOT be rejected.
12
+ */
13
+ interface IdTokenClaims {
14
+ /** Issuer — matched for exact string equality against the discovery document's `issuer` (§12.4 rule 3). */
15
+ iss: string;
16
+ /** Subject — the authenticated end user's stable identifier at AXIAM. */
17
+ sub: string;
18
+ /** Audience — contains the relying party's `client_id` (§12.4 rule 4). */
19
+ aud: string | string[];
20
+ /** Expiry time (epoch seconds). */
21
+ exp: number;
22
+ /** Issued-at time (epoch seconds). */
23
+ iat: number;
24
+ /** Not-before time (epoch seconds), when the server sends one. */
25
+ nbf?: number;
26
+ /** The `nonce` echoed back from the authorization request (§12.4 rule 6). */
27
+ nonce?: string;
28
+ /** Authorized party — required to equal `client_id` when `aud` holds multiple audiences (§12.4 rule 4). */
29
+ azp?: string;
30
+ /** Any further claim the server sends (e.g. `email`, `preferred_username`) — preserved, never rejected (§12.1). */
31
+ [claim: string]: unknown;
32
+ }
33
+ /**
34
+ * What an ID token is checked against by {@link IdTokenVerifier.verifyIdToken}
35
+ * (CONTRACT.md §12.4 rules 3–6).
36
+ */
37
+ interface IdTokenExpectations {
38
+ /**
39
+ * The authoritative issuer — always the `issuer` value of the discovery
40
+ * document the token endpoint was read from, never the client base URL
41
+ * (§12.3 rule 6: behind a proxy the two legitimately differ).
42
+ */
43
+ issuer: string;
44
+ /** The relying party's own `client_id`, matched against `aud`/`azp` (rule 4). */
45
+ clientId: string;
46
+ /**
47
+ * The `nonce` returned by `oidcBegin` and passed back into `oidcExchange`.
48
+ *
49
+ * Mandatory for `oidcExchange`. Left `undefined` by `oidcRefresh` and
50
+ * `loginClientCredentials`, which skip rule 6 entirely — OIDC Core §12.2
51
+ * does not require a `nonce` in a refresh-issued ID token.
52
+ */
53
+ nonce?: string;
54
+ /**
55
+ * Permitted clock skew in seconds for `exp`/`iat`/`nbf` (rule 5). Defaults
56
+ * to {@link MAX_CLOCK_SKEW_SEC} and is clamped to it — the contract forbids
57
+ * configuring it *above* 60 s, so a larger value is silently reduced rather
58
+ * than honoured.
59
+ */
60
+ clockSkewSec?: number;
61
+ }
62
+ /**
63
+ * Maximum (and default) permitted clock skew in seconds for ID-token time
64
+ * claims. CONTRACT.md §12.4 rule 5 caps this at 60 s and forbids any
65
+ * configuration above the bound.
66
+ */
67
+ declare const MAX_CLOCK_SKEW_SEC = 60;
68
+ /** Reject the JOSE header `alg` unless it is exactly `EdDSA` (§12.4 rule 1). */
69
+ declare const ID_TOKEN_ALG = "EdDSA";
70
+
71
+ /** Verified claims carried by an AXIAM access token (the JWT payload {@link Verifier.verifyAccessToken} returns). */
72
+ interface AxiamClaims {
73
+ /** Subject — user ID (UUID). */
74
+ sub: string;
75
+ /** Tenant ID (UUID). */
76
+ tenant_id: string;
77
+ /** Organization ID (UUID), if present. */
78
+ org_id?: string;
79
+ /** Issuer — the AXIAM authorization server that minted the token. */
80
+ iss: string;
81
+ /** Issued-at time (epoch seconds), if present. */
82
+ iat?: number;
83
+ /** Expiry time (epoch seconds); the verifier rejects the token once it has passed. */
84
+ exp: number;
85
+ /** Unique token ID / session id — needed for logout(). */
86
+ jti?: string;
87
+ /** Token audience — "axiam:user" | "axiam:m2m". */
88
+ aud?: string;
89
+ /** OAuth2 scopes (space-separated). */
90
+ scope?: string;
91
+ }
92
+ /** Path (relative to the client base URL) of the org-wide JWKS endpoint. */
93
+ declare const JWKS_PATH = "/oauth2/jwks";
94
+ /** Verifies an AXIAM access token's EdDSA signature against the org-wide remote JWKS. */
95
+ interface Verifier {
96
+ /** Verify `token` against the cached JWKS (EdDSA only) and return its claims; rejects any invalid/expired/wrong-algorithm token. */
97
+ verifyAccessToken(token: string): Promise<AxiamClaims>;
98
+ }
99
+ /**
100
+ * The relying-party half of the same verifier (CONTRACT.md §12.4): validates
101
+ * an OIDC **ID token** rather than an AXIAM access token.
102
+ *
103
+ * @remarks
104
+ * Kept as its own interface, and *added* to the object {@link createVerifier}
105
+ * returns rather than to {@link Verifier} itself, so existing code that
106
+ * implements `Verifier` (e.g. a hand-rolled test double supplied as
107
+ * `VerifiableSession.jwksVerifier`) keeps compiling — contract 1.4 is
108
+ * additive.
109
+ */
110
+ interface IdTokenVerifier {
111
+ /**
112
+ * Validate an OIDC ID token per CONTRACT.md §12.4 and return its claims.
113
+ *
114
+ * Enforces rule 1 (`alg` MUST be `EdDSA`, read from the header *before* any
115
+ * signature work — `none` and every other algorithm rejected), rule 2
116
+ * (Ed25519 signature against the key selected by `kid`, with the single
117
+ * JWKS re-fetch policy §10 already implements), then rules 3–6 via
118
+ * {@link checkIdTokenClaims}. Rejects with `AuthError` carrying the
119
+ * matching §12.3 reason code on the first failure.
120
+ */
121
+ verifyIdToken(token: string, expectations: IdTokenExpectations): Promise<IdTokenClaims>;
122
+ }
123
+ /**
124
+ * The concrete verifier {@link createVerifier} / {@link createJwksVerifier}
125
+ * return: one object, one cached remote key set, both the §10 access-token
126
+ * path and the §12.4 ID-token path. §12 forbids a second verifier.
127
+ */
128
+ interface JwksVerifier extends Verifier, IdTokenVerifier {
129
+ }
130
+ /**
131
+ * Build a verifier bound to `{baseUrl}/oauth2/jwks`.
132
+ *
133
+ * `jose` is loaded lazily via dynamic `import()` (Pitfall 1 — CJS-safe); the
134
+ * remote JWKS itself is also fetched/cached lazily by `jose`, not eagerly
135
+ * here.
136
+ *
137
+ * For the relying-party (§12) flow use {@link createJwksVerifier} with the
138
+ * `jwks_uri` the discovery document advertises instead of hardcoding
139
+ * {@link JWKS_PATH} — §12.3 rule 6 requires reading the URI from the document.
140
+ */
141
+ declare function createVerifier(baseUrl: string): JwksVerifier;
142
+ /**
143
+ * Build a verifier bound to an explicit, absolute JWKS URI — the `jwks_uri`
144
+ * value taken from the OIDC discovery document (CONTRACT.md §12.3 rule 6).
145
+ *
146
+ * Identical machinery to {@link createVerifier}: one lazily-resolved
147
+ * `createRemoteJWKSet` singleton per verifier instance, shared by
148
+ * `verifyAccessToken` and `verifyIdToken`.
149
+ */
150
+ declare function createJwksVerifier(jwksUri: string): JwksVerifier;
151
+
152
+ export { type AxiamClaims as A, ID_TOKEN_ALG as I, JWKS_PATH as J, MAX_CLOCK_SKEW_SEC as M, type Verifier as V, type IdTokenClaims as a, type IdTokenExpectations as b, type IdTokenVerifier as c, type JwksVerifier as d, createJwksVerifier as e, createVerifier as f };
@@ -0,0 +1,152 @@
1
+ /**
2
+ * The decoded, **already-validated** ID-token claim set carried by
3
+ * {@link OidcTokenSet.idClaims} (CONTRACT.md §12.1).
4
+ *
5
+ * @remarks
6
+ * Claim names are kept verbatim in their JWT/OIDC spelling (`iss`, `sub`,
7
+ * `aud`, …) rather than camelCased: they are protocol identifiers a caller
8
+ * cross-references against OIDC Core, exactly as {@link AxiamClaims} already
9
+ * does for access-token claims. The open index signature is mandated by
10
+ * §12.1 — the ID token's full claim set is not enumerated by `openapi.json`,
11
+ * so unknown claims MUST be preserved and MUST NOT be rejected.
12
+ */
13
+ interface IdTokenClaims {
14
+ /** Issuer — matched for exact string equality against the discovery document's `issuer` (§12.4 rule 3). */
15
+ iss: string;
16
+ /** Subject — the authenticated end user's stable identifier at AXIAM. */
17
+ sub: string;
18
+ /** Audience — contains the relying party's `client_id` (§12.4 rule 4). */
19
+ aud: string | string[];
20
+ /** Expiry time (epoch seconds). */
21
+ exp: number;
22
+ /** Issued-at time (epoch seconds). */
23
+ iat: number;
24
+ /** Not-before time (epoch seconds), when the server sends one. */
25
+ nbf?: number;
26
+ /** The `nonce` echoed back from the authorization request (§12.4 rule 6). */
27
+ nonce?: string;
28
+ /** Authorized party — required to equal `client_id` when `aud` holds multiple audiences (§12.4 rule 4). */
29
+ azp?: string;
30
+ /** Any further claim the server sends (e.g. `email`, `preferred_username`) — preserved, never rejected (§12.1). */
31
+ [claim: string]: unknown;
32
+ }
33
+ /**
34
+ * What an ID token is checked against by {@link IdTokenVerifier.verifyIdToken}
35
+ * (CONTRACT.md §12.4 rules 3–6).
36
+ */
37
+ interface IdTokenExpectations {
38
+ /**
39
+ * The authoritative issuer — always the `issuer` value of the discovery
40
+ * document the token endpoint was read from, never the client base URL
41
+ * (§12.3 rule 6: behind a proxy the two legitimately differ).
42
+ */
43
+ issuer: string;
44
+ /** The relying party's own `client_id`, matched against `aud`/`azp` (rule 4). */
45
+ clientId: string;
46
+ /**
47
+ * The `nonce` returned by `oidcBegin` and passed back into `oidcExchange`.
48
+ *
49
+ * Mandatory for `oidcExchange`. Left `undefined` by `oidcRefresh` and
50
+ * `loginClientCredentials`, which skip rule 6 entirely — OIDC Core §12.2
51
+ * does not require a `nonce` in a refresh-issued ID token.
52
+ */
53
+ nonce?: string;
54
+ /**
55
+ * Permitted clock skew in seconds for `exp`/`iat`/`nbf` (rule 5). Defaults
56
+ * to {@link MAX_CLOCK_SKEW_SEC} and is clamped to it — the contract forbids
57
+ * configuring it *above* 60 s, so a larger value is silently reduced rather
58
+ * than honoured.
59
+ */
60
+ clockSkewSec?: number;
61
+ }
62
+ /**
63
+ * Maximum (and default) permitted clock skew in seconds for ID-token time
64
+ * claims. CONTRACT.md §12.4 rule 5 caps this at 60 s and forbids any
65
+ * configuration above the bound.
66
+ */
67
+ declare const MAX_CLOCK_SKEW_SEC = 60;
68
+ /** Reject the JOSE header `alg` unless it is exactly `EdDSA` (§12.4 rule 1). */
69
+ declare const ID_TOKEN_ALG = "EdDSA";
70
+
71
+ /** Verified claims carried by an AXIAM access token (the JWT payload {@link Verifier.verifyAccessToken} returns). */
72
+ interface AxiamClaims {
73
+ /** Subject — user ID (UUID). */
74
+ sub: string;
75
+ /** Tenant ID (UUID). */
76
+ tenant_id: string;
77
+ /** Organization ID (UUID), if present. */
78
+ org_id?: string;
79
+ /** Issuer — the AXIAM authorization server that minted the token. */
80
+ iss: string;
81
+ /** Issued-at time (epoch seconds), if present. */
82
+ iat?: number;
83
+ /** Expiry time (epoch seconds); the verifier rejects the token once it has passed. */
84
+ exp: number;
85
+ /** Unique token ID / session id — needed for logout(). */
86
+ jti?: string;
87
+ /** Token audience — "axiam:user" | "axiam:m2m". */
88
+ aud?: string;
89
+ /** OAuth2 scopes (space-separated). */
90
+ scope?: string;
91
+ }
92
+ /** Path (relative to the client base URL) of the org-wide JWKS endpoint. */
93
+ declare const JWKS_PATH = "/oauth2/jwks";
94
+ /** Verifies an AXIAM access token's EdDSA signature against the org-wide remote JWKS. */
95
+ interface Verifier {
96
+ /** Verify `token` against the cached JWKS (EdDSA only) and return its claims; rejects any invalid/expired/wrong-algorithm token. */
97
+ verifyAccessToken(token: string): Promise<AxiamClaims>;
98
+ }
99
+ /**
100
+ * The relying-party half of the same verifier (CONTRACT.md §12.4): validates
101
+ * an OIDC **ID token** rather than an AXIAM access token.
102
+ *
103
+ * @remarks
104
+ * Kept as its own interface, and *added* to the object {@link createVerifier}
105
+ * returns rather than to {@link Verifier} itself, so existing code that
106
+ * implements `Verifier` (e.g. a hand-rolled test double supplied as
107
+ * `VerifiableSession.jwksVerifier`) keeps compiling — contract 1.4 is
108
+ * additive.
109
+ */
110
+ interface IdTokenVerifier {
111
+ /**
112
+ * Validate an OIDC ID token per CONTRACT.md §12.4 and return its claims.
113
+ *
114
+ * Enforces rule 1 (`alg` MUST be `EdDSA`, read from the header *before* any
115
+ * signature work — `none` and every other algorithm rejected), rule 2
116
+ * (Ed25519 signature against the key selected by `kid`, with the single
117
+ * JWKS re-fetch policy §10 already implements), then rules 3–6 via
118
+ * {@link checkIdTokenClaims}. Rejects with `AuthError` carrying the
119
+ * matching §12.3 reason code on the first failure.
120
+ */
121
+ verifyIdToken(token: string, expectations: IdTokenExpectations): Promise<IdTokenClaims>;
122
+ }
123
+ /**
124
+ * The concrete verifier {@link createVerifier} / {@link createJwksVerifier}
125
+ * return: one object, one cached remote key set, both the §10 access-token
126
+ * path and the §12.4 ID-token path. §12 forbids a second verifier.
127
+ */
128
+ interface JwksVerifier extends Verifier, IdTokenVerifier {
129
+ }
130
+ /**
131
+ * Build a verifier bound to `{baseUrl}/oauth2/jwks`.
132
+ *
133
+ * `jose` is loaded lazily via dynamic `import()` (Pitfall 1 — CJS-safe); the
134
+ * remote JWKS itself is also fetched/cached lazily by `jose`, not eagerly
135
+ * here.
136
+ *
137
+ * For the relying-party (§12) flow use {@link createJwksVerifier} with the
138
+ * `jwks_uri` the discovery document advertises instead of hardcoding
139
+ * {@link JWKS_PATH} — §12.3 rule 6 requires reading the URI from the document.
140
+ */
141
+ declare function createVerifier(baseUrl: string): JwksVerifier;
142
+ /**
143
+ * Build a verifier bound to an explicit, absolute JWKS URI — the `jwks_uri`
144
+ * value taken from the OIDC discovery document (CONTRACT.md §12.3 rule 6).
145
+ *
146
+ * Identical machinery to {@link createVerifier}: one lazily-resolved
147
+ * `createRemoteJWKSet` singleton per verifier instance, shared by
148
+ * `verifyAccessToken` and `verifyIdToken`.
149
+ */
150
+ declare function createJwksVerifier(jwksUri: string): JwksVerifier;
151
+
152
+ export { type AxiamClaims as A, ID_TOKEN_ALG as I, JWKS_PATH as J, MAX_CLOCK_SKEW_SEC as M, type Verifier as V, type IdTokenClaims as a, type IdTokenExpectations as b, type IdTokenVerifier as c, type JwksVerifier as d, createJwksVerifier as e, createVerifier as f };
@@ -1,9 +1,119 @@
1
1
  import { Request, RequestHandler } from 'express';
2
- import { A as AxiamIdentity, V as VerifiableSession, a as AuthzVerifiableSession, R as ResourceSpec, b as RequireAccessOptions } from '../authzCore-B7GSd3-t.cjs';
3
- export { c as AuthzChecker, d as AuthzLogger, C as CheckOutcome, E as ErrorBody, e as ResourceParamRef, f as ResourceResolutionError, g as ResourceResolver, h as assertAuthzClient, i as authenticateRequest, j as evaluateAccess, k as fromParam, l as hasAnyRole, r as resolveResourceId } from '../authzCore-B7GSd3-t.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-DuRI1aJf.cjs';
3
+ export { d as AuthzChecker, C as CheckOutcome, e as ResourceParamRef, f as ResourceResolutionError, g as ResourceResolver, h as assertAuthzClient, i as authenticateRequest, j as evaluateAccess, k as fromParam, l as hasAnyRole, r as resolveResourceId } from '../authzCore-DuRI1aJf.cjs';
4
+ import { d as OidcClient, j as OidcStateStore, k as OidcTokenSet, i as OidcStateEntry } from '../oidcState-BGxqWUun.cjs';
5
+ export { A as AuthorizationRequest, I as IntrospectParams, a as IntrospectionResult, L as LoginClientCredentialsParams, M as MIN_DISCOVERY_TTL_MS, b as MemoryOidcStateStore, O as OIDC_STATE_TTL_MS, c as OidcBeginParams, e as OidcClientOptions, f as OidcConfiguration, g as OidcExchangeParams, h as OidcRefreshParams, R as RevokeParams, m as SsoCompleteParams, n as SsoCompleteResult, o as SsoStartParams, p as SsoStartResult, q as createOidcClient } from '../oidcState-BGxqWUun.cjs';
4
6
  import { FastifyRequest, FastifyReply, FastifyPluginAsync } from 'fastify';
5
- export { A as AxiamClaims, V as Verifier } from '../jwks-B8dPy2c6.cjs';
7
+ export { A as AxiamClaims, a as IdTokenClaims, V as Verifier } from '../jwks-BgojMGC5.cjs';
6
8
  import '../types-BVkMoqLU.cjs';
9
+ import '../sensitive-BC_s7Rrd.cjs';
10
+ import '../session-BWUWhhyB.cjs';
11
+ import 'axios';
12
+
13
+ /** Configuration shared by the login and callback handlers (CONTRACT.md §12). */
14
+ interface OidcLoginOptions {
15
+ /** The relying-party client driving the flow (built with `createOidcClient`). */
16
+ client: OidcClient;
17
+ /**
18
+ * Where in-flight login state is parked between the login redirect and the
19
+ * callback. {@link MemoryOidcStateStore} is a ready single-process
20
+ * implementation; a multi-instance deployment needs a shared one.
21
+ */
22
+ store: OidcStateStore;
23
+ /**
24
+ * The relying party's redirect URI — must be the public URL of the callback
25
+ * route, and is replayed verbatim on the token exchange (the server compares
26
+ * the two).
27
+ */
28
+ redirectUri: string;
29
+ /** Requested scope. `openid` is added automatically when absent (§12.1 rule 4). */
30
+ scope?: string | string[];
31
+ /** Where to send the browser after a successful login. Falls back to the `returnTo` captured at login time, then to a JSON summary. */
32
+ successRedirect?: string;
33
+ /**
34
+ * Called with the validated token set once the exchange succeeds — the hook
35
+ * where an application establishes its OWN session (sign a cookie, write a
36
+ * session row, …). The SDK deliberately does not do this for you: what a
37
+ * session means is the application's decision.
38
+ *
39
+ * Receives the consumed state entry too, so `returnTo` and any other
40
+ * application data captured at login time is available.
41
+ */
42
+ onSuccess?: (tokens: OidcTokenSet, entry: OidcStateEntry) => void | Promise<void>;
43
+ /** Debug-only logger. Receives failure reasons, never token material, `state`, `nonce` or the verifier. */
44
+ logger?: AuthzLogger;
45
+ }
46
+ /**
47
+ * What a login/callback handler should do next — one arm per response shape.
48
+ * Adapters translate this into their framework's API and add nothing of their
49
+ * own, so Express and Fastify cannot drift.
50
+ */
51
+ type OidcLoginOutcome = {
52
+ /** Send a 302 to {@link url}. */
53
+ kind: 'redirect';
54
+ /** Target of the redirect: the IdP authorization URL, or the post-login destination. */
55
+ url: string;
56
+ } | {
57
+ /** Reply `200` with {@link body} — the fallback when no post-login redirect is configured. */
58
+ kind: 'json';
59
+ /** A token-free summary of the established login. */
60
+ body: OidcLoginSuccessBody;
61
+ } | {
62
+ /** Reply {@link status} with the standardized `{ error, message }` body. */
63
+ kind: 'error';
64
+ /** HTTP status: 400 malformed callback, 401 authentication failure, 503 AXIAM unreachable. */
65
+ status: number;
66
+ /** Standardized error body (§10/§11 shape). */
67
+ body: ErrorBody;
68
+ };
69
+ /** The token-free success summary returned when no post-login redirect is configured. */
70
+ interface OidcLoginSuccessBody {
71
+ /** Always `true` — the ID token validated and the login completed. */
72
+ authenticated: true;
73
+ /** The authenticated subject from the validated ID token, when the server issued one. */
74
+ sub?: string;
75
+ /** Access-token lifetime in seconds, for a caller sizing its own session. */
76
+ expiresIn: number;
77
+ }
78
+ /** The callback query parameters the flow reads (RFC 6749 §4.1.2 / §4.1.2.1). */
79
+ interface OidcCallbackQuery {
80
+ /** The `state` the IdP echoed back — matched against the stored entry. */
81
+ state?: string;
82
+ /** The authorization code, on success. */
83
+ code?: string;
84
+ /** An RFC 6749 error code, when the IdP refused instead of issuing a code. */
85
+ error?: string;
86
+ /** The IdP's description of {@link error}. */
87
+ error_description?: string;
88
+ }
89
+ /**
90
+ * Step 1 — build the authorization request, park its state, and hand back the
91
+ * redirect (CONTRACT.md §12.1 `oidc_begin`).
92
+ *
93
+ * Discovery is fetched through `oidcDiscover`, so its per-origin cache and
94
+ * single-flight de-duplication apply and a busy login route does not hammer
95
+ * the discovery endpoint (§12.3 rule 6).
96
+ *
97
+ * @param options the shared login configuration.
98
+ * @param returnTo optional application destination to restore after login;
99
+ * stored with the state entry and used as the post-login redirect when
100
+ * `successRedirect` is unset.
101
+ */
102
+ declare function beginOidcLogin(options: OidcLoginOptions, returnTo?: string): Promise<OidcLoginOutcome>;
103
+ /**
104
+ * Step 2 — validate the callback, consume the stored state, exchange the code,
105
+ * and hand back the post-login response (CONTRACT.md §12.1 `oidc_exchange`).
106
+ *
107
+ * Failure mapping:
108
+ * - IdP returned `error=…` instead of a code → `401 authentication_failed`;
109
+ * - `state` or `code` missing → `400 invalid_request`;
110
+ * - `state` unknown, already consumed, or expired → `401 authentication_failed`
111
+ * (all three are deliberately indistinguishable to the client);
112
+ * - any §12.4 ID-token failure or `OAuthProtocolError` (an `AuthError`
113
+ * sub-type) → `401 authentication_failed`;
114
+ * - `NetworkError` → `503 oidc_unavailable`, never a silent success.
115
+ */
116
+ declare function completeOidcLogin(options: OidcLoginOptions, query: OidcCallbackQuery): Promise<OidcLoginOutcome>;
7
117
 
8
118
  /** An Express `Request` augmented with the AXIAM identity that `axiamMiddleware` injects after §10 verification. */
9
119
  interface AxiamRequest extends Request {
@@ -68,6 +178,51 @@ declare function requireAccess(session: AuthzVerifiableSession, action: string,
68
178
  * coarser than `requireAccess`; NOT a substitute for a resource-level check.
69
179
  */
70
180
  declare function requireRole(session: VerifiableSession, ...roles: string[]): RequestHandler;
181
+ /**
182
+ * `oidcLoginHandlers(options)` (CONTRACT.md §12) — the two Express route
183
+ * handlers an application needs for "Login with AXIAM": a `login` handler that
184
+ * redirects the browser to AXIAM's authorization endpoint, and a `callback`
185
+ * handler that consumes the returned `state`, exchanges the code, and
186
+ * validates the ID token.
187
+ *
188
+ * @remarks
189
+ * Both handlers are thin adapters over {@link beginOidcLogin} /
190
+ * {@link completeOidcLogin}, which the Fastify variant
191
+ * (`oidcLoginPlugin`) also uses — so the two frameworks cannot drift on flow
192
+ * semantics or error mapping.
193
+ *
194
+ * The `login` handler reads an optional `?returnTo=` query parameter and
195
+ * stores it with the login state, so the callback can send the user back where
196
+ * they started. **Validate or allowlist that value in your own application if
197
+ * you accept it from user input** — an unchecked `returnTo` is an open-redirect
198
+ * vector, and the SDK cannot know which destinations your app considers safe.
199
+ *
200
+ * Establishing your application's own session is the `onSuccess` hook's job:
201
+ * the SDK validates the login and hands you the token set, but what a session
202
+ * means (a signed cookie, a database row, a JWT of your own) is your decision.
203
+ *
204
+ * @example
205
+ * ```ts
206
+ * const store = new MemoryOidcStateStore();
207
+ * const oidc = createOidcClient(session, { clientId, clientSecret });
208
+ * const { login, callback } = oidcLoginHandlers({
209
+ * client: oidc,
210
+ * store,
211
+ * redirectUri: 'https://app.example.com/auth/callback',
212
+ * scope: 'openid profile email',
213
+ * onSuccess: (tokens) => { myAppSession.establish(tokens.idClaims!.sub); },
214
+ * });
215
+ *
216
+ * app.get('/auth/login', login);
217
+ * app.get('/auth/callback', callback);
218
+ * ```
219
+ */
220
+ declare function oidcLoginHandlers(options: OidcLoginOptions): {
221
+ /** `GET` handler that redirects the browser to the AXIAM authorization endpoint. */
222
+ login: RequestHandler;
223
+ /** `GET` handler for the redirect URI: consumes `state`, exchanges `code`, validates the ID token. */
224
+ callback: RequestHandler;
225
+ };
71
226
 
72
227
  /** A Fastify `FastifyRequest` augmented with the AXIAM identity that `axiamPlugin` injects after §10 verification. */
73
228
  interface AxiamFastifyRequest extends FastifyRequest {
@@ -113,6 +268,41 @@ declare function requireAccessHook(session: AuthzVerifiableSession, action: stri
113
268
  * `requireAuthHook`/`requireAccessHook` — this check never dereferences it.
114
269
  */
115
270
  declare function requireRoleHook(session: VerifiableSession, ...roles: string[]): PreHandlerHook;
271
+ /** Route paths the {@link oidcLoginPlugin} registers, relative to where it is registered. */
272
+ interface OidcLoginRoutePaths {
273
+ /** Path of the login-redirect route. Defaults to `/auth/login`. */
274
+ loginPath?: string;
275
+ /** Path of the callback route — must match the public URL in `redirectUri`. Defaults to `/auth/callback`. */
276
+ callbackPath?: string;
277
+ }
278
+ /**
279
+ * `oidcLoginPlugin(options)` (CONTRACT.md §12) — a `FastifyPluginAsync`
280
+ * registering the two "Login with AXIAM" routes: a login-redirect route and
281
+ * the callback route that consumes `state`, exchanges the code, and validates
282
+ * the ID token.
283
+ *
284
+ * @remarks
285
+ * The Fastify counterpart of Express's `oidcLoginHandlers`, built on the same
286
+ * {@link beginOidcLogin} / {@link completeOidcLogin} core, so the two
287
+ * frameworks cannot drift on flow semantics or error mapping. See
288
+ * `oidcLoginHandlers` for the `returnTo` open-redirect caveat and the
289
+ * `onSuccess` session-establishment contract, which apply identically here.
290
+ *
291
+ * Unlike `axiamPlugin` this plugin is deliberately **encapsulated** (no
292
+ * `skip-override` marker): it registers routes rather than a hook, so there is
293
+ * nothing that needs to escape its own context.
294
+ *
295
+ * @example
296
+ * ```ts
297
+ * await fastify.register(oidcLoginPlugin({
298
+ * client: oidc,
299
+ * store: new MemoryOidcStateStore(),
300
+ * redirectUri: 'https://app.example.com/auth/callback',
301
+ * onSuccess: (tokens) => { myAppSession.establish(tokens.idClaims!.sub); },
302
+ * }));
303
+ * ```
304
+ */
305
+ declare const oidcLoginPlugin: (options: OidcLoginOptions & OidcLoginRoutePaths) => FastifyPluginAsync;
116
306
 
117
307
  /**
118
308
  * Parse a raw `Cookie` request header into a name -> value map.
@@ -182,4 +372,4 @@ declare function isSafeMethod(method: string | undefined): boolean;
182
372
  */
183
373
  declare function isCsrfValid(cookieHeader: string | undefined, csrfHeaderValue: string | undefined): boolean;
184
374
 
185
- export { ACCESS_COOKIE_NAME, AuthzVerifiableSession, type AxiamFastifyRequest, AxiamIdentity, type AxiamRequest, CSRF_COOKIE_NAME, CSRF_HEADER_NAME, type CredentialSource, type ExtractedCredential, type PreHandlerHook, RequireAccessOptions, ResourceSpec, VerifiableSession, axiamMiddleware, axiamPlugin, extractCredential, extractToken, isCsrfValid, isSafeMethod, parseCookieHeader, requireAccess, requireAccessHook, requireAuth, requireAuthHook, requireRole, requireRoleHook };
375
+ export { ACCESS_COOKIE_NAME, AuthzLogger, AuthzVerifiableSession, type AxiamFastifyRequest, AxiamIdentity, type AxiamRequest, CSRF_COOKIE_NAME, CSRF_HEADER_NAME, type CredentialSource, ErrorBody, type ExtractedCredential, type OidcCallbackQuery, OidcClient, type OidcLoginOptions, type OidcLoginOutcome, type OidcLoginRoutePaths, type OidcLoginSuccessBody, OidcStateEntry, OidcStateStore, OidcTokenSet, type PreHandlerHook, RequireAccessOptions, ResourceSpec, VerifiableSession, axiamMiddleware, axiamPlugin, beginOidcLogin, completeOidcLogin, extractCredential, extractToken, isCsrfValid, isSafeMethod, oidcLoginHandlers, oidcLoginPlugin, parseCookieHeader, requireAccess, requireAccessHook, requireAuth, requireAuthHook, requireRole, requireRoleHook };