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.
- package/README.md +155 -4
- 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-CcTdIf78.d.ts → authzCore-DtSN59if.d.ts} +2 -2
- package/dist/{authzCore-B7GSd3-t.d.cts → authzCore-DuRI1aJf.d.cts} +2 -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 +6 -5
- package/dist/grpc/index.d.ts +6 -5
- package/dist/grpc/index.js +178 -4
- package/dist/grpc/index.js.map +1 -1
- package/dist/grpc/index.mjs +178 -4
- 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 +76 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -4
- 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 +194 -4
- package/dist/middleware/index.d.ts +194 -4
- 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 -113
- package/dist/node/index.d.ts +50 -113
- package/dist/node/index.js +873 -4
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +857 -5
- 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 +76 -3
- package/dist/rest/index.js.map +1 -1
- package/dist/rest/index.mjs +71 -4
- 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/{client-Co_baHgU.d.ts → session-BWUWhhyB.d.cts} +1 -70
- package/dist/{client-CzhzwRGg.d.cts → session-BWUWhhyB.d.ts} +1 -70
- package/package.json +2 -2
- package/dist/jwks-B8dPy2c6.d.cts +0 -36
- package/dist/jwks-B8dPy2c6.d.ts +0 -36
- package/dist/sensitive-CWBH_tHr.d.cts +0 -12
- package/dist/sensitive-CWBH_tHr.d.ts +0 -12
|
@@ -1,9 +1,119 @@
|
|
|
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-DtSN59if.js';
|
|
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-DtSN59if.js';
|
|
4
|
+
import { d as OidcClient, j as OidcStateStore, k as OidcTokenSet, i as OidcStateEntry } from '../oidcState-CkFuCjpM.js';
|
|
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-CkFuCjpM.js';
|
|
4
6
|
import { FastifyRequest, FastifyReply, FastifyPluginAsync } from 'fastify';
|
|
5
|
-
export { A as AxiamClaims, V as Verifier } from '../jwks-
|
|
7
|
+
export { A as AxiamClaims, a as IdTokenClaims, V as Verifier } from '../jwks-BgojMGC5.js';
|
|
6
8
|
import '../types-BVkMoqLU.js';
|
|
9
|
+
import '../sensitive-BC_s7Rrd.js';
|
|
10
|
+
import '../session-BWUWhhyB.js';
|
|
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 };
|