@c9up/visa 0.1.1 → 0.1.3

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 (80) hide show
  1. package/dist/VisaManager.d.ts +42 -7
  2. package/dist/VisaManager.d.ts.map +1 -1
  3. package/dist/VisaManager.js +89 -3
  4. package/dist/VisaManager.js.map +1 -1
  5. package/dist/VisaProvider.d.ts.map +1 -1
  6. package/dist/VisaProvider.js +56 -0
  7. package/dist/VisaProvider.js.map +1 -1
  8. package/dist/authorize.d.ts +18 -0
  9. package/dist/authorize.d.ts.map +1 -1
  10. package/dist/authorize.js +6 -0
  11. package/dist/authorize.js.map +1 -1
  12. package/dist/clients.d.ts +1 -1
  13. package/dist/clients.d.ts.map +1 -1
  14. package/dist/clients.js +9 -1
  15. package/dist/clients.js.map +1 -1
  16. package/dist/config.d.ts +35 -0
  17. package/dist/config.d.ts.map +1 -1
  18. package/dist/config.js.map +1 -1
  19. package/dist/errors.d.ts +9 -3
  20. package/dist/errors.d.ts.map +1 -1
  21. package/dist/errors.js.map +1 -1
  22. package/dist/guard.d.ts +21 -0
  23. package/dist/guard.d.ts.map +1 -1
  24. package/dist/guard.js +25 -1
  25. package/dist/guard.js.map +1 -1
  26. package/dist/index.d.ts +5 -2
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +3 -0
  29. package/dist/index.js.map +1 -1
  30. package/dist/introspect.d.ts +9 -1
  31. package/dist/introspect.d.ts.map +1 -1
  32. package/dist/introspect.js +18 -1
  33. package/dist/introspect.js.map +1 -1
  34. package/dist/protectedResource.d.ts +81 -0
  35. package/dist/protectedResource.d.ts.map +1 -0
  36. package/dist/protectedResource.js +124 -0
  37. package/dist/protectedResource.js.map +1 -0
  38. package/dist/register.d.ts +107 -0
  39. package/dist/register.d.ts.map +1 -0
  40. package/dist/register.js +203 -0
  41. package/dist/register.js.map +1 -0
  42. package/dist/resource.d.ts +50 -0
  43. package/dist/resource.d.ts.map +1 -0
  44. package/dist/resource.js +101 -0
  45. package/dist/resource.js.map +1 -0
  46. package/dist/store.d.ts +25 -0
  47. package/dist/store.d.ts.map +1 -1
  48. package/dist/stores/atlas.d.ts +7 -0
  49. package/dist/stores/atlas.d.ts.map +1 -1
  50. package/dist/stores/atlas.js +70 -16
  51. package/dist/stores/atlas.js.map +1 -1
  52. package/dist/stores/memory.d.ts +4 -0
  53. package/dist/stores/memory.d.ts.map +1 -1
  54. package/dist/stores/memory.js +25 -0
  55. package/dist/stores/memory.js.map +1 -1
  56. package/dist/token.d.ts +2 -0
  57. package/dist/token.d.ts.map +1 -1
  58. package/dist/token.js +21 -1
  59. package/dist/token.js.map +1 -1
  60. package/dist/types.d.ts +51 -0
  61. package/dist/types.d.ts.map +1 -1
  62. package/package.json +1 -1
  63. package/src/VisaManager.ts +122 -3
  64. package/src/VisaProvider.ts +64 -0
  65. package/src/authorize.ts +27 -0
  66. package/src/clients.ts +10 -0
  67. package/src/config.ts +35 -0
  68. package/src/errors.ts +16 -2
  69. package/src/guard.ts +41 -1
  70. package/src/index.ts +25 -0
  71. package/src/introspect.ts +17 -0
  72. package/src/protectedResource.ts +171 -0
  73. package/src/register.ts +335 -0
  74. package/src/resource.ts +123 -0
  75. package/src/store.ts +29 -0
  76. package/src/stores/atlas.ts +99 -15
  77. package/src/stores/memory.ts +33 -0
  78. package/src/token.ts +45 -1
  79. package/src/types.ts +52 -0
  80. package/stubs/database/migrations/9000_create_visa_tables.stub +9 -0
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Clients that register themselves (RFC 7591).
3
+ *
4
+ * An MCP client such as claude.ai or ChatGPT has nobody to fill in a form for
5
+ * it: it discovers this server, registers, and comes back with an id. Without
6
+ * this the only way in is a human pasting credentials somewhere.
7
+ *
8
+ * OFF unless the application turns it on, and that is the important part. Open
9
+ * registration means anyone who can reach the endpoint can create a client —
10
+ * the RFC says a server SHOULD allow it for interoperability, and also says
11
+ * the endpoint MAY be protected (§1.2, §3). The safe default here is the one
12
+ * the RFC permits rather than the one it encourages, because an authorization
13
+ * server that silently accepts registrations is a thing nobody asked for. Turn
14
+ * it on deliberately, and with an initial access token if the deployment is
15
+ * not meant to be open.
16
+ *
17
+ * A registered client gets exactly what this server allows: the grants,
18
+ * scopes and auth methods in the configuration, never what the request asked
19
+ * for. That is the difference between letting a client name itself and letting
20
+ * it decide what it may do.
21
+ */
22
+ import type { Client, ClientAuthMethod, GrantType } from "./types.js";
23
+ /** The metadata a request may send (§2). Unknown members are ignored. */
24
+ export interface ClientRegistrationRequest {
25
+ redirect_uris?: unknown;
26
+ token_endpoint_auth_method?: unknown;
27
+ grant_types?: unknown;
28
+ response_types?: unknown;
29
+ client_name?: unknown;
30
+ client_uri?: unknown;
31
+ logo_uri?: unknown;
32
+ scope?: unknown;
33
+ contacts?: unknown;
34
+ tos_uri?: unknown;
35
+ policy_uri?: unknown;
36
+ software_id?: unknown;
37
+ software_version?: unknown;
38
+ software_statement?: unknown;
39
+ /**
40
+ * Whatever else the client sent.
41
+ *
42
+ * §2 says a server ignores metadata it does not understand, and this is a
43
+ * parsed HTTP body — a client that sends `client_id` hoping to pick its own
44
+ * is a real thing, and it lands here rather than being a type error nobody
45
+ * sees at run time.
46
+ */
47
+ [member: string]: unknown;
48
+ }
49
+ /** The 201 body (§3.2.1). */
50
+ export interface ClientRegistrationResponse {
51
+ client_id: string;
52
+ client_secret?: string;
53
+ /** Seconds since the epoch. */
54
+ client_id_issued_at: number;
55
+ /** REQUIRED when a secret was issued. `0` means it does not expire. */
56
+ client_secret_expires_at?: number;
57
+ redirect_uris: string[];
58
+ grant_types: GrantType[];
59
+ token_endpoint_auth_method: ClientAuthMethod;
60
+ client_name: string;
61
+ scope?: string;
62
+ }
63
+ export interface RegistrationOptions {
64
+ /** Nothing happens unless this is true. */
65
+ enabled?: boolean;
66
+ /**
67
+ * Require this bearer token on the registration request.
68
+ *
69
+ * Left out, the endpoint is open — which is what an MCP client that has
70
+ * never met you needs, and what a deployment on the public internet should
71
+ * think about before shipping.
72
+ */
73
+ initialAccessToken?: string;
74
+ /** What a self-registered client may ever ask for. Defaults to none. */
75
+ scopes?: readonly string[];
76
+ /** Which grants it may use. Defaults to the authorization code flow and refresh. */
77
+ grantTypes?: readonly GrantType[];
78
+ /** Seconds until an issued secret expires. Omitted means it does not (§3.2.1). */
79
+ secretTtlSeconds?: number;
80
+ }
81
+ /**
82
+ * Check a registration request and say what the client may be.
83
+ *
84
+ * Returns the client to store and the plaintext secret, if one was issued —
85
+ * the caller persists the first and hands back the second, once.
86
+ */
87
+ export declare function validateRegistration(request: ClientRegistrationRequest, options: RegistrationOptions, presentedToken?: string): {
88
+ redirectUris: string[];
89
+ grantTypes: GrantType[];
90
+ scopes: string[];
91
+ tokenEndpointAuthMethod: ClientAuthMethod;
92
+ name: string;
93
+ };
94
+ /** The 201 body for a client that was just created. */
95
+ export declare function registrationResponse(client: Client, issuedAt: Date, secret: string | undefined): ClientRegistrationResponse;
96
+ /**
97
+ * When a secret issued now stops working, or `undefined` for never.
98
+ *
99
+ * The TTL is the deployment's value, not the client's, so a bad one is a
100
+ * configuration mistake and says so — `VisaError`, not an OAuth error the
101
+ * caller would read as their own fault. Refused rather than rounded: a
102
+ * fractional or negative TTL means someone intended something this cannot
103
+ * carry out, and a secret quietly issued already-expired (or never expiring)
104
+ * is the worse answer either way.
105
+ */
106
+ export declare function secretExpiryFor(issuedAt: Date, ttlSeconds: number | undefined): Date | undefined;
107
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEtE,yEAAyE;AACzE,MAAM,WAAW,yBAAyB;IACzC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,0BAA0B,CAAC,EAAE,OAAO,CAA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D;;;;;GAKG;AACH,wBAAgB,oBAAoB,CACnC,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE,mBAAmB,EAC5B,cAAc,CAAC,EAAE,MAAM,GACrB;IACF,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,uBAAuB,EAAE,gBAAgB,CAAC;IAC1C,IAAI,EAAE,MAAM,CAAC;CACb,CAmDA;AAED,uDAAuD;AACvD,wBAAgB,oBAAoB,CACnC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,IAAI,EACd,MAAM,EAAE,MAAM,GAAG,SAAS,GACxB,0BAA0B,CA2B5B;AAyDD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC9B,QAAQ,EAAE,IAAI,EACd,UAAU,EAAE,MAAM,GAAG,SAAS,GAC5B,IAAI,GAAG,SAAS,CAUlB"}
@@ -0,0 +1,203 @@
1
+ /**
2
+ * Clients that register themselves (RFC 7591).
3
+ *
4
+ * An MCP client such as claude.ai or ChatGPT has nobody to fill in a form for
5
+ * it: it discovers this server, registers, and comes back with an id. Without
6
+ * this the only way in is a human pasting credentials somewhere.
7
+ *
8
+ * OFF unless the application turns it on, and that is the important part. Open
9
+ * registration means anyone who can reach the endpoint can create a client —
10
+ * the RFC says a server SHOULD allow it for interoperability, and also says
11
+ * the endpoint MAY be protected (§1.2, §3). The safe default here is the one
12
+ * the RFC permits rather than the one it encourages, because an authorization
13
+ * server that silently accepts registrations is a thing nobody asked for. Turn
14
+ * it on deliberately, and with an initial access token if the deployment is
15
+ * not meant to be open.
16
+ *
17
+ * A registered client gets exactly what this server allows: the grants,
18
+ * scopes and auth methods in the configuration, never what the request asked
19
+ * for. That is the difference between letting a client name itself and letting
20
+ * it decide what it may do.
21
+ */
22
+ import { OAuthError, VisaError } from "./errors.js";
23
+ const DEFAULT_GRANTS = [
24
+ "authorization_code",
25
+ "refresh_token",
26
+ ];
27
+ /**
28
+ * Check a registration request and say what the client may be.
29
+ *
30
+ * Returns the client to store and the plaintext secret, if one was issued —
31
+ * the caller persists the first and hands back the second, once.
32
+ */
33
+ export function validateRegistration(request, options, presentedToken) {
34
+ if (options.enabled !== true) {
35
+ throw new OAuthError("invalid_client_metadata", "This server does not accept client registrations.");
36
+ }
37
+ if (options.initialAccessToken !== undefined) {
38
+ // Constant-time is not the point here: the token is compared once per
39
+ // registration, and a registration endpoint is not a guessing oracle
40
+ // worth the machinery. Absent or wrong reads the same to the caller.
41
+ if (presentedToken !== options.initialAccessToken) {
42
+ throw new OAuthError("invalid_client_metadata", "Registration on this server needs an initial access token.");
43
+ }
44
+ }
45
+ const redirectUris = readStringList(request.redirect_uris);
46
+ const grantTypes = resolveGrants(request.grant_types, options);
47
+ // A client using the authorization code flow has somewhere to come back to,
48
+ // and this is the last moment anyone checks.
49
+ if (grantTypes.includes("authorization_code") && redirectUris.length === 0) {
50
+ throw new OAuthError("invalid_redirect_uri", "redirect_uris is required for the authorization_code grant.");
51
+ }
52
+ for (const uri of redirectUris)
53
+ assertRedirectUri(uri);
54
+ const allowed = options.scopes ?? [];
55
+ const requested = readScope(request.scope);
56
+ const outside = requested.filter((scope) => !allowed.includes(scope));
57
+ if (outside.length > 0) {
58
+ throw new OAuthError("invalid_client_metadata", `This server does not grant ${outside.join(", ")} to a self-registered client.`);
59
+ }
60
+ return {
61
+ redirectUris,
62
+ grantTypes,
63
+ // What was asked for, narrowed to what is allowed — never the allowed
64
+ // set, or every client would be registered with everything.
65
+ scopes: requested,
66
+ tokenEndpointAuthMethod: readAuthMethod(request.token_endpoint_auth_method),
67
+ name: readName(request.client_name),
68
+ };
69
+ }
70
+ /** The 201 body for a client that was just created. */
71
+ export function registrationResponse(client, issuedAt, secret) {
72
+ const seconds = Math.floor(issuedAt.getTime() / 1000);
73
+ return {
74
+ client_id: client.id,
75
+ ...(secret === undefined ? {} : { client_secret: secret }),
76
+ client_id_issued_at: seconds,
77
+ // REQUIRED when a secret was issued, and `0` is the spelling for "never"
78
+ // — not an omission, which would mean the field was not answered.
79
+ //
80
+ // Read off the client rather than recomputed from the options: the
81
+ // answer and the stored expiry are then the same value by construction,
82
+ // and cannot drift into a server that announces an expiry it does not
83
+ // enforce.
84
+ ...(secret === undefined
85
+ ? {}
86
+ : {
87
+ client_secret_expires_at: client.secretExpiresAt === undefined
88
+ ? 0
89
+ : Math.floor(client.secretExpiresAt.getTime() / 1000),
90
+ }),
91
+ redirect_uris: client.redirectUris,
92
+ grant_types: client.grantTypes,
93
+ token_endpoint_auth_method: client.tokenEndpointAuthMethod,
94
+ client_name: client.name,
95
+ ...(client.scopes.length === 0 ? {} : { scope: client.scopes.join(" ") }),
96
+ };
97
+ }
98
+ function resolveGrants(value, options) {
99
+ const allowed = options.grantTypes ?? DEFAULT_GRANTS;
100
+ const requested = readStringList(value);
101
+ if (requested.length === 0)
102
+ return [...allowed];
103
+ const grants = [];
104
+ for (const grant of requested) {
105
+ if (!isGrantType(grant) || !allowed.includes(grant)) {
106
+ throw new OAuthError("invalid_client_metadata", `This server does not allow the ${grant} grant to a self-registered client.`);
107
+ }
108
+ if (!grants.includes(grant))
109
+ grants.push(grant);
110
+ }
111
+ return grants;
112
+ }
113
+ /**
114
+ * A redirect URI a self-registered client may use.
115
+ *
116
+ * https, or http on a loopback address — a native app's callback. Anything
117
+ * else is refused: an authorization code sent over plain http to a host
118
+ * someone else controls is the code given away.
119
+ */
120
+ function assertRedirectUri(value) {
121
+ let url;
122
+ try {
123
+ url = new URL(value);
124
+ }
125
+ catch {
126
+ throw new OAuthError("invalid_redirect_uri", `${value} is not an absolute URI.`);
127
+ }
128
+ if (url.hash !== "") {
129
+ throw new OAuthError("invalid_redirect_uri", `${value} must not carry a fragment.`);
130
+ }
131
+ if (url.protocol === "https:")
132
+ return;
133
+ const loopback = url.hostname === "127.0.0.1" ||
134
+ url.hostname === "[::1]" ||
135
+ url.hostname === "localhost";
136
+ if (url.protocol === "http:" && loopback)
137
+ return;
138
+ throw new OAuthError("invalid_redirect_uri", `${value} must use https, or http on a loopback address.`);
139
+ }
140
+ /**
141
+ * When a secret issued now stops working, or `undefined` for never.
142
+ *
143
+ * The TTL is the deployment's value, not the client's, so a bad one is a
144
+ * configuration mistake and says so — `VisaError`, not an OAuth error the
145
+ * caller would read as their own fault. Refused rather than rounded: a
146
+ * fractional or negative TTL means someone intended something this cannot
147
+ * carry out, and a secret quietly issued already-expired (or never expiring)
148
+ * is the worse answer either way.
149
+ */
150
+ export function secretExpiryFor(issuedAt, ttlSeconds) {
151
+ if (ttlSeconds === undefined)
152
+ return undefined;
153
+ if (!Number.isInteger(ttlSeconds) || ttlSeconds <= 0) {
154
+ throw new VisaError("E_VISA_INVALID_SECRET_TTL", `registration.secretTtlSeconds must be a positive whole number of seconds; received ${ttlSeconds}.`, { hint: "Leave it out for a secret that never expires." });
155
+ }
156
+ return new Date(issuedAt.getTime() + ttlSeconds * 1000);
157
+ }
158
+ function readStringList(value) {
159
+ if (value === undefined || value === null)
160
+ return [];
161
+ if (!Array.isArray(value)) {
162
+ throw new OAuthError("invalid_client_metadata", "redirect_uris and grant_types must be arrays of strings.");
163
+ }
164
+ // Refused, not filtered. Dropping the entries that are not strings answers
165
+ // 201 to a request nobody wrote: `["https://app/cb", 42]` registered one
166
+ // redirect uri while the client believed it had registered two, and the
167
+ // second one silently not working is found much later, by a user.
168
+ if (value.some((entry) => typeof entry !== "string")) {
169
+ throw new OAuthError("invalid_client_metadata", "redirect_uris and grant_types must be arrays of strings.");
170
+ }
171
+ return [...value];
172
+ }
173
+ function readScope(value) {
174
+ if (value === undefined || value === null)
175
+ return [];
176
+ if (typeof value !== "string") {
177
+ throw new OAuthError("invalid_client_metadata", "scope must be a space-separated string.");
178
+ }
179
+ return value.split(/\s+/).filter((scope) => scope !== "");
180
+ }
181
+ function readAuthMethod(value) {
182
+ if (value === undefined || value === null)
183
+ return "client_secret_basic";
184
+ if (value === "client_secret_basic" ||
185
+ value === "client_secret_post" ||
186
+ value === "none") {
187
+ return value;
188
+ }
189
+ throw new OAuthError("invalid_client_metadata", `token_endpoint_auth_method ${String(value)} is not supported.`);
190
+ }
191
+ function readName(value) {
192
+ if (typeof value === "string" && value.trim() !== "")
193
+ return value.trim();
194
+ // A client with no name shows as one on a consent screen, which is worse
195
+ // than a placeholder nobody mistakes for a brand.
196
+ return "Unnamed client";
197
+ }
198
+ function isGrantType(value) {
199
+ return (value === "authorization_code" ||
200
+ value === "refresh_token" ||
201
+ value === "client_credentials");
202
+ }
203
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAgEpD,MAAM,cAAc,GAAyB;IAC5C,oBAAoB;IACpB,eAAe;CACf,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CACnC,OAAkC,EAClC,OAA4B,EAC5B,cAAuB;IAQvB,IAAI,OAAO,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;QAC9B,MAAM,IAAI,UAAU,CACnB,yBAAyB,EACzB,mDAAmD,CACnD,CAAC;IACH,CAAC;IACD,IAAI,OAAO,CAAC,kBAAkB,KAAK,SAAS,EAAE,CAAC;QAC9C,sEAAsE;QACtE,qEAAqE;QACrE,qEAAqE;QACrE,IAAI,cAAc,KAAK,OAAO,CAAC,kBAAkB,EAAE,CAAC;YACnD,MAAM,IAAI,UAAU,CACnB,yBAAyB,EACzB,4DAA4D,CAC5D,CAAC;QACH,CAAC;IACF,CAAC;IAED,MAAM,YAAY,GAAG,cAAc,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC3D,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAE/D,4EAA4E;IAC5E,6CAA6C;I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K,KAAK,oBAAoB;QAC9B,KAAK,KAAK,MAAM,EACf,CAAC;QACF,OAAO,KAAK,CAAC;IACd,CAAC;IACD,MAAM,IAAI,UAAU,CACnB,yBAAyB,EACzB,8BAA8B,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAC/D,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC/B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;IAC1E,yEAAyE;IACzE,kDAAkD;IAClD,OAAO,gBAAgB,CAAC;AACzB,CAAC;AAED,SAAS,WAAW,CAAC,KAAa;IACjC,OAAO,CACN,KAAK,KAAK,oBAAoB;QAC9B,KAAK,KAAK,eAAe;QACzB,KAAK,KAAK,oBAAoB,CAC9B,CAAC;AACH,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Which resource a token is for (RFC 8707).
3
+ *
4
+ * A token with no stated audience is a token for everything. Send it to the
5
+ * wrong server — or let a compromised one replay it — and every other resource
6
+ * that trusts the same issuer accepts it. The `resource` parameter is how a
7
+ * client says "this one is for the calendar API", and how the calendar API
8
+ * refuses one minted for somebody else.
9
+ *
10
+ * Read off the RFC rather than recalled: the value MUST be an absolute URI
11
+ * without a fragment (§2), it MAY repeat, and a resource the server does not
12
+ * accept is refused with `invalid_target` (§2) — not `invalid_request`, which
13
+ * would tell a client its request was malformed when it was merely aimed
14
+ * somewhere it may not go.
15
+ */
16
+ /**
17
+ * Normalise however the parameter arrived into a list.
18
+ *
19
+ * A form body gives one value or several under the same name, and a query
20
+ * string the same; both are `resource=` repeated, which parsers hand over
21
+ * either way.
22
+ */
23
+ export declare function readResourceParameter(value: unknown): string[];
24
+ /**
25
+ * Check each one, and refuse the request if any is unusable.
26
+ *
27
+ * `invalid_target` for every rejection here, including a malformed URI: §2
28
+ * names that code for "cannot parse the provided value(s)" as well as for a
29
+ * resource the server will not issue for.
30
+ */
31
+ export declare function validateResources(requested: readonly string[], accepted?: readonly string[]): string[];
32
+ /**
33
+ * What a token request may narrow to.
34
+ *
35
+ * A refresh or an exchange may ask for fewer resources than were authorised,
36
+ * never for more — the same rule scopes follow, and for the same reason: the
37
+ * user agreed to a set, and a later request must not widen it.
38
+ */
39
+ export declare function narrowResources(requested: readonly string[], granted: readonly string[]): string[];
40
+ /**
41
+ * Is this token for me?
42
+ *
43
+ * What a resource server asks. A token bound to nothing is accepted — that is
44
+ * every token issued before a client started sending `resource`, and refusing
45
+ * them would break each one. A token bound to SOMETHING must name this
46
+ * resource, or it was minted for another server and arriving here means it
47
+ * travelled.
48
+ */
49
+ export declare function audienceAllows(audience: readonly string[] | undefined, resource: string | undefined): boolean;
50
+ //# sourceMappingURL=resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,EAAE,CAM9D;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAChC,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,GAC1B,MAAM,EAAE,CA8BV;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC9B,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,OAAO,EAAE,SAAS,MAAM,EAAE,GACxB,MAAM,EAAE,CAmBV;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC7B,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EACvC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC1B,OAAO,CAIT"}
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Which resource a token is for (RFC 8707).
3
+ *
4
+ * A token with no stated audience is a token for everything. Send it to the
5
+ * wrong server — or let a compromised one replay it — and every other resource
6
+ * that trusts the same issuer accepts it. The `resource` parameter is how a
7
+ * client says "this one is for the calendar API", and how the calendar API
8
+ * refuses one minted for somebody else.
9
+ *
10
+ * Read off the RFC rather than recalled: the value MUST be an absolute URI
11
+ * without a fragment (§2), it MAY repeat, and a resource the server does not
12
+ * accept is refused with `invalid_target` (§2) — not `invalid_request`, which
13
+ * would tell a client its request was malformed when it was merely aimed
14
+ * somewhere it may not go.
15
+ */
16
+ import { OAuthError } from "./errors.js";
17
+ /**
18
+ * Normalise however the parameter arrived into a list.
19
+ *
20
+ * A form body gives one value or several under the same name, and a query
21
+ * string the same; both are `resource=` repeated, which parsers hand over
22
+ * either way.
23
+ */
24
+ export function readResourceParameter(value) {
25
+ if (value === undefined || value === null)
26
+ return [];
27
+ if (Array.isArray(value)) {
28
+ return value.filter((entry) => typeof entry === "string");
29
+ }
30
+ return typeof value === "string" && value !== "" ? [value] : [];
31
+ }
32
+ /**
33
+ * Check each one, and refuse the request if any is unusable.
34
+ *
35
+ * `invalid_target` for every rejection here, including a malformed URI: §2
36
+ * names that code for "cannot parse the provided value(s)" as well as for a
37
+ * resource the server will not issue for.
38
+ */
39
+ export function validateResources(requested, accepted) {
40
+ const resources = [];
41
+ for (const value of requested) {
42
+ let url;
43
+ try {
44
+ url = new URL(value);
45
+ }
46
+ catch {
47
+ throw new OAuthError("invalid_target", `resource must be an absolute URI: ${value}`);
48
+ }
49
+ if (url.hash !== "") {
50
+ throw new OAuthError("invalid_target", `resource must not carry a fragment: ${value}`);
51
+ }
52
+ // §2 SHOULD NOT include a query, and recognises that some cases need
53
+ // one — so it travels rather than being refused or stripped. Stripping
54
+ // would hand back a token for a resource nobody asked for.
55
+ if (accepted !== undefined && !accepted.includes(value)) {
56
+ throw new OAuthError("invalid_target", `this server does not issue tokens for ${value}`);
57
+ }
58
+ if (!resources.includes(value))
59
+ resources.push(value);
60
+ }
61
+ return resources;
62
+ }
63
+ /**
64
+ * What a token request may narrow to.
65
+ *
66
+ * A refresh or an exchange may ask for fewer resources than were authorised,
67
+ * never for more — the same rule scopes follow, and for the same reason: the
68
+ * user agreed to a set, and a later request must not widen it.
69
+ */
70
+ export function narrowResources(requested, granted) {
71
+ if (requested.length === 0)
72
+ return [...granted];
73
+ if (granted.length === 0) {
74
+ // Nothing was bound at authorization time, so there is nothing to narrow
75
+ // FROM. Letting the request name one here would mint a token for an
76
+ // audience the user never saw.
77
+ throw new OAuthError("invalid_target", "this grant is not bound to any resource");
78
+ }
79
+ const outside = requested.filter((value) => !granted.includes(value));
80
+ if (outside.length > 0) {
81
+ throw new OAuthError("invalid_target", `this grant does not cover ${outside.join(", ")}`);
82
+ }
83
+ return [...requested];
84
+ }
85
+ /**
86
+ * Is this token for me?
87
+ *
88
+ * What a resource server asks. A token bound to nothing is accepted — that is
89
+ * every token issued before a client started sending `resource`, and refusing
90
+ * them would break each one. A token bound to SOMETHING must name this
91
+ * resource, or it was minted for another server and arriving here means it
92
+ * travelled.
93
+ */
94
+ export function audienceAllows(audience, resource) {
95
+ if (audience === undefined || audience.length === 0)
96
+ return true;
97
+ if (resource === undefined)
98
+ return true;
99
+ return audience.includes(resource);
100
+ }
101
+ //# sourceMappingURL=resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.js","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAc;IACnD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IACrD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC;IAC5E,CA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CAAC;QAC1B,yEAAyE;QACzE,oEAAoE;QACpE,+BAA+B;QAC/B,MAAM,IAAI,UAAU,CACnB,gBAAgB,EAChB,yCAAyC,CACzC,CAAC;IACH,CAAC;IACD,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IACtE,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,UAAU,CACnB,gBAAgB,EAChB,6BAA6B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACjD,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;AACvB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAC7B,QAAuC,EACvC,QAA4B;IAE5B,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACjE,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACxC,OAAO,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACpC,CAAC"}
package/dist/store.d.ts CHANGED
@@ -38,6 +38,31 @@ export interface VisaStore {
38
38
  revokeFamily(familyId: string, at: Date): Promise<void>;
39
39
  findConsent(userId: string, clientId: string): Promise<Consent | null>;
40
40
  saveConsent(consent: Consent): Promise<void>;
41
+ /**
42
+ * Everything this user has granted, so they can be shown it.
43
+ *
44
+ * The consent is the unit a person manages: they authorised an
45
+ * application, not a token. Tokens come and go under that decision.
46
+ */
47
+ listConsents(userId: string): Promise<Consent[]>;
48
+ /**
49
+ * Every access token of this user, EXPIRED ONES INCLUDED.
50
+ *
51
+ * Included deliberately: "last used" is most interesting precisely when
52
+ * nothing is live any more, and a screen that hid them would tell a user an
53
+ * application never touched their data when it did.
54
+ */
55
+ listAccessTokens(userId: string): Promise<AccessToken[]>;
56
+ /**
57
+ * Cut one application off for one user: every token, both kinds.
58
+ *
59
+ * Not the consent — {@link deleteConsent} is separate, because forgetting
60
+ * the grant and ending the sessions are two different things and a caller
61
+ * revoking in a panic wants the second one first.
62
+ */
63
+ revokeAccessFor(userId: string, clientId: string, at: Date): Promise<void>;
64
+ /** Forget the grant, so the user is asked again next time. */
65
+ deleteConsent(userId: string, clientId: string): Promise<void>;
41
66
  /**
42
67
  * Record that an access token was just used.
43
68
  *
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACX,WAAW,EACX,iBAAiB,EACjB,MAAM,EACN,OAAO,EACP,YAAY,EACZ,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,SAAS;IACzB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAE/C,qBAAqB,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;IAC3E;;;;;;OAMG;IACH,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEvE,eAAe,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAChE,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9D,gBAAgB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CA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AAC,CAAC;IAE3E,8DAA8D;IAC9D,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/D;;;;;;OAMG;IACH,gBAAgB,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9D,0EAA0E;IAC1E,KAAK,CAAC,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC"}
@@ -33,6 +33,8 @@ export interface AtlasQuery {
33
33
  whereNull(column: string): AtlasQuery;
34
34
  orderBy(column: string, direction?: "asc" | "desc"): AtlasQuery;
35
35
  first(): Promise<Row | null>;
36
+ /** Run the select and return every row — atlas' `exec()`. */
37
+ exec(): Promise<Row[]>;
36
38
  insert(data: Row): PromiseLike<unknown>;
37
39
  /** Resolves to the number of rows affected, which is what the atomic paths read. */
38
40
  update(data: Row): PromiseLike<number | Row[]>;
@@ -92,6 +94,11 @@ export declare class AtlasStore implements VisaStore {
92
94
  * three different ways, and re-granting is not a hot path.
93
95
  */
94
96
  saveConsent(consent: Consent): Promise<void>;
97
+ listConsents(userId: string): Promise<Consent[]>;
98
+ /** Expired ones included — see the contract for why. */
99
+ listAccessTokens(userId: string): Promise<AccessToken[]>;
100
+ revokeAccessFor(userId: string, clientId: string, at: Date): Promise<void>;
101
+ deleteConsent(userId: string, clientId: string): Promise<void>;
95
102
  /** Drop what has expired and can no longer be presented. */
96
103
  prune(now: Date): Promise<void>;
97
104
  }
@@ -1 +1 @@
1
- {"version":3,"file":"atlas.d.ts","sourceRoot":"","sources":["../../src/stores/atlas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EACX,WAAW,EACX,iBAAiB,EACjB,MAAM,EAEN,OAAO,E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