axiam-sdk 1.0.0-alpha2 → 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.
- package/README.md +219 -8
- package/dist/amqp/index.d.cts +1 -1
- package/dist/amqp/index.d.ts +1 -1
- package/dist/amqp/index.js +4 -0
- package/dist/amqp/index.js.map +1 -1
- package/dist/amqp/index.mjs +4 -0
- package/dist/amqp/index.mjs.map +1 -1
- package/dist/{authzCore-xwmCivHH.d.ts → authzCore-DtSN59if.d.ts} +19 -2
- package/dist/{authzCore-CV-Td-V1.d.cts → authzCore-DuRI1aJf.d.cts} +19 -2
- package/dist/client-B_FqmZ0i.d.cts +72 -0
- package/dist/client-Dn1fs5MH.d.ts +72 -0
- package/dist/cookieJar-BTDnjjbL.d.cts +122 -0
- package/dist/cookieJar-Cl8Lq9dL.d.ts +122 -0
- package/dist/grpc/index.d.cts +113 -6
- package/dist/grpc/index.d.ts +113 -6
- package/dist/grpc/index.js +435 -18
- package/dist/grpc/index.js.map +1 -1
- package/dist/grpc/index.mjs +434 -19
- package/dist/grpc/index.mjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +209 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +204 -14
- package/dist/index.mjs.map +1 -1
- package/dist/jwks-BgojMGC5.d.cts +152 -0
- package/dist/jwks-BgojMGC5.d.ts +152 -0
- package/dist/middleware/index.d.cts +208 -8
- package/dist/middleware/index.d.ts +208 -8
- package/dist/middleware/index.js +1107 -1
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/index.mjs +1100 -3
- package/dist/middleware/index.mjs.map +1 -1
- package/dist/nestjs/index.d.cts +2 -2
- package/dist/nestjs/index.d.ts +2 -2
- package/dist/nestjs/index.js +3 -0
- package/dist/nestjs/index.js.map +1 -1
- package/dist/nestjs/index.mjs +3 -0
- package/dist/nestjs/index.mjs.map +1 -1
- package/dist/node/index.d.cts +50 -94
- package/dist/node/index.d.ts +50 -94
- package/dist/node/index.js +1039 -15
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +1023 -16
- package/dist/node/index.mjs.map +1 -1
- package/dist/oidcState-BGxqWUun.d.cts +598 -0
- package/dist/oidcState-CkFuCjpM.d.ts +598 -0
- package/dist/rest/index.d.cts +107 -5
- package/dist/rest/index.d.ts +107 -5
- package/dist/rest/index.js +209 -13
- package/dist/rest/index.js.map +1 -1
- package/dist/rest/index.mjs +204 -14
- package/dist/rest/index.mjs.map +1 -1
- package/dist/sensitive-BC_s7Rrd.d.cts +39 -0
- package/dist/sensitive-BC_s7Rrd.d.ts +39 -0
- package/dist/session-BWUWhhyB.d.cts +154 -0
- package/dist/session-BWUWhhyB.d.ts +154 -0
- package/package.json +2 -2
- package/dist/client-BPg9kfKV.d.ts +0 -150
- package/dist/client-CAeQw1a-.d.cts +0 -150
- package/dist/jwks-CX-nhD6A.d.cts +0 -29
- package/dist/jwks-CX-nhD6A.d.ts +0 -29
- package/dist/sensitive-CWBH_tHr.d.cts +0 -12
- 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 };
|
|
@@ -1,11 +1,123 @@
|
|
|
1
1
|
import { Request, RequestHandler } from 'express';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
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';
|
|
7
|
+
export { A as AxiamClaims, a as IdTokenClaims, V as Verifier } from '../jwks-BgojMGC5.cjs';
|
|
5
8
|
import '../types-BVkMoqLU.cjs';
|
|
6
|
-
import '../
|
|
9
|
+
import '../sensitive-BC_s7Rrd.cjs';
|
|
10
|
+
import '../session-BWUWhhyB.cjs';
|
|
11
|
+
import 'axios';
|
|
7
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>;
|
|
117
|
+
|
|
118
|
+
/** An Express `Request` augmented with the AXIAM identity that `axiamMiddleware` injects after §10 verification. */
|
|
8
119
|
interface AxiamRequest extends Request {
|
|
120
|
+
/** The authenticated identity, present once `axiamMiddleware` (or `requireAuth`) has run; absent on an unauthenticated request. */
|
|
9
121
|
axiamUser?: AxiamIdentity;
|
|
10
122
|
}
|
|
11
123
|
/**
|
|
@@ -66,15 +178,62 @@ declare function requireAccess(session: AuthzVerifiableSession, action: string,
|
|
|
66
178
|
* coarser than `requireAccess`; NOT a substitute for a resource-level check.
|
|
67
179
|
*/
|
|
68
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
|
+
};
|
|
69
226
|
|
|
227
|
+
/** A Fastify `FastifyRequest` augmented with the AXIAM identity that `axiamPlugin` injects after §10 verification. */
|
|
70
228
|
interface AxiamFastifyRequest extends FastifyRequest {
|
|
229
|
+
/** The authenticated identity, present once `axiamPlugin` (or `requireAuthHook`) has run; absent on an unauthenticated request. */
|
|
71
230
|
axiamUser?: AxiamIdentity;
|
|
72
231
|
}
|
|
73
232
|
/** A Fastify `preHandler`-compatible hook function (CONTRACT.md §11) — usable both via `fastify.addHook('preHandler', ...)` and per-route as `{ preHandler: hook }`. */
|
|
74
233
|
type PreHandlerHook = (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
75
234
|
/**
|
|
76
|
-
* `axiamPlugin(session)` — a `FastifyPluginAsync` registering
|
|
77
|
-
*
|
|
235
|
+
* `axiamPlugin(session)` — a `FastifyPluginAsync` registering the shared
|
|
236
|
+
* auth `preHandler` hook globally (D-27, CONTRACT.md
|
|
78
237
|
* §10). Marked with fastify's own `skip-override` plugin symbol (the same
|
|
79
238
|
* mechanism the `fastify-plugin` package wraps) so the `preHandler` hook
|
|
80
239
|
* applies to routes registered as siblings of this plugin rather than
|
|
@@ -88,8 +247,8 @@ declare const axiamPlugin: (session: VerifiableSession) => FastifyPluginAsync;
|
|
|
88
247
|
* `preHandler` function usable per-route:
|
|
89
248
|
* `fastify.get('/x', { preHandler: requireAuthHook(session) }, handler)`,
|
|
90
249
|
* rather than registered globally via `fastify.register(axiamPlugin(session))`.
|
|
91
|
-
* Pure sugar: it performs no verification of its own beyond what
|
|
92
|
-
*
|
|
250
|
+
* Pure sugar: it performs no verification of its own beyond what the shared
|
|
251
|
+
* auth `preHandler` hook (also used by `axiamPlugin`) already does.
|
|
93
252
|
*/
|
|
94
253
|
declare function requireAuthHook(session: VerifiableSession): PreHandlerHook;
|
|
95
254
|
/**
|
|
@@ -109,6 +268,41 @@ declare function requireAccessHook(session: AuthzVerifiableSession, action: stri
|
|
|
109
268
|
* `requireAuthHook`/`requireAccessHook` — this check never dereferences it.
|
|
110
269
|
*/
|
|
111
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;
|
|
112
306
|
|
|
113
307
|
/**
|
|
114
308
|
* Parse a raw `Cookie` request header into a name -> value map.
|
|
@@ -116,6 +310,7 @@ declare function requireRoleHook(session: VerifiableSession, ...roles: string[])
|
|
|
116
310
|
* `=` only (cookie values may themselves contain `=`, e.g. base64/JWT).
|
|
117
311
|
*/
|
|
118
312
|
declare function parseCookieHeader(header: string | undefined): Record<string, string>;
|
|
313
|
+
/** Name of the cookie carrying the AXIAM access token (`axiam_access`). */
|
|
119
314
|
declare const ACCESS_COOKIE_NAME = "axiam_access";
|
|
120
315
|
/**
|
|
121
316
|
* Where an extracted bearer credential came from. Load-bearing for the CSRF
|
|
@@ -126,8 +321,11 @@ declare const ACCESS_COOKIE_NAME = "axiam_access";
|
|
|
126
321
|
* set arbitrary request headers, but the browser will still send cookies.
|
|
127
322
|
*/
|
|
128
323
|
type CredentialSource = 'cookie' | 'header';
|
|
324
|
+
/** A bearer credential together with where it was read from. */
|
|
129
325
|
interface ExtractedCredential {
|
|
326
|
+
/** The raw bearer token value. */
|
|
130
327
|
token: string;
|
|
328
|
+
/** Whether the token came from the `axiam_access` cookie or the `Authorization` header — load-bearing for the CSRF gate (§3). */
|
|
131
329
|
source: CredentialSource;
|
|
132
330
|
}
|
|
133
331
|
/**
|
|
@@ -144,7 +342,9 @@ declare function extractCredential(cookieHeader: string | undefined, authHeader:
|
|
|
144
342
|
* {@link extractCredential} directly.
|
|
145
343
|
*/
|
|
146
344
|
declare function extractToken(cookieHeader: string | undefined, authHeader: string | undefined): string | undefined;
|
|
345
|
+
/** Name of the double-submit CSRF cookie (`axiam_csrf`). */
|
|
147
346
|
declare const CSRF_COOKIE_NAME = "axiam_csrf";
|
|
347
|
+
/** Name of the CSRF request header (`x-csrf-token`) matched against {@link CSRF_COOKIE_NAME}. */
|
|
148
348
|
declare const CSRF_HEADER_NAME = "x-csrf-token";
|
|
149
349
|
/**
|
|
150
350
|
* Whether `method` is a "safe" (non-state-changing) HTTP method per
|
|
@@ -172,4 +372,4 @@ declare function isSafeMethod(method: string | undefined): boolean;
|
|
|
172
372
|
*/
|
|
173
373
|
declare function isCsrfValid(cookieHeader: string | undefined, csrfHeaderValue: string | undefined): boolean;
|
|
174
374
|
|
|
175
|
-
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 };
|