axiam-sdk 1.0.0-beta14 → 1.0.0-beta16

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 (56) hide show
  1. package/README.md +276 -16
  2. package/dist/{authzCore-Biyca_Rm.d.ts → authzCore-0fObXIqB.d.ts} +37 -0
  3. package/dist/{authzCore-BZahGkBf.d.cts → authzCore-DJmDAAtw.d.cts} +37 -0
  4. package/dist/browser/index.d.cts +24 -5
  5. package/dist/browser/index.d.ts +24 -5
  6. package/dist/browser/index.js +7 -0
  7. package/dist/browser/index.js.map +1 -1
  8. package/dist/browser/index.mjs +7 -1
  9. package/dist/browser/index.mjs.map +1 -1
  10. package/dist/{client-BXXwSvBI.d.ts → client-BstRBtp8.d.ts} +515 -30
  11. package/dist/{client-JWANinYZ.d.cts → client-Dd_XaOtg.d.cts} +515 -30
  12. package/dist/{cookieJar-DZSc_d8H.d.ts → cookieJar-D0FxzBQG.d.ts} +14 -4
  13. package/dist/{cookieJar-DXyJgm8n.d.cts → cookieJar-Dvb1Gnwm.d.cts} +14 -4
  14. package/dist/errors-CxqAZsex.d.cts +168 -0
  15. package/dist/errors-CxqAZsex.d.ts +168 -0
  16. package/dist/grpc/index.d.cts +5 -5
  17. package/dist/grpc/index.d.ts +5 -5
  18. package/dist/grpc/index.js +173 -10
  19. package/dist/grpc/index.js.map +1 -1
  20. package/dist/grpc/index.mjs +173 -10
  21. package/dist/grpc/index.mjs.map +1 -1
  22. package/dist/index.d.cts +4 -3
  23. package/dist/index.d.ts +4 -3
  24. package/dist/index.js +142 -7
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.mjs +142 -8
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/middleware/index.d.cts +261 -14
  29. package/dist/middleware/index.d.ts +261 -14
  30. package/dist/middleware/index.js +373 -11
  31. package/dist/middleware/index.js.map +1 -1
  32. package/dist/middleware/index.mjs +369 -12
  33. package/dist/middleware/index.mjs.map +1 -1
  34. package/dist/nestjs/index.d.cts +1 -1
  35. package/dist/nestjs/index.d.ts +1 -1
  36. package/dist/nestjs/index.js +9 -3
  37. package/dist/nestjs/index.js.map +1 -1
  38. package/dist/nestjs/index.mjs +9 -3
  39. package/dist/nestjs/index.mjs.map +1 -1
  40. package/dist/node/index.d.cts +5 -5
  41. package/dist/node/index.d.ts +5 -5
  42. package/dist/node/index.js +173 -10
  43. package/dist/node/index.js.map +1 -1
  44. package/dist/node/index.mjs +173 -10
  45. package/dist/node/index.mjs.map +1 -1
  46. package/dist/{oidcState-C_9FRWTp.d.cts → oidcState-CSi4DY8h.d.cts} +1 -1
  47. package/dist/{oidcState-YzbbVX-C.d.ts → oidcState-CffZ6PkC.d.ts} +1 -1
  48. package/dist/rest/index.d.cts +6 -171
  49. package/dist/rest/index.d.ts +6 -171
  50. package/dist/rest/index.js +142 -7
  51. package/dist/rest/index.js.map +1 -1
  52. package/dist/rest/index.mjs +142 -8
  53. package/dist/rest/index.mjs.map +1 -1
  54. package/dist/{session-B0Lkz0X9.d.cts → session-oiuBA1ZA.d.cts} +17 -1
  55. package/dist/{session-fJCGq5jw.d.ts → session-ymrHvMuJ.d.ts} +17 -1
  56. package/package.json +1 -1
package/README.md CHANGED
@@ -1,8 +1,13 @@
1
1
  # axiam-sdk (TypeScript/JavaScript)
2
2
 
