@introspection-sdk/aauth-resource 0.0.0 → 0.37.0

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/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2026 Introspection AI Inc.
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # @introspection-sdk/aauth-resource
2
+
3
+ Make an HTTP API a native AAuth resource ([draft-hardt-oauth-aauth-protocol](https://github.com/dickhardt/AAuth) `-11`, three-party): the resource side of what [`@introspection-sdk/person-server`](../introspection-person-server) is to the person's side. Handlers take a Web `Request` and return a `Response`.
4
+
5
+ - **Discovery:** `/.well-known/aauth-resource.json` and its JWKS.
6
+ - **Signed facts:** `sign()` a quote or an offer, `verifySigned()` it when it comes back, so the price a Person Server weighs is the resource's, not the agent's.
7
+ - **One call to admit an operation:** `authorize()` verifies the request's RFC 9421 signature and the token it presents, asks for a person token, then answers `401` with a resource token for exactly this call (an R3 proposal of its parameters, readable only by the person's Person Server, and its price as a budget), and admits it once an auth token for that proposal comes back.
8
+ - **R3:** serves each proposal to the Person Server it was published for and no one else.
9
+
10
+ Policy is not the resource's job: who approves, and within what budget, is the Person Server's.
11
+
12
+ ## Use
13
+
14
+ ```ts
15
+ import {
16
+ createAAuthResource,
17
+ respond,
18
+ } from "@introspection-sdk/aauth-resource";
19
+
20
+ const resource = await createAAuthResource({
21
+ issuer: "https://works.example", // https://host
22
+ name: "Works API",
23
+ scopes: { "works.order": "Issue a work order on a quote" },
24
+ budgetUnits: [{ unit: "AUD", decimals: 2 }],
25
+ personServers: ["https://ps.example"], // closed list: verifying fetches their keys
26
+ agentProviders: ["https://api.introspection.dev"],
27
+ signingKey: process.env.WORKS_SIGNING_KEY, // PKCS#8 Ed25519 PEM; a fresh key otherwise
28
+ });
29
+
30
+ export async function handle(request: Request): Promise<Response> {
31
+ const served = await resource.handle(request); // well-known documents and R3 proposals
32
+ if (served) return served;
33
+ return respond(async () => {
34
+ const body = await request.text();
35
+ const { quote_id, quote } = JSON.parse(body);
36
+ const facts = await resource.verifySigned(quote); // 400 unless this resource signed it
37
+ const authz = await resource.authorize(request, body, {
38
+ scope: "works.order",
39
+ operation: { action: "order" },
40
+ parameters: { quote_id }, // exactly what the approval binds
41
+ summary: `Order ${quote_id} for $${Number(facts.total_cents) / 100}`,
42
+ budget: { amount: Number(facts.total_cents), unit: "AUD", decimals: 2 },
43
+ });
44
+ if (!authz.ok) return authz.response; // the 401 challenge, or a problem
45
+ return Response.json({
46
+ ordered: quote_id,
47
+ for: authz.sub,
48
+ mission: authz.mission_s256,
49
+ });
50
+ });
51
+ }
52
+ ```
53
+
54
+ `authz.jti` is the auth token's id: keep it with what the call created to answer a retried call with the same result.
55
+
56
+ Two resources are built on it:
57
+
58
+ - [`examples/aauth-travel`](../../examples/aauth-travel)'s booking provider (`lib/booking.ts`), served by Next.js under a rewritten path, so it passes `authorize(…, { url })` and lets its router hand `serveProposal` the key.
59
+ - The strata works API in [introspection-org/recipe-strata-vendor](https://github.com/introspection-org/recipe-strata-vendor) (`aauth-strata/`).
60
+
61
+ ## Options worth knowing
62
+
63
+ - `authorize(request, body, ask, { url })`: `ask` may be a function, run only once the presented token verifies, so a resource challenges before it validates the call. `url` is the public URL the request was addressed to, when the app serves it under another path.
64
+ - `onPropose`: called as each call is put to a Person Server, e.g. to log or narrate it.
65
+ - `r3Store`: where proposals live until their Person Server reads them; in memory by default, so a multi-process deployment supplies a shared one.
@@ -0,0 +1,3 @@
1
+ export { createAAuthResource, type AAuthResource, type AAuthResourceOptions, type Authorization, type AuthorizeRequest, type Budget, type Identification, respond, } from "./resource.js";
2
+ export { AAuthError, problem } from "@introspection-sdk/person-server";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,OAAO,GACR,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { createAAuthResource, respond, } from "./resource.js";
2
+ export { AAuthError, problem } from "@introspection-sdk/person-server";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAOnB,OAAO,GACR,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * An HTTP API as a native AAuth resource. Policy is not the resource's job: an
3
+ * operation that needs a person's say asks for a person token from their Person
4
+ * Server, then for an auth token for exactly this call, which the resource
5
+ * describes in a per-call R3 proposal only that Person Server may read, with
6
+ * its price as a budget any Person Server can weigh without reading R3.
7
+ */
8
+ import { type R3Store, type VerifiedToken } from "@aauth/resource";
9
+ import { type JWK, type JWTPayload } from "jose";
10
+ /** draft-hardt-aauth-budgets: an amount in a unit's smallest denomination. */
11
+ export interface Budget {
12
+ amount: number;
13
+ unit: string;
14
+ decimals: number;
15
+ }
16
+ export interface AAuthResourceOptions {
17
+ /** This resource's identifier: `https://host`, the origin agents call. */
18
+ issuer: string;
19
+ name: string;
20
+ description?: string;
21
+ /** Each scope this resource asks Person Servers to approve, described for people. */
22
+ scopes: Record<string, string>;
23
+ /** The R3 vocabulary its proposals are written in; `{issuer}/r3/vocabulary` by default. */
24
+ vocabulary?: string;
25
+ /** The budget units its resource tokens carry, advertised in its metadata. */
26
+ budgetUnits?: {
27
+ unit: string;
28
+ decimals: number;
29
+ }[];
30
+ /**
31
+ * Person Servers whose people it serves. Verifying a token fetches its
32
+ * issuer's keys, which is egress, so the list is closed.
33
+ */
34
+ personServers: readonly string[];
35
+ /** Agent Providers whose agent tokens it accepts. */
36
+ agentProviders: readonly string[];
37
+ /** A PKCS#8 PEM to keep the key across restarts; a fresh key otherwise. */
38
+ signingKey?: string;
39
+ kid?: string;
40
+ /** Where proposals live until their Person Server reads them; in memory by default. */
41
+ r3Store?: R3Store;
42
+ /** Called as each call is put to a Person Server, e.g. to log or narrate it. */
43
+ onPropose?: (proposal: {
44
+ ps: string;
45
+ scope: string;
46
+ parameters: Record<string, string>;
47
+ mission_s256?: string;
48
+ }) => void;
49
+ }
50
+ /** What one call asks the person's Person Server to approve. */
51
+ export interface AuthorizeRequest {
52
+ scope: string;
53
+ /** The operation, as the vocabulary names it, e.g. `{ action: "order" }`. */
54
+ operation: Record<string, string>;
55
+ /** Exactly the parameters an approval binds: a retry must present the same. */
56
+ parameters: Record<string, string>;
57
+ /** One line for whoever approves it. */
58
+ summary: string;
59
+ /** The call's price, so a Person Server can weigh it against a mission's budget. */
60
+ budget?: Budget;
61
+ }
62
+ export type Authorization = {
63
+ ok: true;
64
+ token: VerifiedToken;
65
+ /** The person the call is for, as their Person Server names them. */
66
+ sub: string;
67
+ /** The Person Server that approved it. */
68
+ ps: string;
69
+ mission_s256?: string;
70
+ /** The auth token's `jti`, to make a retried call idempotent. */
71
+ jti: string;
72
+ } | {
73
+ ok: false;
74
+ response: Response;
75
+ };
76
+ export type Identification = {
77
+ ok: true;
78
+ token: VerifiedToken;
79
+ /** The person the call is for, as their Person Server names them. */
80
+ sub: string;
81
+ /** The person's Person Server. */
82
+ ps: string;
83
+ mission_s256?: string;
84
+ } | {
85
+ ok: false;
86
+ response: Response;
87
+ };
88
+ export interface AAuthResource {
89
+ readonly issuer: string;
90
+ /** `/.well-known/aauth-resource.json`. */
91
+ metadata(): Record<string, unknown>;
92
+ /** `/.well-known/jwks.json`. */
93
+ jwks(): {
94
+ keys: JWK[];
95
+ };
96
+ /** Sign facts this resource vouches for, such as a quote; `iss` is this resource. */
97
+ sign(claims: Record<string, unknown>): Promise<string>;
98
+ /** Verify a token this resource signed; a 400 problem otherwise. */
99
+ verifySigned(token: string): Promise<JWTPayload>;
100
+ /**
101
+ * Admit a call on an auth token whose R3 proposal is exactly `ask`, or answer
102
+ * with the challenge for what it lacks. `body` is the raw request body the
103
+ * signature covers. `ask` may be a function, run once the presented token
104
+ * verifies, so a resource challenges before it validates the call; an error
105
+ * it throws propagates. `url` is the public URL the request was addressed to,
106
+ * when the app serves it under another path; `{issuer}{path}` by default.
107
+ */
108
+ authorize(request: Request, body: string, ask: AuthorizeRequest | ((token: VerifiedToken) => AuthorizeRequest | Promise<AuthorizeRequest>), options?: {
109
+ url?: string;
110
+ }): Promise<Authorization>;
111
+ /**
112
+ * Admit a call on a person token alone, for an operation that spends nothing
113
+ * and needs no one's approval, such as undoing the person's own earlier call:
114
+ * it says who the agent acts for and under which mission, and the resource
115
+ * checks the call against that. Answers the person-token challenge otherwise.
116
+ */
117
+ authenticate(request: Request, body: string, options?: {
118
+ url?: string;
119
+ }): Promise<Identification>;
120
+ /** An R3 proposal, to the Person Server it was published for and no one else. */
121
+ serveProposal(request: Request, key: string): Promise<Response>;
122
+ /** Serve this resource's discovery documents and R3 proposals; undefined for other paths. */
123
+ handle(request: Request): Promise<Response | undefined>;
124
+ }
125
+ /** Run a handler, answering any AAuthError as a problem response. */
126
+ export declare function respond(run: () => Promise<Response>): Promise<Response>;
127
+ export declare function createAAuthResource(options: AAuthResourceOptions): Promise<AAuthResource>;
128
+ //# sourceMappingURL=resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAGL,KAAK,OAAO,EAEZ,KAAK,aAAa,EAOnB,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAEL,KAAK,GAAG,EACR,KAAK,UAAU,EAQhB,MAAM,MAAM,CAAC;AAOd,8EAA8E;AAC9E,MAAM,WAAW,MAAM;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,0EAA0E;IAC1E,MAAM,EAAE,MAAM,CAAC;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AC,aAAa,CAAC,CAAC;IAC1B;;;;;OAKG;IACH,YAAY,CACV,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,GACzB,OAAO,CAAC,cAAc,CAAC,CAAC;IAC3B,iFAAiF;IACjF,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAChE,6FAA6F;IAC7F,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC;CACzD;AAED,qEAAqE;AACrE,wBAAsB,OAAO,CAAC,GAAG,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAQ7E;AAkED,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,aAAa,CAAC,CA4SxB"}
@@ -0,0 +1,281 @@
1
+ /**
2
+ * An HTTP API as a native AAuth resource. Policy is not the resource's job: an
3
+ * operation that needs a person's say asks for a person token from their Person
4
+ * Server, then for an auth token for exactly this call, which the resource
5
+ * describes in a per-call R3 proposal only that Person Server may read, with
6
+ * its price as a budget any Person Server can weigh without reading R3.
7
+ */
8
+ import { AAuthTokenError, MemoryR3Store, buildRequirementHeader, createResourceToken, publishProposal, serveR3Document, verifyProposalParameters, verifyToken, } from "@aauth/resource";
9
+ import { generateAcceptSignatureSchemeHeader, generateSignatureErrorHeader, verify, } from "@hellocoop/httpsig";
10
+ import { SignJWT, createLocalJWKSet, decodeJwt, exportJWK, generateKeyPair, importPKCS8, jwtVerify, } from "jose";
11
+ import { AAuthError, problem } from "@introspection-sdk/person-server";
12
+ /** RFC 9864's fully-specified identifier; the polymorphic `EdDSA` is not used. */
13
+ const ALG = "Ed25519";
14
+ /** Run a handler, answering any AAuthError as a problem response. */
15
+ export async function respond(run) {
16
+ try {
17
+ return await run();
18
+ }
19
+ catch (err) {
20
+ if (err instanceof AAuthError)
21
+ return problem(err.status, err.error, err.message, err.headers);
22
+ throw err;
23
+ }
24
+ }
25
+ function signatureError(code, detail) {
26
+ const headers = {
27
+ "Signature-Error": generateSignatureErrorHeader({ error: code }),
28
+ };
29
+ if (code === "unsupported_scheme")
30
+ headers["Accept-Signature-Scheme"] = generateAcceptSignatureSchemeHeader([
31
+ "jwt",
32
+ ]);
33
+ return new AAuthError(401, code, detail, headers);
34
+ }
35
+ const challenge = (requirement, detail) => Response.json({ error: "unauthorized", detail }, {
36
+ status: 401,
37
+ headers: {
38
+ "AAuth-Requirement": buildRequirementHeader(requirement),
39
+ "Content-Type": "application/problem+json",
40
+ },
41
+ });
42
+ // #region verify-signature
43
+ /** Verify the RFC 9421 signature on a request as addressed to `url`; a body must be covered by `content-digest`. */
44
+ async function verifySignature(request, body, url) {
45
+ const { host, pathname } = new URL(url);
46
+ const result = await verify({
47
+ method: request.method,
48
+ authority: host,
49
+ path: pathname,
50
+ headers: request.headers,
51
+ ...(body ? { body } : {}),
52
+ }, { requireContentDigest: true, supportedAlgorithms: ["Ed25519", "ES256"] });
53
+ if (!result.verified) {
54
+ const code = result.signatureError?.error ?? "invalid_signature";
55
+ throw signatureError(code, result.error ?? "signature does not verify");
56
+ }
57
+ return {
58
+ keyType: result.keyType,
59
+ thumbprint: result.thumbprint,
60
+ ...(result.jwt ? { jwt: result.jwt.raw } : {}),
61
+ ...(result.jwks_uri ? { server: result.jwks_uri.id } : {}),
62
+ };
63
+ }
64
+ // #endregion
65
+ export async function createAAuthResource(options) {
66
+ const issuer = options.issuer.replace(/\/+$/, "");
67
+ if (!issuer.startsWith("https://"))
68
+ throw new Error("issuer must be an https origin");
69
+ const vocabulary = options.vocabulary ?? `${issuer}/r3/vocabulary`;
70
+ const r3 = options.r3Store ?? new MemoryR3Store();
71
+ const kid = options.kid ?? `${new URL(issuer).hostname}-1`;
72
+ const privateKey = options.signingKey
73
+ ? await importPKCS8(options.signingKey, ALG, { extractable: true })
74
+ : (await generateKeyPair(ALG, { extractable: true })).privateKey;
75
+ const publicJwk = { ...(await exportJWK(privateKey)), kid, alg: ALG };
76
+ delete publicJwk.d;
77
+ const keys = { keys: [{ ...publicJwk, use: "sig" }] };
78
+ const signWithHeader = (claims, header) => new SignJWT(claims)
79
+ .setProtectedHeader({ ...header, alg: ALG, kid })
80
+ .sign(privateKey);
81
+ const issuers = {
82
+ agent: options.agentProviders,
83
+ person: options.personServers,
84
+ auth: options.personServers,
85
+ };
86
+ /** The token a signed request presented: a kind it accepts, from an issuer it trusts, binding the signing key. */
87
+ async function verifyPresented(signed, accept) {
88
+ if (signed.keyType !== "jwt" || !signed.jwt)
89
+ throw signatureError("unsupported_scheme", "sign with sig=jwt");
90
+ let claims;
91
+ try {
92
+ claims = decodeJwt(signed.jwt);
93
+ }
94
+ catch {
95
+ throw signatureError("invalid_jwt", "not a JWT");
96
+ }
97
+ // Checked before verifying, since verifying fetches the issuer's keys.
98
+ if (!accept.some((kind) => issuers[kind]?.includes(String(claims.iss))))
99
+ throw signatureError("invalid_jwt", `${String(claims.iss)} is not trusted here`);
100
+ return verifyToken({
101
+ jwt: signed.jwt,
102
+ httpSignatureThumbprint: signed.thumbprint,
103
+ resource: issuer,
104
+ accept,
105
+ }).catch((err) => {
106
+ const code = err instanceof AAuthTokenError ? err.code : "invalid_jwt";
107
+ throw signatureError(code === "token_expired" ? "expired_jwt" : "invalid_jwt", err.message);
108
+ });
109
+ }
110
+ // #region propose
111
+ /** `401 requirement=auth-token`: a resource token for this one call, its proposal readable by the person's Person Server alone. */
112
+ async function propose(token, agentJkt, ask) {
113
+ const ps = token.type === "auth" ? token.ps : token.iss;
114
+ const proposal = await publishProposal({
115
+ vocabulary,
116
+ operation: ask.operation,
117
+ parameters: ask.parameters,
118
+ display: { summary: ask.summary },
119
+ store: r3,
120
+ baseUri: `${issuer}/r3`,
121
+ authorized: [ps],
122
+ });
123
+ const resourceToken = await createResourceToken({
124
+ resource: issuer,
125
+ audience: ps,
126
+ presentedToken: token,
127
+ agentJkt,
128
+ scope: ask.scope,
129
+ kid,
130
+ r3: { uri: proposal.r3_uri, s256: proposal.r3_s256 },
131
+ }, (claims, header) => signWithHeader({ ...claims, ...(ask.budget ? { budget: ask.budget } : {}) }, header));
132
+ options.onPropose?.({
133
+ ps,
134
+ scope: ask.scope,
135
+ parameters: ask.parameters,
136
+ ...("mission_s256" in token && token.mission_s256
137
+ ? { mission_s256: token.mission_s256 }
138
+ : {}),
139
+ });
140
+ return challenge({ requirement: "auth-token", resourceToken }, `take the resource token to ${ps}`);
141
+ }
142
+ // #endregion
143
+ /**
144
+ * The person or auth token a signed call presents, with the signed request,
145
+ * or the challenge for a person token when it presents none.
146
+ */
147
+ async function presented(request, body, url) {
148
+ if (!request.headers.get("signature-key"))
149
+ return {
150
+ challenge: challenge({ requirement: "person-token" }, "sign the request"),
151
+ };
152
+ const signed = await verifySignature(request, body, url ?? `${issuer}${new URL(request.url).pathname}`);
153
+ const token = await verifyPresented(signed, ["agent", "person", "auth"]);
154
+ if (token.type === "agent")
155
+ return {
156
+ challenge: challenge({ requirement: "person-token" }, "present a person token from the person's Person Server"),
157
+ };
158
+ return { signed, token };
159
+ }
160
+ /** Who a verified token is for, and under which mission. */
161
+ const caller = (token) => ({
162
+ token,
163
+ sub: token.sub,
164
+ ps: token.type === "auth" ? token.ps : token.iss,
165
+ ...("mission_s256" in token && token.mission_s256
166
+ ? { mission_s256: token.mission_s256 }
167
+ : {}),
168
+ });
169
+ /** Run `admit`, answering an AAuthError as its problem response. */
170
+ async function admitting(admit) {
171
+ try {
172
+ return await admit();
173
+ }
174
+ catch (err) {
175
+ if (err instanceof AAuthError)
176
+ return {
177
+ ok: false,
178
+ response: problem(err.status, err.error, err.message, err.headers),
179
+ };
180
+ throw err;
181
+ }
182
+ }
183
+ async function authorize(request, body, asked, { url } = {}) {
184
+ return admitting(async () => {
185
+ const call = await presented(request, body, url);
186
+ if ("challenge" in call)
187
+ return { ok: false, response: call.challenge };
188
+ const { signed, token } = call;
189
+ const ask = typeof asked === "function" ? await asked(token) : asked;
190
+ if (token.type === "auth" && token.r3_s256) {
191
+ const approved = await verifyProposalParameters({
192
+ store: r3,
193
+ r3_s256: token.r3_s256,
194
+ presented: ask.parameters,
195
+ operation: ask.operation,
196
+ }).then(() => true, () => false);
197
+ if (approved)
198
+ return {
199
+ ok: true,
200
+ ...caller(token),
201
+ jti: String(token.claims.jti),
202
+ };
203
+ }
204
+ return {
205
+ ok: false,
206
+ response: await propose(token, signed.thumbprint, ask),
207
+ };
208
+ });
209
+ }
210
+ async function authenticate(request, body, { url } = {}) {
211
+ return admitting(async () => {
212
+ const call = await presented(request, body, url);
213
+ if ("challenge" in call)
214
+ return { ok: false, response: call.challenge };
215
+ return { ok: true, ...caller(call.token) };
216
+ });
217
+ }
218
+ // #region serve-r3
219
+ /** An R3 proposal, to the Person Server it was published for and no one else. */
220
+ async function serveProposal(request, key) {
221
+ const id = /jwks_uri;(?:[^,]*;)?id="([^"]+)"/.exec(request.headers.get("signature-key") ?? "")?.[1];
222
+ if (!id || !options.personServers.includes(id))
223
+ throw signatureError("invalid_signature", "only the person's Person Server reads a proposal");
224
+ const signed = await verifySignature(request, undefined, `${issuer}/r3/${key}`);
225
+ const served = await serveR3Document({
226
+ store: r3,
227
+ key,
228
+ signer: signed.server,
229
+ });
230
+ return new Response(served.body, {
231
+ status: served.status,
232
+ headers: served.headers,
233
+ });
234
+ }
235
+ // #endregion
236
+ const metadata = () => ({
237
+ issuer,
238
+ jwks_uri: `${issuer}/.well-known/jwks.json`,
239
+ access_mode: "auth-token",
240
+ name: options.name,
241
+ ...(options.description ? { description: options.description } : {}),
242
+ scope_descriptions: options.scopes,
243
+ r3_vocabularies: [vocabulary],
244
+ ...(options.budgetUnits ? { budget_units: options.budgetUnits } : {}),
245
+ additional_signature_components: ["content-type", "content-digest"],
246
+ });
247
+ return {
248
+ issuer,
249
+ metadata,
250
+ jwks: () => keys,
251
+ sign: (claims) => signWithHeader({ ...claims, iss: issuer }, { typ: "JWT" }),
252
+ async verifySigned(token) {
253
+ try {
254
+ return (await jwtVerify(token, createLocalJWKSet(keys), {
255
+ issuer,
256
+ algorithms: [ALG],
257
+ })).payload;
258
+ }
259
+ catch {
260
+ throw new AAuthError(400, "invalid_request", "not signed by this resource");
261
+ }
262
+ },
263
+ authorize,
264
+ authenticate,
265
+ serveProposal,
266
+ async handle(request) {
267
+ const { pathname } = new URL(request.url);
268
+ if (request.method !== "GET")
269
+ return undefined;
270
+ if (pathname === "/.well-known/aauth-resource.json")
271
+ return Response.json(metadata());
272
+ if (pathname === "/.well-known/jwks.json")
273
+ return Response.json(keys);
274
+ const key = /^\/r3\/([^/]+)$/.exec(pathname)?.[1];
275
+ if (key && key !== "vocabulary")
276
+ return respond(() => serveProposal(request, key));
277
+ return undefined;
278
+ },
279
+ };
280
+ }
281
+ //# sourceMappingURL=resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.js","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACL,eAAe,EACf,aAAa,EAIb,sBAAsB,EACtB,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,mCAAmC,EACnC,4BAA4B,EAE5B,MAAM,GACP,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAIL,OAAO,EACP,iBAAiB,EACjB,SAAS,EACT,SAAS,EACT,eAAe,EACf,WAAW,EACX,SAAS,GACV,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAEvE,kFAAkF;AAClF,MAAM,GAAG,GAAG,SAAS,CAAC;AA6HtB,qEAAqE;AACrE,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,GAA4B;IACxD,IAAI,CAA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C,OAAO,CAAC;YACZ,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,IAAI,UAAU,CAClB,GAAG,EACH,iBAAiB,EACjB,6BAA6B,CAC9B,CAAC;YACJ,CAAC;QACH,CAAC;QACD,SAAS;QACT,YAAY;QACZ,aAAa;QACb,KAAK,CAAC,MAAM,CAAC,OAAO;YAClB,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAC1C,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK;gBAAE,OAAO,SAAS,CAAC;YAC/C,IAAI,QAAQ,KAAK,kCAAkC;gBACjD,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;YACnC,IAAI,QAAQ,KAAK,wBAAwB;gBAAE,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACtE,MAAM,GAAG,GAAG,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAClD,IAAI,GAAG,IAAI,GAAG,KAAK,YAAY;gBAC7B,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;YACpD,OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1 +1,46 @@
1
- {"name":"@introspection-sdk/aauth-resource","version":"0.0.0"}
1
+ {
2
+ "name": "@introspection-sdk/aauth-resource",
3
+ "version": "0.37.0",
4
+ "license": "Apache-2.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/introspection-org/introspection-js-sdk.git",
8
+ "directory": "packages/introspection-aauth-resource"
9
+ },
10
+ "description": "Make an HTTP API an AAuth resource (draft-hardt-oauth-aauth-protocol -11): signed quotes, the person-token and auth-token challenges with an R3 proposal and a budget, and serving that proposal to its Person Server, as Request → Response helpers",
11
+ "engines": {
12
+ "node": ">=22"
13
+ },
14
+ "type": "module",
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ }
22
+ },
23
+ "files": [
24
+ "dist/"
25
+ ],
26
+ "dependencies": {
27
+ "@aauth/resource": "^3.0.0",
28
+ "@hellocoop/httpsig": "^2.6.0",
29
+ "jose": "^6.2.12",
30
+ "@introspection-sdk/person-server": "0.37.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^22.20.5",
34
+ "eslint": "^9.39.5",
35
+ "typescript": "5.9.3",
36
+ "@repo/eslint-config": "0.0.0",
37
+ "@repo/typescript-config": "0.0.0"
38
+ },
39
+ "scripts": {
40
+ "lint": "eslint . --max-warnings 0",
41
+ "check-types": "tsc --noEmit",
42
+ "build": "rm -rf dist && tsc",
43
+ "clean": "rm -rf dist",
44
+ "check:package": "publint --strict && attw --pack . --profile esm-only"
45
+ }
46
+ }