axiam-sdk 1.0.0-alpha24 → 1.0.0-alpha25
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 +416 -3
- package/dist/amqp/index.d.cts +605 -1
- package/dist/amqp/index.d.ts +605 -1
- package/dist/amqp/index.js +491 -0
- package/dist/amqp/index.js.map +1 -1
- package/dist/amqp/index.mjs +461 -2
- package/dist/amqp/index.mjs.map +1 -1
- package/dist/{authzCore-CA9zFm1n.d.cts → authzCore-DQSXszkj.d.ts} +68 -4
- package/dist/{authzCore-a-wZL2P3.d.ts → authzCore-Dzr_x_UK.d.cts} +68 -4
- package/dist/client-C2MEcxjG.d.cts +284 -0
- package/dist/client-YQQcFDTy.d.ts +284 -0
- package/dist/{cookieJar-C9fqLqbh.d.ts → cookieJar-BDeX40ZG.d.ts} +3 -3
- package/dist/{cookieJar-DeJKczxD.d.cts → cookieJar-C8YixLEs.d.cts} +3 -3
- package/dist/grpc/index.d.cts +33 -13
- package/dist/grpc/index.d.ts +33 -13
- package/dist/grpc/index.js +308 -7
- package/dist/grpc/index.js.map +1 -1
- package/dist/grpc/index.mjs +308 -7
- package/dist/grpc/index.mjs.map +1 -1
- package/dist/index.d.cts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +310 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +301 -39
- package/dist/index.mjs.map +1 -1
- package/dist/{jwks-DEiwxlku.d.cts → jwks-CSXHo3DS.d.cts} +145 -1
- package/dist/{jwks-DEiwxlku.d.ts → jwks-CSXHo3DS.d.ts} +145 -1
- package/dist/middleware/index.d.cts +8 -7
- package/dist/middleware/index.d.ts +8 -7
- package/dist/middleware/index.js +651 -5
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/index.mjs +649 -6
- package/dist/middleware/index.mjs.map +1 -1
- package/dist/nestjs/index.d.cts +4 -3
- package/dist/nestjs/index.d.ts +4 -3
- package/dist/nestjs/index.js +6 -3
- package/dist/nestjs/index.js.map +1 -1
- package/dist/nestjs/index.mjs +6 -3
- package/dist/nestjs/index.mjs.map +1 -1
- package/dist/node/index.d.cts +101 -7
- package/dist/node/index.d.ts +101 -7
- package/dist/node/index.js +1124 -12
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +1103 -14
- package/dist/node/index.mjs.map +1 -1
- package/dist/{oidcState-tHRAg5bu.d.cts → oidcState-y6UaPeRx.d.cts} +601 -3
- package/dist/{oidcState-CfebuJ0n.d.ts → oidcState-ziGS0XYP.d.ts} +601 -3
- package/dist/rest/index.d.cts +5 -20
- package/dist/rest/index.d.ts +5 -20
- package/dist/rest/index.js +310 -38
- package/dist/rest/index.js.map +1 -1
- package/dist/rest/index.mjs +301 -39
- package/dist/rest/index.mjs.map +1 -1
- package/dist/{session-ti3C9ZJU.d.cts → session-BJHqprWm.d.ts} +48 -0
- package/dist/{session-ti3C9ZJU.d.ts → session-CMgYRxLP.d.cts} +48 -0
- package/dist/telemetry-DrGqL4kb.d.cts +124 -0
- package/dist/telemetry-DrGqL4kb.d.ts +124 -0
- package/dist/{types-BVkMoqLU.d.cts → types-CO10Ainw.d.cts} +23 -1
- package/dist/{types-BVkMoqLU.d.ts → types-CO10Ainw.d.ts} +23 -1
- package/package.json +1 -1
- package/dist/client-CtT9nHQP.d.cts +0 -72
- package/dist/client-utwuwc9m.d.ts +0 -72
package/README.md
CHANGED
|
@@ -17,9 +17,13 @@ Official TypeScript/JavaScript client SDK for [AXIAM](https://github.com/ilpanic
|
|
|
17
17
|
|
|
18
18
|
## Contract conformance
|
|
19
19
|
|
|
20
|
-
This SDK conforms to CONTRACT.md §1–§13 (including §6.1 mTLS
|
|
21
|
-
§10.1 minimum local-verification set, the §12 OIDC/SSO
|
|
22
|
-
`verifyWebhook` signature verifier).
|
|
20
|
+
This SDK conforms to CONTRACT.md §1–§13 and §12.7, §14, §15, §17, §19, §20, §21, §22 (including §6.1 mTLS
|
|
21
|
+
client certificates, the §10.1 minimum local-verification set, the §12 OIDC/SSO
|
|
22
|
+
relying-party helpers, and the §13 `verifyWebhook` signature verifier).
|
|
23
|
+
|
|
24
|
+
§12.7, §14, §15 and §22 are named rather than folded into the range because they landed
|
|
25
|
+
after this SDK already claimed §1–§13: widening the range silently would turn a statement
|
|
26
|
+
that was true when written into a different claim without anyone editing it.
|
|
23
27
|
|
|
24
28
|
### §10.1 minimum local-verification set
|
|
25
29
|
|
|
@@ -225,6 +229,137 @@ await consume('amqp://localhost:5672', 'axiam.audit.events', signingKey, async (
|
|
|
225
229
|
});
|
|
226
230
|
```
|
|
227
231
|
|
|
232
|
+
### Node — reactors, AMQP extension actors (`axiam-sdk/amqp`, CONTRACT.md §22)
|
|
233
|
+
|
|
234
|
+
A **reactor** is an external process that subscribes to named hook events on the AMQP bus and
|
|
235
|
+
answers back — allow, deny, or a field-allow-listed mutation — inside a timeout the server
|
|
236
|
+
declared. It is AXIAM's answer to Zitadel Actions and Keycloak SPIs, and the difference is the
|
|
237
|
+
whole design: those load third-party code *into* the authorization server, and this keeps it
|
|
238
|
+
outside, reachable only through a signed reply schema the server validates before it believes
|
|
239
|
+
a word of it.
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
import { Sensitive } from 'axiam-sdk/amqp';
|
|
243
|
+
import { REACTOR_EVENTS, allow, deny, mutate, reactorServe } from 'axiam-sdk/amqp';
|
|
244
|
+
|
|
245
|
+
const signingKey = new Sensitive(Buffer.from(process.env.AXIAM_AMQP_SIGNING_KEY_HEX ?? '', 'hex'));
|
|
246
|
+
|
|
247
|
+
await reactorServe(
|
|
248
|
+
{
|
|
249
|
+
amqpUrl: 'amqps://reactor:secret@broker.example.com:5671',
|
|
250
|
+
tenantId: '11111111-1111-1111-1111-111111111111',
|
|
251
|
+
reactorId: '99999999-9999-9999-9999-999999999999',
|
|
252
|
+
signingKey, // the tenant's HKDF-derived AMQP subkey, never the master key
|
|
253
|
+
},
|
|
254
|
+
(event) => {
|
|
255
|
+
switch (event.event) {
|
|
256
|
+
// token.pre_issue is mutable — the `ext.` namespace, and nothing else.
|
|
257
|
+
case REACTOR_EVENTS.TOKEN_PRE_ISSUE:
|
|
258
|
+
return mutate({ 'ext.cost_center': '42' });
|
|
259
|
+
// login.post_auth is veto-only, plus step-up.
|
|
260
|
+
case REACTOR_EVENTS.LOGIN_POST_AUTH:
|
|
261
|
+
return deny('embargoed region');
|
|
262
|
+
default:
|
|
263
|
+
return allow();
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
);
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
See [`examples/reactor/index.ts`](examples/reactor/index.ts) for a complete three-hook reactor
|
|
270
|
+
with graceful shutdown and a telemetry hook.
|
|
271
|
+
|
|
272
|
+
#### The five hookable events, and their allow-lists
|
|
273
|
+
|
|
274
|
+
| Event | Mutable | Complete allow-list | Default failure policy |
|
|
275
|
+
|---|---|---|---|
|
|
276
|
+
| `token.pre_issue` | yes | the **`ext.`** namespace only | `fail_open` |
|
|
277
|
+
| `login.post_auth` | no | — (veto, or `require_mfa`) | `fail_closed` |
|
|
278
|
+
| `user.pre_create` | yes | `username`, `email`, `metadata.` | `fail_closed` |
|
|
279
|
+
| `user.pre_update` | yes | `username`, `email`, `metadata.` | `fail_closed` |
|
|
280
|
+
| `grant.pre_assign` | no | — (veto only) | `fail_closed` |
|
|
281
|
+
|
|
282
|
+
An entry ending in `.` is a **namespace prefix** and needs at least one character after the
|
|
283
|
+
dot: `ext.` admits `ext.department` and `ext.a.b.c`, and refuses `ext.` itself, `ext`, `extra`,
|
|
284
|
+
`external_id` and `evil.ext.department`. So a reactor can never reach `sub`, `aud`, `exp`,
|
|
285
|
+
`scope` or any other standard claim — a **correctly signed** reply setting `sub` is refused
|
|
286
|
+
exactly as a forged one is.
|
|
287
|
+
|
|
288
|
+
Registrations that name no `failure_policy` get **the strictest default among their events**,
|
|
289
|
+
in either array order — `defaultFailurePolicyFor([...])` computes it, and "take the first
|
|
290
|
+
event's default" is specifically what §22.8 forbids, because it lets the order of a JSON array
|
|
291
|
+
decide whether an unreachable fraud check passes.
|
|
292
|
+
|
|
293
|
+
#### `authz.check` is not hookable, and this SDK does not pretend otherwise
|
|
294
|
+
|
|
295
|
+
`authz.check`, `authz.check_batch` and `token.introspect` are absent from `EVENT_REGISTRY`,
|
|
296
|
+
from `REACTOR_EVENTS` and from every example here (§22.7, a normative MUST NOT). A reactor
|
|
297
|
+
round-trip is milliseconds; the check path's budget is microseconds. An application that needs
|
|
298
|
+
external input on an authorization decision writes a **deny grant**, which the engine
|
|
299
|
+
evaluates in the hot path at hot-path cost — and there is deliberately no client-side
|
|
300
|
+
interceptor in this SDK offering itself as the reactor equivalent.
|
|
301
|
+
|
|
302
|
+
#### What the runtime guarantees
|
|
303
|
+
|
|
304
|
+
- **Both directions are signed.** The server signs the event with the tenant's HKDF-derived
|
|
305
|
+
AMQP subkey; the reactor signs its reply with the same key. An unsigned or stale reply is
|
|
306
|
+
not a weak reply — the server discards it as though the reactor had never answered. Every
|
|
307
|
+
event is verified (`key_version >= 2`, MAC, ±300 s freshness, nonce seen-set) *before* your
|
|
308
|
+
handler is called.
|
|
309
|
+
- **Two canonicalization quirks, both of which are silent failures if missed.** First, a
|
|
310
|
+
reactor body signs `hmac_signature` as **`null`**, where §8's own two message types omit it.
|
|
311
|
+
Second — and this one is TypeScript's alone — `Date.prototype.toISOString()` always emits
|
|
312
|
+
three fractional digits, while the server's `chrono` emits none on a whole second; a reply
|
|
313
|
+
timestamped `…T12:00:00.000Z` is re-serialized server-side as `…T12:00:00Z` and its MAC
|
|
314
|
+
fails with no other symptom. `toChronoRfc3339()` is the fix and the runtime always uses it.
|
|
315
|
+
Both are pinned by server-generated vectors rather than by memory — see
|
|
316
|
+
[`testdata/reactor_v2_reference_vectors.json`](testdata/reactor_v2_reference_vectors.json)
|
|
317
|
+
and [`test/amqp/reactor/vectors.test.ts`](test/amqp/reactor/vectors.test.ts).
|
|
318
|
+
- **It declares no topology.** No `assertQueue`, no `assertExchange`, no `bindQueue` — the
|
|
319
|
+
server owns all three, and the `ReactorChannel` seam this runtime is written against does
|
|
320
|
+
not even offer them. A reactor that can bind is a reactor that can bind itself to
|
|
321
|
+
`*.token.pre_issue` and read another tenant's issuance events.
|
|
322
|
+
- **It fails closed on its own errors.** A handler that throws, a body that will not parse, a
|
|
323
|
+
window that has already closed: each publishes **nothing**, so the registration's
|
|
324
|
+
`failure_policy` decides. Synthesizing an `allow` would override the operator's
|
|
325
|
+
`fail_closed` setting from inside the library. `abstain()` is the explicit form of the same
|
|
326
|
+
thing.
|
|
327
|
+
- **It does not filter your patch.** One forbidden key rejects the whole patch server-side;
|
|
328
|
+
pruning it here would leave you believing a field was set when it was dropped. Check
|
|
329
|
+
yourself with `patchFieldAllowed(spec, field)` if you want to know before you send.
|
|
330
|
+
- **It honours `timeout_ms`.** The handler runs inside the window the server declared, and a
|
|
331
|
+
reply whose window has closed is abandoned rather than published late.
|
|
332
|
+
- **Shutdown drains (§18).** Pass an `AbortSignal`; aborting it cancels the consumer, lets
|
|
333
|
+
every dispatch already running finish — handler, signature, publish — and only then closes
|
|
334
|
+
the channel and connection.
|
|
335
|
+
|
|
336
|
+
#### Registering a reactor (§22.9)
|
|
337
|
+
|
|
338
|
+
Registration is a REST admin call, not part of this runtime:
|
|
339
|
+
|
|
340
|
+
```bash
|
|
341
|
+
curl -X POST https://axiam.example.com/api/v1/reactors \
|
|
342
|
+
-H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
|
|
343
|
+
-d '{"name":"fraud-check","events":["login.post_auth"],"mode":"intercept","timeout_ms":500}'
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
The response's `id` is what `reactorId` takes, and the server declares the queue.
|
|
347
|
+
`timeout_ms` defaults to **500** and is refused outside `1…5000`; the chain's wall-clock
|
|
348
|
+
ceiling is **5000 ms** and the per-tenant in-flight cap is **64**. This SDK exposes those as
|
|
349
|
+
constants (`DEFAULT_REACTOR_TIMEOUT_MS`, `MAX_REACTOR_TIMEOUT_MS`,
|
|
350
|
+
`DEFAULT_REACTOR_MAX_IN_FLIGHT`) but ships **no typed client for the CRUD endpoints** — call
|
|
351
|
+
them through the REST client, and let the server validate; §22.9 explicitly warns against
|
|
352
|
+
re-deriving `PUT` merge semantics or the `failure_policy` re-derivation client-side.
|
|
353
|
+
|
|
354
|
+
#### Logging
|
|
355
|
+
|
|
356
|
+
The `payload`, `patch`, `reason` and `decision` are tenant business data — readable by design,
|
|
357
|
+
since a handler that cannot inspect the event cannot decide anything, but this runtime never
|
|
358
|
+
logs them at info level and yours should not either (§22.12). The signing key is
|
|
359
|
+
`Sensitive<Buffer>`, is never logged at any level, and never appears in an error payload.
|
|
360
|
+
`nonce`, `correlation_id` and `hmac_signature` are not secrets and may be logged for
|
|
361
|
+
correlation.
|
|
362
|
+
|
|
228
363
|
### Express middleware (`axiam-sdk/middleware`)
|
|
229
364
|
|
|
230
365
|
```typescript
|
|
@@ -507,6 +642,192 @@ strings.
|
|
|
507
642
|
|
|
508
643
|
See `examples/express-oidc-login.ts` for a complete, runnable example.
|
|
509
644
|
|
|
645
|
+
## Device authorization grant (`axiam-sdk/node`, CONTRACT.md §14)
|
|
646
|
+
|
|
647
|
+
RFC 8628 — signing in a device that cannot show a browser: a TV, a CLI, a headless
|
|
648
|
+
commissioning tool.
|
|
649
|
+
|
|
650
|
+
```ts
|
|
651
|
+
const tokens = await oidc.deviceLogin({
|
|
652
|
+
onUserCode: (auth) => {
|
|
653
|
+
// Called BEFORE the first poll. Display it however the device can —
|
|
654
|
+
// screen, QR code, e-ink panel. The SDK never prints it for you.
|
|
655
|
+
console.log(`visit ${auth.verificationUri} and enter ${auth.userCode}`);
|
|
656
|
+
},
|
|
657
|
+
});
|
|
658
|
+
```
|
|
659
|
+
|
|
660
|
+
`deviceAuthorize` and `devicePoll` are also public, for an application driving its own
|
|
661
|
+
loop. The polling rules are where implementations go wrong, so they are worth stating:
|
|
662
|
+
|
|
663
|
+
- **`slow_down` raises the interval permanently.** An SDK that backs off for one round and
|
|
664
|
+
returns to the original interval will be told to slow down again, forever.
|
|
665
|
+
- **`access_denied` and `expired_token` stay distinct.** A human said no, versus nobody
|
|
666
|
+
answered — the only information the device can act on.
|
|
667
|
+
- **Polling stops at `expires_in`**, even if the server has not yet said `expired_token`.
|
|
668
|
+
- **A `5xx` mid-poll is not terminal.** A server restart must not lose a grant the user has
|
|
669
|
+
already approved.
|
|
670
|
+
|
|
671
|
+
`deviceCode` is `Sensitive`; `userCode` deliberately is not — it exists to be read aloud,
|
|
672
|
+
and wrapping it would defeat the one thing it is for.
|
|
673
|
+
|
|
674
|
+
Per §14.3 rule 4, `deviceLogin` **returns** the token set rather than adopting it. See
|
|
675
|
+
[`examples/device-login.ts`](examples/device-login.ts).
|
|
676
|
+
|
|
677
|
+
## Token exchange (`axiam-sdk/node`, CONTRACT.md §15)
|
|
678
|
+
|
|
679
|
+
RFC 8693 — a service holding a user's token exchanging it for a *narrower* one before
|
|
680
|
+
calling the next service.
|
|
681
|
+
|
|
682
|
+
```ts
|
|
683
|
+
const exchanged = await oidc.tokenExchange({
|
|
684
|
+
subjectToken: new Sensitive(userToken),
|
|
685
|
+
subjectTokenType: ACCESS_TOKEN_TYPE, // required (§15.1), no default
|
|
686
|
+
scopes: ['orders:read'],
|
|
687
|
+
audience: 'orders-service',
|
|
688
|
+
});
|
|
689
|
+
```
|
|
690
|
+
|
|
691
|
+
Most of what this method does is refuse to be helpful, and each refusal is deliberate:
|
|
692
|
+
|
|
693
|
+
- **No default `actorToken`.** Omitting it asks for *impersonation*; the SDK will not
|
|
694
|
+
quietly substitute the client's own session token and turn that into a delegation.
|
|
695
|
+
- **No auto-narrowing after `invalid_scope`.** The server refuses rather than silently
|
|
696
|
+
narrowing precisely so the caller finds out here.
|
|
697
|
+
- **No refresh token, ever** — `ExchangedToken` has no such field, so there is nothing to
|
|
698
|
+
synthesise. Re-run the exchange.
|
|
699
|
+
- **No adoption.** The issued token is handed onward in one call; adopting it would
|
|
700
|
+
silently re-privilege every later call this client makes. A MUST NOT, where
|
|
701
|
+
`loginClientCredentials` adoption is a MAY.
|
|
702
|
+
|
|
703
|
+
See [`examples/token-exchange.ts`](examples/token-exchange.ts).
|
|
704
|
+
|
|
705
|
+
### External-IdP subject tokens (CONTRACT.md §15.7)
|
|
706
|
+
|
|
707
|
+
The same method exchanges a token minted by a **trusted external IdP** — a partner's
|
|
708
|
+
Entra, Okta or Keycloak — for an AXIAM token scoped to what the resolved AXIAM user may
|
|
709
|
+
actually do. There is no separate operation:
|
|
710
|
+
|
|
711
|
+
```ts
|
|
712
|
+
const exchanged = await oidc.tokenExchange({
|
|
713
|
+
subjectToken: new Sensitive(partnerToken),
|
|
714
|
+
subjectTokenType: JWT_TOKEN_TYPE, // named, never guessed
|
|
715
|
+
scopes: ['read:orders'],
|
|
716
|
+
audience: 'https://orders.internal',
|
|
717
|
+
});
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
- **`subjectTokenType` is yours to state, and is required** (§15.1). The SDK never decodes
|
|
721
|
+
the subject token to pick it, and never overrides what you named. There is no default —
|
|
722
|
+
omitting it does not compile, because a default would be the SDK choosing for you.
|
|
723
|
+
- **No actor token.** Delegation across a trust boundary is unsupported in v1; sending one
|
|
724
|
+
is `invalid_request`, which the SDK will not work around by dropping it and re-sending.
|
|
725
|
+
- **One refusal is distinguishable.** `invalid_grant` whose description is `the subject
|
|
726
|
+
token's issuer is not configured for token exchange` means *fix the AXIAM trust
|
|
727
|
+
configuration*. Every other `invalid_grant` means *fix your token*, and is deliberately
|
|
728
|
+
generic.
|
|
729
|
+
- **Forward the result as-is.** It carries an `ext_exchange` claim naming the partner
|
|
730
|
+
issuer; never strip it, and never read it as an authorization input. It also cannot be
|
|
731
|
+
exchanged again — exchanges do not compose.
|
|
732
|
+
|
|
733
|
+
See [`examples/external-token-exchange.ts`](examples/external-token-exchange.ts) and the
|
|
734
|
+
operator guide, `docs/api/federated-token-exchange.md`.
|
|
735
|
+
|
|
736
|
+
## Logout — RP-initiated and back-channel (`axiam-sdk/node`, CONTRACT.md §12.7)
|
|
737
|
+
|
|
738
|
+
`logoutUrl` builds the redirect; `verifyLogoutToken` validates a token the OP **pushed** to
|
|
739
|
+
your back-channel endpoint.
|
|
740
|
+
|
|
741
|
+
```ts
|
|
742
|
+
const url = await oidc.logoutUrl({ idToken });
|
|
743
|
+
|
|
744
|
+
// …and at your registered backchannel_logout_uri:
|
|
745
|
+
const verified = await oidc.verifyLogoutToken(logoutToken);
|
|
746
|
+
if (verified.sid) {
|
|
747
|
+
endSession(verified.sid); // that session ONLY
|
|
748
|
+
}
|
|
749
|
+
```
|
|
750
|
+
|
|
751
|
+
The verifier is where the security weight sits — the input arrives unsolicited and
|
|
752
|
+
instructs you to terminate a session. It checks the signature (same JWKS path, same
|
|
753
|
+
`kid`-required discipline as §12.4), `iss`, `aud`, that `events` carries the
|
|
754
|
+
back-channel-logout key (**the only thing separating a logout token from an ID token**),
|
|
755
|
+
that `nonce` is *absent* (its presence is how an ID token gets replayed as one), that
|
|
756
|
+
something is named, and freshness.
|
|
757
|
+
|
|
758
|
+
It returns `sid`/`sub`/`jti` rather than a bare boolean: you have to know *which* session to
|
|
759
|
+
end. **Dedup on `jti` yourself** — delivery is at-least-once, so a valid token legitimately
|
|
760
|
+
arrives twice; the SDK has no durable store and an in-memory guard would silently drop a
|
|
761
|
+
real second logout after a restart.
|
|
762
|
+
|
|
763
|
+
See [`examples/logout.ts`](examples/logout.ts).
|
|
764
|
+
|
|
765
|
+
## UMA 2.0 — Protection API and ticket grant (CONTRACT.md §20)
|
|
766
|
+
|
|
767
|
+
The resource-server side of User-Managed Access: register what you guard, ask the
|
|
768
|
+
authorization server what a caller would need, and redeem the resulting ticket.
|
|
769
|
+
|
|
770
|
+
The two runnable halves are [`examples/uma-resource-server.ts`](examples/uma-resource-server.ts)
|
|
771
|
+
and [`examples/uma-client.ts`](examples/uma-client.ts) — run the first, then the second
|
|
772
|
+
against it.
|
|
773
|
+
|
|
774
|
+
### Making a denial actionable (`axiam-sdk/middleware`)
|
|
775
|
+
|
|
776
|
+
```ts
|
|
777
|
+
import { requireAccess, type UmaChallenger } from 'axiam-sdk/middleware';
|
|
778
|
+
|
|
779
|
+
const challenger: UmaChallenger = {
|
|
780
|
+
realm: 'invoices',
|
|
781
|
+
asUri: (await oidc.oidcDiscover()).issuer,
|
|
782
|
+
pat, // a client-credentials token carrying `uma_protection` (§20.2 rule 1)
|
|
783
|
+
mint: (token, permissions) => oidc.umaRequestTicket(token, [...permissions]),
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
app.get(
|
|
787
|
+
'/invoices/:id',
|
|
788
|
+
requireAccess(session, 'invoices:read', fromParam('id'), { umaChallenge: challenger }),
|
|
789
|
+
handler,
|
|
790
|
+
);
|
|
791
|
+
```
|
|
792
|
+
|
|
793
|
+
Without `umaChallenge` this is an ordinary §11 guard and a denial is a bare 403. With it, the
|
|
794
|
+
guard mints a permission ticket for the action it just refused and returns
|
|
795
|
+
`WWW-Authenticate: UMA realm=…, as_uri=…, ticket=…` alongside the 403 — so a UMA-aware client
|
|
796
|
+
knows where to obtain authority instead of only being told no. The body is unchanged, so a
|
|
797
|
+
client that does not speak UMA sees exactly the 403 it saw before. Both `requireAccess`
|
|
798
|
+
(Express) and `requireAccessHook` (Fastify) take the option.
|
|
799
|
+
|
|
800
|
+
**It is opt-in, and that is a design decision rather than an oversight.** Emitting a
|
|
801
|
+
challenge means *minting a credential*: a wire call to the Protection API and a live ticket,
|
|
802
|
+
produced on a path the caller did not explicitly request. A guard that did that on every
|
|
803
|
+
denial by default would turn each unauthorized request into a Protection API call — a
|
|
804
|
+
denial-of-service amplifier pointed at your own authorization server.
|
|
805
|
+
|
|
806
|
+
**Failure is not escalation.** If minting fails — expired PAT, Protection API down, a scope
|
|
807
|
+
the resource never declared — the denial still surfaces as a plain 403 with no challenge. A
|
|
808
|
+
caller who was going to be refused is refused either way; letting an outage turn a deny into
|
|
809
|
+
a 500 would give it a second consequence, and letting it turn into an allow would be a
|
|
810
|
+
security bug.
|
|
811
|
+
|
|
812
|
+
### Consuming the challenge (`axiam-sdk/node`)
|
|
813
|
+
|
|
814
|
+
```ts
|
|
815
|
+
import { umaParseChallenge } from 'axiam-sdk/node';
|
|
816
|
+
|
|
817
|
+
const challenge = umaParseChallenge(response.headers.get('www-authenticate') ?? '');
|
|
818
|
+
if (challenge?.ticket) {
|
|
819
|
+
// Deciding whether to trust challenge.asUri is YOUR call — parsing performed no
|
|
820
|
+
// exchange, deliberately (§20.3): that host was chosen by the server you just
|
|
821
|
+
// failed against.
|
|
822
|
+
const rpt = await oidc.umaExchangeTicket({ ticket: challenge.ticket, claimToken: userToken });
|
|
823
|
+
}
|
|
824
|
+
```
|
|
825
|
+
|
|
826
|
+
The rest of the surface — `umaRegisterResource`, the other four `rreg` operations,
|
|
827
|
+
`umaRequestTicket`, `umaExchangeTicket` — plus the rules they enforce (a ticket is never
|
|
828
|
+
retried, the RPT is never adopted, an update replaces the scope list rather than merging it)
|
|
829
|
+
is documented on the generated API docs for `axiam-sdk/node`.
|
|
830
|
+
|
|
510
831
|
## Webhook signature verification (`axiam-sdk/node`, CONTRACT.md §13)
|
|
511
832
|
|
|
512
833
|
AXIAM signs every webhook delivery with a Stripe-style signed timestamp:
|
|
@@ -569,6 +890,98 @@ like a stale one — and accepts a `tolerance` override plus a `now` injection s
|
|
|
569
890
|
failure always raises the typed `WebhookVerifyError` (never a generic exception whose message
|
|
570
891
|
could leak the expected signature).
|
|
571
892
|
|
|
893
|
+
## Client quality-of-life (CONTRACT.md §16–§19)
|
|
894
|
+
|
|
895
|
+
### Retry policy (§16)
|
|
896
|
+
|
|
897
|
+
Read-only authorization checks — `checkAccess`, `can`, `batchCheck` — retry transient
|
|
898
|
+
failures under the contract's normative table: **3 attempts** (1 initial + 2 retries),
|
|
899
|
+
200 ms base, 5 s cap, **full jitter** (uniform over `[0, backoff]`), and `Retry-After`
|
|
900
|
+
honored as a **floor**.
|
|
901
|
+
|
|
902
|
+
> **This changed in D5.** The previous policy used a 1000 ms base, an 8 s cap, partial
|
|
903
|
+
> jitter, and let `Retry-After` *replace* the backoff — so a `Retry-After: 0` retried
|
|
904
|
+
> immediately. Worse, `withRetry` was exported and unit-tested but **never called by
|
|
905
|
+
> `checkAccess`**, so this SDK performed no read-only retries at all. Both are fixed, and
|
|
906
|
+
> the conformance tests now assert through the public API rather than against the helper.
|
|
907
|
+
|
|
908
|
+
Only failures that could plausibly succeed on a second attempt are retried — transport
|
|
909
|
+
errors, `408`, `429`, `5xx`. A `401` or `403` is an answer, not a transport failure, and is
|
|
910
|
+
surfaced after exactly one attempt. Nothing that changes server state is ever retried.
|
|
911
|
+
|
|
912
|
+
```ts
|
|
913
|
+
// Turn it off if you own your own retry layer — you know your deadline, this SDK doesn't.
|
|
914
|
+
const client = new AxiamClient({ baseUrl, tenantSlug: 'acme', retryEnabled: false });
|
|
915
|
+
```
|
|
916
|
+
|
|
917
|
+
There is deliberately no knob for the attempt cap, base delay or delay cap: §16.1 forbids
|
|
918
|
+
raising them, and eleven SDKs agreeing on one table is the point.
|
|
919
|
+
|
|
920
|
+
### Deterministic shutdown (§18)
|
|
921
|
+
|
|
922
|
+
`client.close()` releases the client's local resources. It is idempotent, and any call
|
|
923
|
+
afterwards rejects with a `NetworkError` naming the cause rather than silently reconnecting.
|
|
924
|
+
|
|
925
|
+
**`close()` does not log out.** It never reaches the network. The server-side session
|
|
926
|
+
deliberately outlives the client object — that is what lets a process restart and resume —
|
|
927
|
+
so a `close()` that logged out would silently end every user's session on each deploy. Call
|
|
928
|
+
`logout()` first if ending the session is what you want.
|
|
929
|
+
|
|
930
|
+
### Telemetry hooks (§19)
|
|
931
|
+
|
|
932
|
+
Wire metrics without this package depending on any metrics library:
|
|
933
|
+
|
|
934
|
+
```ts
|
|
935
|
+
const client = new AxiamClient({
|
|
936
|
+
baseUrl,
|
|
937
|
+
tenantSlug: 'acme',
|
|
938
|
+
telemetryHook: (event) => {
|
|
939
|
+
if (event.type === 'requestEnd') {
|
|
940
|
+
histogram.record(event.durationMs, { op: event.operation, outcome: event.outcome });
|
|
941
|
+
} else if (event.type === 'retry') {
|
|
942
|
+
counter.add(1, { op: event.operation, attempt: event.attempt });
|
|
943
|
+
}
|
|
944
|
+
},
|
|
945
|
+
});
|
|
946
|
+
```
|
|
947
|
+
|
|
948
|
+
- **A hook that throws cannot fail the operation that fired it.** Telemetry is not permitted
|
|
949
|
+
to fail an authorization check.
|
|
950
|
+
- **No event payload can carry a token.** `TelemetryEvent` is a closed union with a fixed
|
|
951
|
+
field set — this surface exists to be shipped to a metrics backend.
|
|
952
|
+
- **Path templates, not URLs**, so a metric label cannot become a cardinality bomb.
|
|
953
|
+
|
|
954
|
+
One `requestStart`/`requestEnd` pair is emitted **per attempt**, so you can count real wire
|
|
955
|
+
calls. See [`examples/telemetry-hook.ts`](examples/telemetry-hook.ts), including the
|
|
956
|
+
OpenTelemetry mapping.
|
|
957
|
+
|
|
958
|
+
### Decision memo (§17) — opt-in, off by default
|
|
959
|
+
|
|
960
|
+
An optional TTL-bounded cache for `checkAccess` results. **Disabled by default**, because
|
|
961
|
+
§11.2 rule 6's ban on caching authorization decisions is still the default behaviour.
|
|
962
|
+
|
|
963
|
+
```ts
|
|
964
|
+
const client = new AxiamClient({
|
|
965
|
+
baseUrl,
|
|
966
|
+
tenantSlug: 'acme',
|
|
967
|
+
decisionMemoTtlMs: 5000, // 0 = off, which is the default
|
|
968
|
+
});
|
|
969
|
+
```
|
|
970
|
+
|
|
971
|
+
**What you are accepting.** The staleness bound is the TTL, in *both* directions: a grant
|
|
972
|
+
revoked on the server can still read as allowed for up to the TTL, and a grant just added
|
|
973
|
+
can still read as denied for up to the TTL.
|
|
974
|
+
|
|
975
|
+
> **Reads-your-own-writes is not guaranteed.** An admin UI that grants a role and
|
|
976
|
+
> immediately re-checks is the case that breaks, and it breaks silently. If that is your
|
|
977
|
+
> workload, leave this off.
|
|
978
|
+
|
|
979
|
+
The TTL is clamped to 5000 ms rather than rejected. Allows and denies are memoized
|
|
980
|
+
identically — asymmetric caching would leak which outcome occurred through latency.
|
|
981
|
+
Failures are never memoized: caching a transport error as a deny would turn a blip into a
|
|
982
|
+
TTL-long outage. The memo is cleared on `login`, `verifyMfa`, `refresh` and `logout`, since
|
|
983
|
+
entries are keyed by subject rather than by session.
|
|
984
|
+
|
|
572
985
|
## Error handling
|
|
573
986
|
|
|
574
987
|
Every persona throws the three CONTRACT.md §2 error types — `AuthError`, `AuthzError`,
|