3
+ <!-- Track the CURRENT channel's dist-tag, not `latest`: releases are prereleases and
4
+ the publish job keeps those off `latest` (see "Release / versioning"), so a plain
5
+ `npm/v/axiam-sdk` badge reports whatever was last published to `latest` — today
6
+ 1.0.0-alpha28, dozens of releases stale. Move `beta` below to `rc`, then drop it
7
+ entirely, as the channel advances. -->
3
8
  [![CI](https://github.com/ilpanich/axiam-typescript-sdk/actions/workflows/sdk-ci-typescript.yml/badge.svg?branch=main)](https://github.com/ilpanich/axiam-typescript-sdk/actions/workflows/sdk-ci-typescript.yml)
4
9
  [![Coverage Status](https://coveralls.io/repos/github/ilpanich/axiam-typescript-sdk/badge.svg?branch=main)](https://coveralls.io/github/ilpanich/axiam-typescript-sdk?branch=main)
5
- [![npm](https://img.shields.io/npm/v/axiam-sdk.svg)](https://www.npmjs.com/package/axiam-sdk)
10
+ [![npm](https://img.shields.io/npm/v/axiam-sdk/beta?label=npm%20beta)](https://www.npmjs.com/package/axiam-sdk)
6
11
  [![Docs](https://img.shields.io/badge/docs-TypeDoc-blue.svg)](https://ilpanich.github.io/axiam-typescript-sdk/)
7
12
  [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
8
13
 
@@ -13,16 +18,16 @@ Official TypeScript/JavaScript client SDK for [AXIAM](https://github.com/ilpanic
13
18
  ## Package identity
14
19
 
15
20
  - **npm package:** `axiam-sdk`
16
- - **Registry:** [npmjs.com/package/axiam-sdk](https://www.npmjs.com/package/axiam-sdk) _(reserved, not yet published)_
21
+ - **Registry:** [npmjs.com/package/axiam-sdk](https://www.npmjs.com/package/axiam-sdk) — published as prereleases, under the `alpha`/`beta` dist-tags
17
22
  - **Source:** [github.com/ilpanich/axiam-typescript-sdk](https://github.com/ilpanich/axiam-typescript-sdk)
18
23
  - **License:** Apache-2.0
19
24
  - **Node:** `>=22` — see [Supported Node versions](#supported-node-versions)
20
25
 
21
26
  ## Contract conformance
22
27
 
23
- This SDK conforms to **contract 1.42**: CONTRACT.md §1–§13 and §12.7, §14, §15, §17, §19,
24
- §20, §21, §22, §23, §24, §25, §26, §27 (including §6.1 mTLS client certificates, the §10.1
25
- minimum local-verification set, the §12 OIDC/SSO relying-party helpers, and the §13
28
+ This SDK conforms to **contract 1.50**: CONTRACT.md §1–§13 and §12.7, §14, §15, §17, §19,
29
+ §20, §21, §22, §23, §24, §25, §26, §27, §28 (including §6.1 mTLS client certificates, the
30
+ §10.1 minimum local-verification set, the §12 OIDC/SSO relying-party helpers, and the §13
26
31
  `verifyWebhook` signature verifier). §12 is implemented in full at its 1.38 shape: all
27
32
  **thirteen** operations, including the four public "Sign in with X" entry points.
28
33
 
@@ -32,14 +37,19 @@ browser bundle pulls in no Node-only code. §12.2 forbids splitting them across
32
37
  the four operations contract 1.38 adds are on `OidcClient` too, with the nine that preceded
33
38
  them, even though three of them need no Node-only code at all.
34
39
 
35
- §27 is implemented **in full**, both halves: the 158-operation imperative surface *and*
40
+ §27 is implemented **in full**, both halves: the 160-operation imperative surface *and*
36
41
  the §27.6 declarative manifest with its §27.7 `defineManifest` and decorator forms. The
37
42
  contract asks an SDK that ships only one half to say which; this one ships both.
38
43
 
39
- §12.7, §14, §15, §22, §24, §25, §26 and §27 are named rather than folded into the range
40
- because they landed after this SDK already claimed §1–§13: widening the range silently
41
- would turn a statement that was true when written into a different claim without anyone
42
- editing it.
44
+ §28 (MCP resource-server helpers) is implemented on **both** framework surfaces — the
45
+ Express middleware and the Fastify plugin — with all three operations, the
46
+ `resourceMetadataUrl` guard option and §28.9's five required tests. This SDK is §28.10's
47
+ reference implementation: it lands first and the ten ports are read against it.
48
+
49
+ §12.7, §14, §15, §22, §24, §25, §26, §27 and §28 are named rather than folded into the
50
+ range because they landed after this SDK already claimed §1–§13: widening the range
51
+ silently would turn a statement that was true when written into a different claim without
52
+ anyone editing it.
43
53
 
44
54
  ### §10.1 minimum local-verification set
45
55
 
@@ -74,9 +84,14 @@ See [`CONTRACT.md`](./CONTRACT.md) for the full cross-language behavioral contra
74
84
  ## Install
75
85
 
76
86
  ```bash
77
- npm install axiam-sdk
87
+ npm install axiam-sdk@beta
78
88
  ```
79
89
 
90
+ Every release so far is a prerelease, and the publish job files each one under its
91
+ channel's dist-tag (`beta` today) rather than `latest` — so name the channel, or pin an
92
+ exact version. A bare `npm install axiam-sdk` resolves `latest`, which no prerelease
93
+ moves.
94
+
80
95
  ## Supported Node versions
81
96
 
82
97
  | | Version | Why this one |
@@ -120,7 +135,7 @@ never contains `@grpc/grpc-js` or `amqplib`):
120
135
  | Entry point | Persona | Contents |
121
136
  |-------------------------|-----------------------------|---------------------------------------------------------------------------|
122
137
  | `axiam-sdk` / `axiam-sdk/rest` | Browser + Node, REST-only | `AxiamClient`: `login`/`verifyMfa`/`refresh`/`logout`, `can`/`batchCheck` over the FND-04 REST authz endpoint |
123
- | `axiam-sdk/browser` | Browser only | The WebAuthn **platform ceremony** — `webauthnRegister`/`webauthnLogin`/`webauthnDiscoverableLogin` over `navigator.credentials` (CONTRACT.md §24.6b). The relying-party operations themselves are on `AxiamClient` in `/rest` and work in Node too. |
138
+ | `axiam-sdk/browser` | Browser only | The WebAuthn **platform ceremony** — `webauthnRegister`/`webauthnSetupRegister`/`webauthnLogin`/`webauthnDiscoverableLogin` over `navigator.credentials` (CONTRACT.md §24.6b). The relying-party operations themselves are on `AxiamClient` in `/rest` and work in Node too. |
124
139
  | `axiam-sdk/grpc` | Node only | Everything in `/rest` plus `AuthzGrpcClient.checkAccess`/`batchCheck` and `UserInfoGrpcClient.getUserInfo` over gRPC, the Node persona (`createNodeSession`), and the local-JWKS verifier |
125
140
  | `axiam-sdk/amqp` | Node only | `consume()` — HMAC-verified AMQP audit/authz event consumer (CONTRACT.md §8) |
126
141
  | `axiam-sdk/node` | Node only | The Node persona (`createNodeSession`/`createNodeClient`, cookie jar + local-JWKS verifier) plus the **OIDC/SSO relying-party helpers** — `OidcClient`, `MemoryOidcStateStore`, PKCE primitives (CONTRACT.md §12) |
@@ -1046,9 +1061,16 @@ you which half you get.
1046
1061
 
1047
1062
  | | Where | Runs in |
1048
1063
  |---|---|---|
1049
- | The six relying-party operations | `AxiamClient`, from `axiam-sdk` / `axiam-sdk/rest` | **Browser and Node** |
1064
+ | The eight relying-party operations | `AxiamClient`, from `axiam-sdk` / `axiam-sdk/rest` | **Browser and Node** |
1050
1065
  | The ceremony (`navigator.credentials`) | `axiam-sdk/browser` | Browser only |
1051
1066
 
1067
+ Six of the eight enrol or authenticate an existing account and are covered
1068
+ below. The other two, `webauthnSetupRegisterStart`/`webauthnSetupRegisterFinish`
1069
+ (contract 1.45), enrol a passkey as an account's **first** factor during forced
1070
+ login setup and take no session at all — see
1071
+ ["A passkey or security key as the first factor"](#a-passkey-or-security-key-as-the-first-factor-contract-145)
1072
+ in the account-lifecycle section, next to their TOTP twin.
1073
+
1052
1074
  The Node half is not a consolation prize. A service completing a ceremony that
1053
1075
  ran on a handset — an Android app, an iOS app, a hardware client — is the
1054
1076
  relying party, exactly as a browser is, and it never touches
@@ -1226,6 +1248,39 @@ If you match `LoginResult` exhaustively, this is the edit you need. A genuine
1226
1248
  authorization refusal is still an `AuthzError`: the SDK matches on the body's own
1227
1249
  discriminant, not on the `403` alone.
1228
1250
 
1251
+ ### A passkey or security key as the first factor (contract 1.45)
1252
+
1253
+ `mfaSetupEnroll`/`mfaSetupConfirm` above are the TOTP path through
1254
+ `mfa_setup_required`. `webauthnSetupRegisterStart`/`webauthnSetupRegisterFinish`
1255
+ are the WebAuthn twin, for a user who would rather enrol a passkey or security
1256
+ key as their first factor:
1257
+
1258
+ ```ts
1259
+ case 'mfa_setup_required': {
1260
+ const { challenge, stateToken } = await client.webauthnSetupRegisterStart(result.setupToken);
1261
+ const credential = await createTheAuthenticatorResponse(challenge); // e.g. axiam-sdk/browser
1262
+ await client.webauthnSetupRegisterFinish(
1263
+ result.setupToken,
1264
+ stateToken,
1265
+ 'Alice’s security key',
1266
+ credential,
1267
+ );
1268
+ break; // this completes the login, exactly as mfaSetupConfirm does
1269
+ }
1270
+ ```
1271
+
1272
+ In the browser, `webauthnSetupRegister(client, result.setupToken, name)` from
1273
+ `axiam-sdk/browser` (§24.6b) runs all three steps, mirroring `webauthnRegister`.
1274
+
1275
+ **They take no session, and never will.** The setup token in the body is the
1276
+ only credential either endpoint accepts — unlike `webauthnRegisterStart`/
1277
+ `webauthnRegisterFinish`, which enrol a passkey for an *already signed-in*
1278
+ user and require one. Calling them on a client that happens to be
1279
+ authenticated elsewhere does not attach that session: a setup token adds an
1280
+ account's first factor, never a second, and the SDK never lets the two
1281
+ credentials mix. `webauthnSetupRegisterFinish` adopts the resulting session
1282
+ exactly as `mfaSetupConfirm` does, because it *is* the same completed login.
1283
+
1229
1284
  ### Email verification and password reset
1230
1285
 
1231
1286
  ```ts
@@ -1665,6 +1720,211 @@ like a stale one — and accepts a `tolerance` override plus a `now` injection s
1665
1720
  failure always raises the typed `WebhookVerifyError` (never a generic exception whose message
1666
1721
  could leak the expected signature).
1667
1722
 
1723
+ ## MCP resource-server helpers (`axiam-sdk/middleware`, CONTRACT.md §28)
1724
+
1725
+ The resource-server half of the Model Context Protocol authorization handshake: publish the
1726
+ RFC 9728 document that tells an MCP client which authorization server guards this resource,
1727
+ and put the RFC 6750 `WWW-Authenticate` challenge on the 401 that starts its discovery.
1728
+
1729
+ **AXIAM is the authorization server and implements none of this.** Your MCP server is the
1730
+ resource server, and this is its side. Nothing here talks to AXIAM, performs any network I/O
1731
+ or touches the SDK client's own session — all three operations are pure local computation,
1732
+ like `oidcBegin` and `umaParseChallenge`. The *client* half — parsing a challenge, fetching
1733
+ a document, deciding whether to trust the authorization server it names — is deliberately
1734
+ not in the SDK: a helper that read a 401 and acted on it would send a credential to whatever
1735
+ host the 401 asked it to.
1736
+
1737
+ **It is opt-in and off by default.** With `resourceMetadataUrl` unset, every guard behaves
1738
+ byte-for-byte as it did before §28 existed: no header on any response, no status changed, no
1739
+ body changed.
1740
+
1741
+ ### The whole integration
1742
+
1743
+ ```ts
1744
+ import express from 'express';
1745
+ import { createVerifier } from 'axiam-sdk/node';
1746
+ import {
1747
+ axiamMiddleware,
1748
+ protectedResourceMetadata,
1749
+ serveProtectedResourceMetadata,
1750
+ } from 'axiam-sdk/middleware';
1751
+
1752
+ // 1. Describe the resource server. Validated here, at construction — before any
1753
+ // route exists and before any request is served.
1754
+ const metadata = protectedResourceMetadata({
1755
+ resource: 'https://mcp.example.com/mcp',
1756
+ authorizationServers: ['https://axiam.example.com'],
1757
+ scopesSupported: ['mcp:read', 'mcp:tools'],
1758
+ });
1759
+
1760
+ // 2. Configure the guard FROM that value rather than by retyping the strings —
1761
+ // retyping is how the guard and the document come to disagree. The session
1762
+ // is the same plain `VerifiableSession` literal §10.4's feed is attached to.
1763
+ const session = {
1764
+ jwksVerifier: createVerifier('https://axiam.example.com'),
1765
+ tenantHeaderValue: TENANT_UUID,
1766
+ expectedAudience: metadata.document.resource, // https://mcp.example.com/mcp
1767
+ resourceMetadataUrl: metadata.metadataUrl, // https://mcp.example.com/.well-known/…/mcp
1768
+ };
1769
+
1770
+ const app = express();
1771
+ app.use(axiamMiddleware(session));
1772
+
1773
+ // 3. Publish the document. Passing `session` is what lets the SDK check that
1774
+ // the three strings agree; it throws at startup if they do not.
1775
+ serveProtectedResourceMetadata(app, metadata, session);
1776
+
1777
+ app.post('/mcp', handler);
1778
+ ```
1779
+
1780
+ Fastify is the same three calls — `axiamPlugin(session)` instead of `axiamMiddleware`, and
1781
+ the Fastify instance instead of the Express app. `serveProtectedResourceMetadata` takes
1782
+ either.
1783
+
1784
+ A request with no credential now gets what it needs to go and get one:
1785
+
1786
+ ```http
1787
+ HTTP/1.1 401 Unauthorized
1788
+ WWW-Authenticate: Bearer resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource/mcp"
1789
+ Content-Type: application/json
1790
+
1791
+ {"error":"authentication_failed","message":"..."}
1792
+ ```
1793
+
1794
+ and the document it points at answers without a credential:
1795
+
1796
+ ```json
1797
+ {
1798
+ "resource": "https://mcp.example.com/mcp",
1799
+ "authorization_servers": ["https://axiam.example.com"],
1800
+ "scopes_supported": ["mcp:read", "mcp:tools"],
1801
+ "bearer_methods_supported": ["header"]
1802
+ }
1803
+ ```
1804
+
1805
+ **The path is derived from the resource, not chosen.** RFC 9728 §3.1 inserts
1806
+ `/.well-known/oauth-protected-resource` between the authority and the path, so
1807
+ `https://mcp.example.com/mcp` publishes at `/.well-known/oauth-protected-resource/mcp` and
1808
+ `https://mcp.example.com` at the bare well-known path. A trailing slash is carried through
1809
+ rather than trimmed — it is part of the identifier the client compares, and two resources
1810
+ that differ only by it are two resources. Exactly one route is registered; a deployment
1811
+ fronting several resources calls the helper once per resource.
1812
+
1813
+ **You do not have to order the routes.** Where the guard is mounted globally it exempts the
1814
+ document's path itself, from the `resourceMetadataUrl` it was configured with — which is the
1815
+ only thing that works on Fastify, where a `preHandler` hook applies to every route in its
1816
+ context no matter when it was registered.
1817
+
1818
+ ### Announcing yourself obliges you to check
1819
+
1820
+ **`expectedAudience` is mandatory once `resourceMetadataUrl` is set**, and every guard
1821
+ factory refuses the configuration at construction, naming both options. A resource server
1822
+ that publishes *"tokens for me carry this `aud`"* and then does not check `aud` has published
1823
+ a claim it does not honour — and a token minted for a **different** MCP server opens it. That
1824
+ is the confusion RFC 8707 exists to prevent, so it is impossible to configure rather than
1825
+ merely discouraged:
1826
+
1827
+ ```ts
1828
+ axiamMiddleware({ jwksVerifier, tenantHeaderValue, resourceMetadataUrl: metadata.metadataUrl });
1829
+ // ValidationError: resourceMetadataUrl: requires expectedAudience to be set on the
1830
+ // same session (CONTRACT.md §28.5 rule 2) — …
1831
+ ```
1832
+
1833
+ With both set, a token carrying `aud: "axiam:user"` — a perfectly valid AXIAM token that
1834
+ simply was not minted for this resource — is a 401, exactly like a token minted for
1835
+ `https://other.example.com/mcp`.
1836
+
1837
+ ### The 403 that asks for a scope
1838
+
1839
+ One class of 403 carries a challenge, and only one: a `requireAccess`/`requireAccessHook`
1840
+ that **named a scope** whose decision came back `allowed: false` with `reasonCode:
1841
+ "no_grant"`.
1842
+
1843
+ ```ts
1844
+ app.post('/mcp/tools', requireAccess(session, 'mcp:invoke', 'tools', { scope: 'mcp:tools' }), handler);
1845
+ ```
1846
+
1847
+ ```http
1848
+ HTTP/1.1 403 Forbidden
1849
+ WWW-Authenticate: Bearer error="insufficient_scope", scope="mcp:tools", resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource/mcp"
1850
+ Content-Type: application/json
1851
+
1852
+ {"error":"authorization_denied","message":"..."}
1853
+ ```
1854
+
1855
+ `insufficient_scope` is in the header and `authorization_denied` is in the body, and they are
1856
+ not two spellings of one thing: the body is the §11 error taxonomy, unchanged, and the header
1857
+ is the RFC 6750 hint. The scope named is the one the route asked for, **verbatim** — never
1858
+ synthesised, never derived from `action`/`resource`, never substituted from the document's
1859
+ `scopes_supported`, because where a deployment's AXIAM resource-scope names and its OAuth
1860
+ scope names differ, that mapping is the operator's decision and the SDK cannot see it.
1861
+
1862
+ Every other 403 carries no header at all: a `requireAccess` with no `scope` argument, a
1863
+ `requireRole` failure, a CSRF refusal, and — the one that matters — a decision whose
1864
+ `reasonCode` is `denied_by_rule`. `no_grant` means *ask for more*, which is what a challenge
1865
+ invites a client to do; `denied_by_rule` means *an administrator has already decided*, and
1866
+ challenging on it would send an MCP client all the way around the authorization loop to
1867
+ arrive at the identical 403. An absent or unrecognised `reasonCode` is not eligible either.
1868
+
1869
+ Where a route also carries a `umaChallenge` (§20.3), the UMA challenge wins: it is per-route
1870
+ opt-in and carries a live ticket for the exact authority just refused, where this one is the
1871
+ generic hint. Only one `WWW-Authenticate` value is ever emitted.
1872
+
1873
+ ### The challenge says only what RFC 6750 can say
1874
+
1875
+ Expired, not yet valid, wrong tenant, wrong audience, bad signature, `alg` confusion, a `cnf`
1876
+ the guard could not satisfy, a `sid` in the §10.4 revocation feed — all of them are
1877
+ `invalid_token`, indistinguishably. The SDK's own guard never emits an `error_description`,
1878
+ and adds nothing to the response that tells them apart. It is a 401 to an unauthenticated
1879
+ stranger: every distinction it draws is an oracle.
1880
+
1881
+ `bearerChallenge` exists for the challenge you build yourself, for your own 400, and it takes
1882
+ `errorDescription` for that reason alone. It **refuses rather than escapes**: RFC 6750
1883
+ restricts every parameter to a character set that cannot contain `"` or `\`, so a value
1884
+ needing an escape is a value that does not belong in a challenge.
1885
+
1886
+ ```ts
1887
+ bearerChallenge({
1888
+ resourceMetadataUrl: metadata.metadataUrl,
1889
+ error: 'invalid_request',
1890
+ errorDescription: 'The access token is malformed',
1891
+ scope: 'mcp:read mcp:tools',
1892
+ });
1893
+ // Bearer error="invalid_request", error_description="The access token is malformed",
1894
+ // scope="mcp:read mcp:tools", resource_metadata="https://mcp.example.com/.well-known/…/mcp"
1895
+
1896
+ bearerChallenge({ resourceMetadataUrl: metadata.metadataUrl, errorDescription: 'he said "no"' });
1897
+ // ValidationError — never a challenge containing \"
1898
+ ```
1899
+
1900
+ ### Validation refuses; it never repairs
1901
+
1902
+ Every §28.2 rule is checked by `protectedResourceMetadata` itself, and a violation throws
1903
+ `ValidationError` (§2's taxonomy, unchanged — §28 adds no error type). Nothing is normalised,
1904
+ trimmed, lowercased or re-encoded to make it pass: that would publish a document describing a
1905
+ resource server that does not exist. The rules, in one list:
1906
+
1907
+ | Member | Rule |
1908
+ |---|---|
1909
+ | `resource` | absolute URI with a scheme and an authority, **no query and no fragment**; a trailing slash is significant |
1910
+ | any URL | `https`, except on `127.0.0.1`, `[::1]` or `localhost` — there is no flag, env var or debug build that widens this |
1911
+ | `authorizationServers` | at least one entry, each an issuer **verbatim** (no `?tenant_id=`), no query, no fragment, no duplicates |
1912
+ | `scopesSupported` | RFC 6749 `NQCHAR` tokens, order preserved, no duplicates; an empty list **omits the member** |
1913
+ | `bearerMethodsSupported` | exactly `["header"]` — this SDK's guard reads a bearer credential from the `Authorization` header alone |
1914
+ | `resourceDocumentation` | an absolute URL, query and fragment permitted; omitted when absent, never `null` |
1915
+
1916
+ **Nothing in the document may come from a request.** `resource` and `authorizationServers`
1917
+ are configuration, and this SDK offers no option to build either from the `Host` header, the
1918
+ `Forwarded`/`X-Forwarded-*` family or the request URL. A document assembled from the request
1919
+ is a document an attacker can point at an authorization server of their choosing — the whole
1920
+ handshake redirected with one header.
1921
+
1922
+ Nothing in §28 is wrapped in `Sensitive<T>`, and that is a rule rather than an omission: the
1923
+ document is published unauthenticated to the world and the challenge goes to a caller who has
1924
+ just failed to authenticate, so both must stay readable. The corollary is the one that
1925
+ matters — **no part of the presented credential reaches either of them**, in any parameter,
1926
+ any header, any body or any log line the guard writes on the 401 path.
1927
+
1668
1928
  ## Client quality-of-life (CONTRACT.md §16–§19)
1669
1929
 
1670
1930
  ### Retry policy (§16)
@@ -1762,7 +2022,7 @@ entries are keyed by subject rather than by session.
1762
2022
  Everything above assumes a populated tenant. `login` signs a user in,
1763
2023
  `checkAccess` asks about a resource, `verifyWebhook` checks a delivery signature — and
1764
2024
  none of them can create the user, declare the resource or register the webhook. The
1765
- management surface is the part that can: **158 operations across 24 namespaces**,
2025
+ management surface is the part that can: **160 operations across 24 namespaces**,
1766
2026
  generated from `management-registry.json`, which is the whole server API minus what other
1767
2027
  contract sections own and minus organization creation and deletion (§27.0 keeps those out
1768
2028
  of reach of a client library on purpose).
@@ -1873,7 +2133,7 @@ back.
1873
2133
 
1874
2134
  ### Declarative manifests (§27.6, §27.7)
1875
2135
 
1876
- Calling 158 operations one at a time is rarely what an application wants. What it does at
2136
+ Calling 160 operations one at a time is rarely what an application wants. What it does at
1877
2137
  start-up, in a migration, or in a test fixture is assert a shape:
1878
2138
 
1879
2139
  ```ts
@@ -1911,7 +2171,7 @@ actions that would reconcile the tenant.
1911
2171
  a tenant that also holds hand-made state.
1912
2172
  - **Applying twice converges**: the second plan is all `no-change`. That is what makes
1913
2173
  re-running after a failure safe.
1914
- - **There is no transaction** across 158 independent HTTP endpoints, and `ApplyReport` does
2174
+ - **There is no transaction** across 160 independent HTTP endpoints, and `ApplyReport` does
1915
2175
  not pretend there is. If step 12 of 30 fails, steps 1–11 have happened; the report says
1916
2176
  which, execution stops rather than continuing blindly, and there is no `rollback` —
1917
2177
  because this SDK could not honour one.
@@ -39,6 +39,33 @@ interface VerifiableSession {
39
39
  * `"axiam:user"`. Populated from `AxiamClientOptions.expectedAudience`.
40
40
  */
41
41
  expectedAudience?: string;
42
+ /**
43
+ * CONTRACT.md §28.5 (contract 1.48) — the URL of this resource server's RFC
44
+ * 9728 protected-resource metadata document.
45
+ *
46
+ * Unset by default, and **setting it is what turns §28 on**. With it unset
47
+ * every guard built from this session behaves byte-for-byte as it did before
48
+ * §28 existed: no `WWW-Authenticate` header on any response, no status
49
+ * changed, no body changed.
50
+ *
51
+ * With it set, the guard's 401s carry §28.4's challenge, a
52
+ * `require_access`/`requireAccessHook` denial that named a scope and came
53
+ * back `no_grant` carries `insufficient_scope`, and the path this URL names
54
+ * is served without authentication so the document can start the handshake
55
+ * it exists to start.
56
+ *
57
+ * **{@link VerifiableSession.expectedAudience} becomes mandatory.** Every
58
+ * guard factory refuses the configuration at construction — before the first
59
+ * request — when this is set and that is not, and the refusal names both. A
60
+ * resource server that publishes "tokens for me carry this `aud`" and then
61
+ * does not check `aud` is opened by a token minted for a different resource
62
+ * server, which is the confusion RFC 8707 exists to prevent.
63
+ *
64
+ * Feed it from `protectedResourceMetadata(...).metadataUrl` rather than by
65
+ * retyping the string — retyping is how the guard and the document come to
66
+ * disagree.
67
+ */
68
+ resourceMetadataUrl?: string;
42
69
  /**
43
70
  * CONTRACT.md §10.4 (contract 1.44) — the optional session-revocation feed.
44
71
  *
@@ -238,6 +265,16 @@ type CheckOutcome = {
238
265
  * when minting failed — the denial stands either way.
239
266
  */
240
267
  challenge?: string;
268
+ /**
269
+ * The decision's `reason_code` (§11 rule 9), surfaced verbatim so the
270
+ * caller can apply §28.5 rule 5 — `no_grant` is the one denial a bearer
271
+ * challenge may invite a client to retry, and `denied_by_rule` is not.
272
+ *
273
+ * Absent when the decision carried none, and absent on the `AuthzError`
274
+ * arm: a server 403 names no reason code, and §11 rule 9 requires an
275
+ * absent one to leave the outcome alone.
276
+ */
277
+ reasonCode?: string;
241
278
  } | {
242
279
  /** The authz transport failed — fail-closed → HTTP 503, never an allow. */
243
280
  kind: 'unavailable';
@@ -39,6 +39,33 @@ interface VerifiableSession {
39
39
  * `"axiam:user"`. Populated from `AxiamClientOptions.expectedAudience`.
40
40
  */
41
41
  expectedAudience?: string;
42
+ /**
43
+ * CONTRACT.md §28.5 (contract 1.48) — the URL of this resource server's RFC
44
+ * 9728 protected-resource metadata document.
45
+ *
46
+ * Unset by default, and **setting it is what turns §28 on**. With it unset
47
+ * every guard built from this session behaves byte-for-byte as it did before
48
+ * §28 existed: no `WWW-Authenticate` header on any response, no status
49
+ * changed, no body changed.
50
+ *
51
+ * With it set, the guard's 401s carry §28.4's challenge, a
52
+ * `require_access`/`requireAccessHook` denial that named a scope and came
53
+ * back `no_grant` carries `insufficient_scope`, and the path this URL names
54
+ * is served without authentication so the document can start the handshake
55
+ * it exists to start.
56
+ *
57
+ * **{@link VerifiableSession.expectedAudience} becomes mandatory.** Every
58
+ * guard factory refuses the configuration at construction — before the first
59
+ * request — when this is set and that is not, and the refusal names both. A
60
+ * resource server that publishes "tokens for me carry this `aud`" and then
61
+ * does not check `aud` is opened by a token minted for a different resource
62
+ * server, which is the confusion RFC 8707 exists to prevent.
63
+ *
64
+ * Feed it from `protectedResourceMetadata(...).metadataUrl` rather than by
65
+ * retyping the string — retyping is how the guard and the document come to
66
+ * disagree.
67
+ */
68
+ resourceMetadataUrl?: string;
42
69
  /**
43
70
  * CONTRACT.md §10.4 (contract 1.44) — the optional session-revocation feed.
44
71
  *
@@ -238,6 +265,16 @@ type CheckOutcome = {
238
265
  * when minting failed — the denial stands either way.
239
266
  */
240
267
  challenge?: string;
268
+ /**
269
+ * The decision's `reason_code` (§11 rule 9), surfaced verbatim so the
270
+ * caller can apply §28.5 rule 5 — `no_grant` is the one denial a bearer
271
+ * challenge may invite a client to retry, and `denied_by_rule` is not.
272
+ *
273
+ * Absent when the decision carried none, and absent on the `AuthzError`
274
+ * arm: a server 403 names no reason code, and §11 rule 9 requires an
275
+ * absent one to leave the outcome alone.
276
+ */
277
+ reasonCode?: string;
241
278
  } | {
242
279
  /** The authz transport failed — fail-closed → HTTP 503, never an allow. */
243
280
  kind: 'unavailable';
@@ -1,10 +1,10 @@
1
- import { A as AxiamClient, W as WebauthnWorkspace, a as WebauthnLoginResult, b as WebauthnCredential } from '../client-JWANinYZ.cjs';
1
+ import { A as AxiamClient, W as WebauthnWorkspace, a as WebauthnLoginResult, b as WebauthnCredential } from '../client-Dd_XaOtg.cjs';
2
+ import { S as Sensitive } from '../sensitive-BC_s7Rrd.cjs';
3
+ import { L as LoginResult } from '../types-zXSpiQM-.cjs';
2
4
  export { W as WebauthnFailure, c as classifyWebauthnError, w as webauthnErrorMessage } from '../webauthnErrors-fLgfOflO.cjs';
3
- import '../sensitive-BC_s7Rrd.cjs';
4
- import '../session-B0Lkz0X9.cjs';
5
+ import '../session-oiuBA1ZA.cjs';
5
6
  import 'axios';
6
7
  import '../telemetry-DrGqL4kb.cjs';
7
- import '../types-zXSpiQM-.cjs';
8
8
 
9
9
  /**
10
10
  * Whether this runtime can perform a WebAuthn ceremony at all.
@@ -59,6 +59,25 @@ interface WebauthnCeremonyOptions {
59
59
  * not passed — the SDK never infers it and never defaults it.
60
60
  */
61
61
  declare function webauthnRegister(client: AxiamClient, credentialName: string, kind?: AuthenticatorKind, options?: WebauthnCeremonyOptions): Promise<WebauthnCredential>;
62
+ /**
63
+ * Enrol a passkey or security key as the account's **first** factor, during
64
+ * forced login setup (§24.6, contract 1.45) — the setup-token twin of
65
+ * {@link webauthnRegister}, reached where `mfaSetupEnroll`/`mfaSetupConfirm`'s
66
+ * TOTP path is reached: `login()` answered `mfa_setup_required` because the
67
+ * tenant requires MFA and this account has none.
68
+ *
69
+ * Runs the full ceremony: `setup/register/start`, the authenticator, then
70
+ * `setup/register/finish` — which, unlike `webauthnRegisterFinish`,
71
+ * adopts credentials and completes the interrupted login (§25.2 rule 2,
72
+ * mirrored). The pair stays individually callable on `AxiamClient` for the
73
+ * same reason {@link webauthnRegister} is additive rather than the only way
74
+ * in (§24.6 rule 1).
75
+ *
76
+ * @param setupToken the token from `login()`'s `mfa_setup_required` outcome.
77
+ * @param kind optional `authenticatorAttachment` hint. Omitted entirely when
78
+ * not passed — the SDK never infers it and never defaults it.
79
+ */
80
+ declare function webauthnSetupRegister(client: AxiamClient, setupToken: Sensitive<string> | string, credentialName: string, kind?: AuthenticatorKind, options?: WebauthnCeremonyOptions): Promise<LoginResult>;
62
81
  /**
63
82
  * Sign in with a passkey as a **second factor** (§24.6).
64
83
  *
@@ -87,4 +106,4 @@ declare function base64UrlToBytes(value: string): Uint8Array<ArrayBuffer>;
87
106
  /** Encode bytes as unpadded base64url. */
88
107
  declare function bytesToBase64Url(buffer: ArrayBuffer | Uint8Array): string;
89
108
 
90
- export { type AuthenticatorKind, type WebauthnCeremonyOptions, base64UrlToBytes, bytesToBase64Url, isConditionalMediationAvailable, isWebauthnSupported, webauthnDiscoverableLogin, webauthnLogin, webauthnRegister };
109
+ export { type AuthenticatorKind, type WebauthnCeremonyOptions, base64UrlToBytes, bytesToBase64Url, isConditionalMediationAvailable, isWebauthnSupported, webauthnDiscoverableLogin, webauthnLogin, webauthnRegister, webauthnSetupRegister };
@@ -1,10 +1,10 @@
1
- import { A as AxiamClient, W as WebauthnWorkspace, a as WebauthnLoginResult, b as WebauthnCredential } from '../client-BXXwSvBI.js';
1
+ import { A as AxiamClient, W as WebauthnWorkspace, a as WebauthnLoginResult, b as WebauthnCredential } from '../client-BstRBtp8.js';
2
+ import { S as Sensitive } from '../sensitive-BC_s7Rrd.js';
3
+ import { L as LoginResult } from '../types-BOX-6Srv.js';
2
4
  export { W as WebauthnFailure, c as classifyWebauthnError, w as webauthnErrorMessage } from '../webauthnErrors-fLgfOflO.js';
3
- import '../sensitive-BC_s7Rrd.js';
4
- import '../session-fJCGq5jw.js';
5
+ import '../session-ymrHvMuJ.js';
5
6
  import 'axios';
6
7
  import '../telemetry-DrGqL4kb.js';
7
- import '../types-BOX-6Srv.js';
8
8
 
9
9
  /**
10
10
  * Whether this runtime can perform a WebAuthn ceremony at all.
@@ -59,6 +59,25 @@ interface WebauthnCeremonyOptions {
59
59
  * not passed — the SDK never infers it and never defaults it.
60
60
  */
61
61
  declare function webauthnRegister(client: AxiamClient, credentialName: string, kind?: AuthenticatorKind, options?: WebauthnCeremonyOptions): Promise<WebauthnCredential>;
62
+ /**
63
+ * Enrol a passkey or security key as the account's **first** factor, during
64
+ * forced login setup (§24.6, contract 1.45) — the setup-token twin of
65
+ * {@link webauthnRegister}, reached where `mfaSetupEnroll`/`mfaSetupConfirm`'s
66
+ * TOTP path is reached: `login()` answered `mfa_setup_required` because the
67
+ * tenant requires MFA and this account has none.
68
+ *
69
+ * Runs the full ceremony: `setup/register/start`, the authenticator, then
70
+ * `setup/register/finish` — which, unlike `webauthnRegisterFinish`,
71
+ * adopts credentials and completes the interrupted login (§25.2 rule 2,
72
+ * mirrored). The pair stays individually callable on `AxiamClient` for the
73
+ * same reason {@link webauthnRegister} is additive rather than the only way
74
+ * in (§24.6 rule 1).
75
+ *
76
+ * @param setupToken the token from `login()`'s `mfa_setup_required` outcome.
77
+ * @param kind optional `authenticatorAttachment` hint. Omitted entirely when
78
+ * not passed — the SDK never infers it and never defaults it.
79
+ */
80
+ declare function webauthnSetupRegister(client: AxiamClient, setupToken: Sensitive<string> | string, credentialName: string, kind?: AuthenticatorKind, options?: WebauthnCeremonyOptions): Promise<LoginResult>;
62
81
  /**
63
82
  * Sign in with a passkey as a **second factor** (§24.6).
64
83
  *
@@ -87,4 +106,4 @@ declare function base64UrlToBytes(value: string): Uint8Array<ArrayBuffer>;
87
106
  /** Encode bytes as unpadded base64url. */
88
107
  declare function bytesToBase64Url(buffer: ArrayBuffer | Uint8Array): string;
89
108
 
90
- export { type AuthenticatorKind, type WebauthnCeremonyOptions, base64UrlToBytes, bytesToBase64Url, isConditionalMediationAvailable, isWebauthnSupported, webauthnDiscoverableLogin, webauthnLogin, webauthnRegister };
109
+ export { type AuthenticatorKind, type WebauthnCeremonyOptions, base64UrlToBytes, bytesToBase64Url, isConditionalMediationAvailable, isWebauthnSupported, webauthnDiscoverableLogin, webauthnLogin, webauthnRegister, webauthnSetupRegister };
@@ -92,6 +92,12 @@ async function webauthnRegister(client, credentialName, kind, options) {
92
92
  const credential = await createCredential(challenge, kind, options?.signal);
93
93
  return client.webauthnRegisterFinish(stateToken, credentialName, credential);
94
94
  }
95
+ async function webauthnSetupRegister(client, setupToken, credentialName, kind, options) {
96
+ requireSupport("webauthnSetupRegister");
97
+ const { challenge, stateToken } = await client.webauthnSetupRegisterStart(setupToken);
98
+ const credential = await createCredential(challenge, kind, options?.signal);
99
+ return client.webauthnSetupRegisterFinish(setupToken, stateToken, credentialName, credential);
100
+ }
95
101
  async function webauthnLogin(client, challengeToken, options) {
96
102
  requireSupport("webauthnLogin");
97
103
  const { challenge, stateToken } = await client.webauthnAuthenticateStart(challengeToken);
@@ -209,5 +215,6 @@ exports.webauthnDiscoverableLogin = webauthnDiscoverableLogin;
209
215
  exports.webauthnErrorMessage = webauthnErrorMessage;
210
216
  exports.webauthnLogin = webauthnLogin;
211
217
  exports.webauthnRegister = webauthnRegister;
218
+ exports.webauthnSetupRegister = webauthnSetupRegister;
212
219
  //# sourceMappingURL=index.js.map
213
220
  //# sourceMappingURL=index.js.map