@c9up/visa 0.1.0 → 0.1.2
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/dist/VisaManager.d.ts +40 -7
- package/dist/VisaManager.d.ts.map +1 -1
- package/dist/VisaManager.js +79 -3
- package/dist/VisaManager.js.map +1 -1
- package/dist/VisaProvider.d.ts.map +1 -1
- package/dist/VisaProvider.js +56 -0
- package/dist/VisaProvider.js.map +1 -1
- package/dist/authorize.d.ts +18 -0
- package/dist/authorize.d.ts.map +1 -1
- package/dist/authorize.js +6 -0
- package/dist/authorize.js.map +1 -1
- package/dist/config.d.ts +35 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/configure.d.ts.map +1 -1
- package/dist/configure.js +19 -0
- package/dist/configure.js.map +1 -1
- package/dist/errors.d.ts +9 -3
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/guard.d.ts +243 -0
- package/dist/guard.d.ts.map +1 -0
- package/dist/guard.js +293 -0
- package/dist/guard.js.map +1 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/introspect.d.ts +11 -1
- package/dist/introspect.d.ts.map +1 -1
- package/dist/introspect.js +27 -1
- package/dist/introspect.js.map +1 -1
- package/dist/protectedResource.d.ts +81 -0
- package/dist/protectedResource.d.ts.map +1 -0
- package/dist/protectedResource.js +124 -0
- package/dist/protectedResource.js.map +1 -0
- package/dist/register.d.ts +96 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +173 -0
- package/dist/register.js.map +1 -0
- package/dist/resource.d.ts +50 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/resource.js +101 -0
- package/dist/resource.js.map +1 -0
- package/dist/store.d.ts +33 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/stores/atlas.d.ts +106 -0
- package/dist/stores/atlas.d.ts.map +1 -0
- package/dist/stores/atlas.js +408 -0
- package/dist/stores/atlas.js.map +1 -0
- package/dist/stores/memory.d.ts +5 -0
- package/dist/stores/memory.d.ts.map +1 -1
- package/dist/stores/memory.js +30 -0
- package/dist/stores/memory.js.map +1 -1
- package/dist/token.d.ts +2 -0
- package/dist/token.d.ts.map +1 -1
- package/dist/token.js +21 -1
- package/dist/token.js.map +1 -1
- package/dist/types.d.ts +49 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -1
- package/src/VisaManager.ts +109 -3
- package/src/VisaProvider.ts +64 -0
- package/src/authorize.ts +27 -0
- package/src/config.ts +35 -0
- package/src/configure.ts +21 -0
- package/src/errors.ts +16 -2
- package/src/guard.ts +443 -0
- package/src/index.ts +41 -0
- package/src/introspect.ts +33 -2
- package/src/protectedResource.ts +171 -0
- package/src/register.ts +296 -0
- package/src/resource.ts +123 -0
- package/src/store.ts +38 -0
- package/src/stores/atlas.ts +514 -0
- package/src/stores/memory.ts +38 -0
- package/src/token.ts +45 -1
- package/src/types.ts +50 -0
- package/stubs/database/migrations/9000_create_visa_tables.stub +112 -0
package/dist/introspect.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { authenticateClient } from "./clients.js";
|
|
10
10
|
import { hashSecret } from "./crypto.js";
|
|
11
11
|
import { OAuthError } from "./errors.js";
|
|
12
|
+
import { audienceAllows } from "./resource.js";
|
|
12
13
|
/** `{ active: false }` — the only thing an inactive token ever reveals. */
|
|
13
14
|
const INACTIVE = { active: false };
|
|
14
15
|
export async function introspect(request, credentials, store, now = new Date(), issuer) {
|
|
@@ -39,6 +40,9 @@ export async function introspect(request, credentials, store, now = new Date(),
|
|
|
39
40
|
token_type: "Bearer",
|
|
40
41
|
exp: Math.floor(access.expiresAt.getTime() / 1000),
|
|
41
42
|
...(access.userId === undefined ? {} : { sub: access.userId }),
|
|
43
|
+
// RFC 8707 §3 names introspection as where a resource server learns
|
|
44
|
+
// what a token was minted for.
|
|
45
|
+
...(access.audience === undefined ? {} : { aud: access.audience }),
|
|
42
46
|
};
|
|
43
47
|
}
|
|
44
48
|
const refresh = await store.findRefreshToken(hash);
|
|
@@ -92,16 +96,38 @@ export async function revoke(request, credentials, store, now = new Date()) {
|
|
|
92
96
|
* What a resource server calls on every request — so it reads the store
|
|
93
97
|
* directly instead of going through introspection's client authentication.
|
|
94
98
|
*/
|
|
95
|
-
export async function verifyAccessToken(presented,
|
|
99
|
+
export async function verifyAccessToken(presented,
|
|
100
|
+
// Only the one read: a resource server that keeps nothing but tokens should
|
|
101
|
+
// not have to implement eleven methods it never calls.
|
|
102
|
+
store, now = new Date(),
|
|
103
|
+
/**
|
|
104
|
+
* This resource's identifier (RFC 8707).
|
|
105
|
+
*
|
|
106
|
+
* Given, a token minted for a different resource is refused here rather
|
|
107
|
+
* than honoured — which is the entire point of binding one.
|
|
108
|
+
*/
|
|
109
|
+
resource) {
|
|
96
110
|
const token = await store.findAccessToken(hashSecret(presented));
|
|
97
111
|
if (token === null)
|
|
98
112
|
return null;
|
|
99
113
|
if (token.revokedAt !== undefined || token.expiresAt <= now)
|
|
100
114
|
return null;
|
|
115
|
+
// RFC 8707: a token bound to a resource is refused anywhere else. Unbound
|
|
116
|
+
// tokens are accepted — that is every token issued before a client started
|
|
117
|
+
// asking, and refusing them would break each one.
|
|
118
|
+
if (!audienceAllows(token.audience, resource))
|
|
119
|
+
return null;
|
|
101
120
|
return {
|
|
102
121
|
clientId: token.clientId,
|
|
103
122
|
...(token.userId === undefined ? {} : { userId: token.userId }),
|
|
104
123
|
scopes: token.scopes,
|
|
124
|
+
// Carried out so a caller can report the expiry it just checked, rather
|
|
125
|
+
// than reading the store a second time to say the same thing.
|
|
126
|
+
expiresAt: token.expiresAt,
|
|
127
|
+
// The PREVIOUS use, before this one is recorded — which is what the
|
|
128
|
+
// upstream guard shows on `currentAccessToken.lastUsedAt`.
|
|
129
|
+
...(token.lastUsedAt === undefined ? {} : { lastUsedAt: token.lastUsedAt }),
|
|
130
|
+
...(token.audience === undefined ? {} : { audience: token.audience }),
|
|
105
131
|
};
|
|
106
132
|
}
|
|
107
133
|
function asString(value) {
|
package/dist/introspect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"introspect.js","sourceRoot":"","sources":["../src/introspect.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,kBAAkB,EAA0B,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"introspect.js","sourceRoot":"","sources":["../src/introspect.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,kBAAkB,EAA0B,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAI/C,2EAA2E;AAC3E,MAAM,QAAQ,GAA0B,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AAE1D,MAAM,CAAC,KAAK,UAAU,UAAU,CAC/B,OAAgC,EAChC,WAA8B,EAC9B,KAAgB,EAChB,MAAY,IAAI,IAAI,EAAE,EACtB,MAAe;IAEf,0EAA0E;IAC1E,2DAA2D;IAC3D,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE,CAC3D,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,CACpB,CAAC;IACF,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC1C,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC7B,MAAM,IAAI,UAAU,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,CAAC;IAC/D,CAAC;IAED,MAAM,IAA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Q,EAAE,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3D,OAAO;QACN,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;QAC/D,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,wEAAwE;QACxE,8DAA8D;QAC9D,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,oEAAoE;QACpE,2DAA2D;QAC3D,GAAG,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC;QAC3E,GAAG,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;KACrE,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a protected resource says when it refuses, so a client can find its way
|
|
3
|
+
* in on its own (RFC 9728).
|
|
4
|
+
*
|
|
5
|
+
* Without this, a 401 is a dead end: the caller knows it needs a token and has
|
|
6
|
+
* no way to learn where tokens come from. With it, the refusal names a
|
|
7
|
+
* metadata document, the document names the authorization server, and an MCP
|
|
8
|
+
* client walks from one to the other unattended. That is the whole point — it
|
|
9
|
+
* is the difference between an agent that can connect and one that needs
|
|
10
|
+
* somebody to paste a URL into a config file.
|
|
11
|
+
*
|
|
12
|
+
* Nothing here is visa-specific: a resource server is free to be a different
|
|
13
|
+
* process from the authorization server, which is why the metadata takes the
|
|
14
|
+
* issuer as a value rather than reading one.
|
|
15
|
+
*/
|
|
16
|
+
/** The metadata document, §3.2. Only `resource` is required. */
|
|
17
|
+
export interface ProtectedResourceMetadata {
|
|
18
|
+
resource: string;
|
|
19
|
+
authorization_servers?: string[];
|
|
20
|
+
scopes_supported?: string[];
|
|
21
|
+
bearer_methods_supported?: string[];
|
|
22
|
+
resource_name?: string;
|
|
23
|
+
resource_documentation?: string;
|
|
24
|
+
jwks_uri?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ProtectedResourceOptions {
|
|
27
|
+
/** This resource's identifier — an absolute URI, no fragment. */
|
|
28
|
+
resource: string;
|
|
29
|
+
/** The authorization servers that issue tokens for it. */
|
|
30
|
+
authorizationServers?: readonly string[];
|
|
31
|
+
/** What a client may ask for here. RECOMMENDED by §3.2. */
|
|
32
|
+
scopesSupported?: readonly string[];
|
|
33
|
+
/** Where the token may travel. Defaults to the header, which is all visa reads. */
|
|
34
|
+
bearerMethodsSupported?: readonly string[];
|
|
35
|
+
resourceName?: string;
|
|
36
|
+
resourceDocumentation?: string;
|
|
37
|
+
}
|
|
38
|
+
/** The path the document is served at, §3. */
|
|
39
|
+
export declare const PROTECTED_RESOURCE_PATH = "/.well-known/oauth-protected-resource";
|
|
40
|
+
/**
|
|
41
|
+
* The well-known URL for a resource identifier.
|
|
42
|
+
*
|
|
43
|
+
* §3 inserts the well-known segment BETWEEN the host and the path, so a
|
|
44
|
+
* resource at `https://api.example/mcp` publishes at
|
|
45
|
+
* `https://api.example/.well-known/oauth-protected-resource/mcp` — not at the
|
|
46
|
+
* resource's own path with the segment appended, which is the easy mistake and
|
|
47
|
+
* the one that leaves a client fetching 404s.
|
|
48
|
+
*/
|
|
49
|
+
export declare function protectedResourceMetadataUrl(resource: string): string;
|
|
50
|
+
/** Build the document a client fetches after a 401. */
|
|
51
|
+
export declare function protectedResourceMetadata(options: ProtectedResourceOptions): ProtectedResourceMetadata;
|
|
52
|
+
export interface ChallengeOptions {
|
|
53
|
+
/** Where the metadata lives. Derived from the resource when omitted. */
|
|
54
|
+
resourceMetadata?: string;
|
|
55
|
+
/** This resource's identifier, used to derive the metadata URL. */
|
|
56
|
+
resource?: string;
|
|
57
|
+
/** `invalid_token`, `insufficient_scope` — RFC 6750 §3.1. */
|
|
58
|
+
error?: string;
|
|
59
|
+
errorDescription?: string;
|
|
60
|
+
/** What the caller would have needed, with `insufficient_scope`. */
|
|
61
|
+
scope?: readonly string[];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The `WWW-Authenticate` value for a 401, §5.1.
|
|
65
|
+
*
|
|
66
|
+
* Quoted values are checked rather than escaped: the header is a
|
|
67
|
+
* comma-separated list of quoted strings, and a value carrying a quote or a
|
|
68
|
+
* control character cannot be represented in it at all. A caller that built
|
|
69
|
+
* one from user input should hear about it here, not ship a header a client
|
|
70
|
+
* parses into something else.
|
|
71
|
+
*/
|
|
72
|
+
export declare function wwwAuthenticate(options?: ChallengeOptions): string;
|
|
73
|
+
/**
|
|
74
|
+
* A resource identifier is an absolute URI with no fragment (RFC 8707 §2).
|
|
75
|
+
*
|
|
76
|
+
* Checked where the metadata is built, because a resource that publishes an
|
|
77
|
+
* identifier its own tokens will not match is broken in a way only visible at
|
|
78
|
+
* the moment a client is refused.
|
|
79
|
+
*/
|
|
80
|
+
export declare function assertResourceIdentifier(resource: string): void;
|
|
81
|
+
//# sourceMappingURL=protectedResource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protectedResource.d.ts","sourceRoot":"","sources":["../src/protectedResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,gEAAgE;AAChE,MAAM,WAAW,yBAAyB;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;IACjC,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IA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
|
1
|
+
/**
|
|
2
|
+
* What a protected resource says when it refuses, so a client can find its way
|
|
3
|
+
* in on its own (RFC 9728).
|
|
4
|
+
*
|
|
5
|
+
* Without this, a 401 is a dead end: the caller knows it needs a token and has
|
|
6
|
+
* no way to learn where tokens come from. With it, the refusal names a
|
|
7
|
+
* metadata document, the document names the authorization server, and an MCP
|
|
8
|
+
* client walks from one to the other unattended. That is the whole point — it
|
|
9
|
+
* is the difference between an agent that can connect and one that needs
|
|
10
|
+
* somebody to paste a URL into a config file.
|
|
11
|
+
*
|
|
12
|
+
* Nothing here is visa-specific: a resource server is free to be a different
|
|
13
|
+
* process from the authorization server, which is why the metadata takes the
|
|
14
|
+
* issuer as a value rather than reading one.
|
|
15
|
+
*/
|
|
16
|
+
/** The path the document is served at, §3. */
|
|
17
|
+
export const PROTECTED_RESOURCE_PATH = "/.well-known/oauth-protected-resource";
|
|
18
|
+
/**
|
|
19
|
+
* The well-known URL for a resource identifier.
|
|
20
|
+
*
|
|
21
|
+
* §3 inserts the well-known segment BETWEEN the host and the path, so a
|
|
22
|
+
* resource at `https://api.example/mcp` publishes at
|
|
23
|
+
* `https://api.example/.well-known/oauth-protected-resource/mcp` — not at the
|
|
24
|
+
* resource's own path with the segment appended, which is the easy mistake and
|
|
25
|
+
* the one that leaves a client fetching 404s.
|
|
26
|
+
*/
|
|
27
|
+
export function protectedResourceMetadataUrl(resource) {
|
|
28
|
+
const url = new URL(resource);
|
|
29
|
+
const path = url.pathname === "/" ? "" : url.pathname.replace(/\/$/, "");
|
|
30
|
+
url.pathname = `${PROTECTED_RESOURCE_PATH}${path}`;
|
|
31
|
+
url.search = "";
|
|
32
|
+
url.hash = "";
|
|
33
|
+
return url.href;
|
|
34
|
+
}
|
|
35
|
+
/** Build the document a client fetches after a 401. */
|
|
36
|
+
export function protectedResourceMetadata(options) {
|
|
37
|
+
assertResourceIdentifier(options.resource);
|
|
38
|
+
return {
|
|
39
|
+
resource: options.resource,
|
|
40
|
+
...(options.authorizationServers === undefined
|
|
41
|
+
? {}
|
|
42
|
+
: { authorization_servers: [...options.authorizationServers] }),
|
|
43
|
+
...(options.scopesSupported === undefined
|
|
44
|
+
? {}
|
|
45
|
+
: { scopes_supported: [...options.scopesSupported] }),
|
|
46
|
+
bearer_methods_supported: [
|
|
47
|
+
...(options.bearerMethodsSupported ?? ["header"]),
|
|
48
|
+
],
|
|
49
|
+
...(options.resourceName === undefined
|
|
50
|
+
? {}
|
|
51
|
+
: { resource_name: options.resourceName }),
|
|
52
|
+
...(options.resourceDocumentation === undefined
|
|
53
|
+
? {}
|
|
54
|
+
: { resource_documentation: options.resourceDocumentation }),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The `WWW-Authenticate` value for a 401, §5.1.
|
|
59
|
+
*
|
|
60
|
+
* Quoted values are checked rather than escaped: the header is a
|
|
61
|
+
* comma-separated list of quoted strings, and a value carrying a quote or a
|
|
62
|
+
* control character cannot be represented in it at all. A caller that built
|
|
63
|
+
* one from user input should hear about it here, not ship a header a client
|
|
64
|
+
* parses into something else.
|
|
65
|
+
*/
|
|
66
|
+
export function wwwAuthenticate(options = {}) {
|
|
67
|
+
const metadataUrl = options.resourceMetadata ??
|
|
68
|
+
(options.resource === undefined
|
|
69
|
+
? undefined
|
|
70
|
+
: protectedResourceMetadataUrl(options.resource));
|
|
71
|
+
const parameters = [];
|
|
72
|
+
if (options.error !== undefined)
|
|
73
|
+
parameters.push(["error", options.error]);
|
|
74
|
+
if (options.errorDescription !== undefined) {
|
|
75
|
+
parameters.push(["error_description", options.errorDescription]);
|
|
76
|
+
}
|
|
77
|
+
if (options.scope !== undefined && options.scope.length > 0) {
|
|
78
|
+
parameters.push(["scope", options.scope.join(" ")]);
|
|
79
|
+
}
|
|
80
|
+
if (metadataUrl !== undefined) {
|
|
81
|
+
parameters.push(["resource_metadata", metadataUrl]);
|
|
82
|
+
}
|
|
83
|
+
if (parameters.length === 0)
|
|
84
|
+
return "Bearer";
|
|
85
|
+
const rendered = parameters
|
|
86
|
+
.map(([key, value]) => `${key}="${quotable(value, key)}"`)
|
|
87
|
+
.join(", ");
|
|
88
|
+
return `Bearer ${rendered}`;
|
|
89
|
+
}
|
|
90
|
+
function quotable(value, parameter) {
|
|
91
|
+
// A quoted-string holds neither a bare quote nor a control character, and
|
|
92
|
+
// neither can be escaped into one usefully — a client would read the header
|
|
93
|
+
// as a different set of parameters.
|
|
94
|
+
for (const character of value) {
|
|
95
|
+
const code = character.codePointAt(0) ?? 0;
|
|
96
|
+
if (character === '"' ||
|
|
97
|
+
character === "\\" ||
|
|
98
|
+
code < 0x20 ||
|
|
99
|
+
code === 0x7f) {
|
|
100
|
+
throw new Error(`[visa] ${parameter} cannot go in a WWW-Authenticate header: it holds a quote, a backslash or a control character`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* A resource identifier is an absolute URI with no fragment (RFC 8707 §2).
|
|
107
|
+
*
|
|
108
|
+
* Checked where the metadata is built, because a resource that publishes an
|
|
109
|
+
* identifier its own tokens will not match is broken in a way only visible at
|
|
110
|
+
* the moment a client is refused.
|
|
111
|
+
*/
|
|
112
|
+
export function assertResourceIdentifier(resource) {
|
|
113
|
+
let url;
|
|
114
|
+
try {
|
|
115
|
+
url = new URL(resource);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
throw new Error(`[visa] resource must be an absolute URI: ${resource}`);
|
|
119
|
+
}
|
|
120
|
+
if (url.hash !== "") {
|
|
121
|
+
throw new Error(`[visa] resource must not carry a fragment: ${resource}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=protectedResource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protectedResource.js","sourceRoot":"","sources":["../src/protectedResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA0BH,8CAA8C;AAC9C,MAA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,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC;SACzD,IAAI,CAAC,IAAI,CAAC,CAAC;IACb,OAAO,UAAU,QAAQ,EAAE,CAAC;AAC7B,CAAC;AAED,SAAS,QAAQ,CAAC,KAAa,EAAE,SAAiB;IACjD,0EAA0E;IAC1E,4EAA4E;IAC5E,oCAAoC;IACpC,KAAK,MAAM,SAAS,IAAI,KAAK,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC3C,IACC,SAAS,KAAK,GAAG;YACjB,SAAS,KAAK,IAAI;YAClB,IAAI,GAAG,IAAI;YACX,IAAI,KAAK,IAAI,EACZ,CAAC;YACF,MAAM,IAAI,KAAK,CACd,UAAU,SAAS,+FAA+F,CAClH,CAAC;QACH,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CAAC,QAAgB;IACxD,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACJ,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;IAAC,MAAM,CAAC;QACR,MAAM,IAAI,KAAK,CAAC,4CAA4C,QAAQ,EAAE,CAAC,CAAC;IACzE,CAAC;IACD,IAAI,GAAG,CAAC,IAAI,KAAK,EAAE,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,8CAA8C,QAAQ,EAAE,CAAC,CAAC;IAC3E,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
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, options: RegistrationOptions): ClientRegistrationResponse;
|
|
96
|
+
//# 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,CAAC;IACrC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;;;;OAOG;IACH,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED,6BAA6B;AAC7B,MAAM,WAAW,0BAA0B;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,+BAA+B;IAC/B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,uEAAuE;IACvE,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,WAAW,EAAE,SAAS,EAAE,CAAC;IACzB,0BAA0B,EAAE,gBAAgB,CAAC;IAC7C,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IACnC,2CAA2C;IAC3C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,wEAAwE;IACxE,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,oFAAoF;IACpF,UAAU,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IAClC,kFAAkF;IAClF,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AAOD;;;;;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,EAC1B,OAAO,EAAE,mBAAmB,GAC1B,0BAA0B,CAsB5B"}
|
package/dist/register.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
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 } 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, options) {
|
|
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
|
+
...(secret === undefined
|
|
80
|
+
? {}
|
|
81
|
+
: {
|
|
82
|
+
client_secret_expires_at: options.secretTtlSeconds === undefined
|
|
83
|
+
? 0
|
|
84
|
+
: seconds + options.secretTtlSeconds,
|
|
85
|
+
}),
|
|
86
|
+
redirect_uris: client.redirectUris,
|
|
87
|
+
grant_types: client.grantTypes,
|
|
88
|
+
token_endpoint_auth_method: client.tokenEndpointAuthMethod,
|
|
89
|
+
client_name: client.name,
|
|
90
|
+
...(client.scopes.length === 0 ? {} : { scope: client.scopes.join(" ") }),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function resolveGrants(value, options) {
|
|
94
|
+
const allowed = options.grantTypes ?? DEFAULT_GRANTS;
|
|
95
|
+
const requested = readStringList(value);
|
|
96
|
+
if (requested.length === 0)
|
|
97
|
+
return [...allowed];
|
|
98
|
+
const grants = [];
|
|
99
|
+
for (const grant of requested) {
|
|
100
|
+
if (!isGrantType(grant) || !allowed.includes(grant)) {
|
|
101
|
+
throw new OAuthError("invalid_client_metadata", `This server does not allow the ${grant} grant to a self-registered client.`);
|
|
102
|
+
}
|
|
103
|
+
if (!grants.includes(grant))
|
|
104
|
+
grants.push(grant);
|
|
105
|
+
}
|
|
106
|
+
return grants;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A redirect URI a self-registered client may use.
|
|
110
|
+
*
|
|
111
|
+
* https, or http on a loopback address — a native app's callback. Anything
|
|
112
|
+
* else is refused: an authorization code sent over plain http to a host
|
|
113
|
+
* someone else controls is the code given away.
|
|
114
|
+
*/
|
|
115
|
+
function assertRedirectUri(value) {
|
|
116
|
+
let url;
|
|
117
|
+
try {
|
|
118
|
+
url = new URL(value);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
throw new OAuthError("invalid_redirect_uri", `${value} is not an absolute URI.`);
|
|
122
|
+
}
|
|
123
|
+
if (url.hash !== "") {
|
|
124
|
+
throw new OAuthError("invalid_redirect_uri", `${value} must not carry a fragment.`);
|
|
125
|
+
}
|
|
126
|
+
if (url.protocol === "https:")
|
|
127
|
+
return;
|
|
128
|
+
const loopback = url.hostname === "127.0.0.1" ||
|
|
129
|
+
url.hostname === "[::1]" ||
|
|
130
|
+
url.hostname === "localhost";
|
|
131
|
+
if (url.protocol === "http:" && loopback)
|
|
132
|
+
return;
|
|
133
|
+
throw new OAuthError("invalid_redirect_uri", `${value} must use https, or http on a loopback address.`);
|
|
134
|
+
}
|
|
135
|
+
function readStringList(value) {
|
|
136
|
+
if (value === undefined || value === null)
|
|
137
|
+
return [];
|
|
138
|
+
if (!Array.isArray(value)) {
|
|
139
|
+
throw new OAuthError("invalid_client_metadata", "redirect_uris and grant_types must be arrays of strings.");
|
|
140
|
+
}
|
|
141
|
+
return value.filter((entry) => typeof entry === "string");
|
|
142
|
+
}
|
|
143
|
+
function readScope(value) {
|
|
144
|
+
if (value === undefined || value === null)
|
|
145
|
+
return [];
|
|
146
|
+
if (typeof value !== "string") {
|
|
147
|
+
throw new OAuthError("invalid_client_metadata", "scope must be a space-separated string.");
|
|
148
|
+
}
|
|
149
|
+
return value.split(/\s+/).filter((scope) => scope !== "");
|
|
150
|
+
}
|
|
151
|
+
function readAuthMethod(value) {
|
|
152
|
+
if (value === undefined || value === null)
|
|
153
|
+
return "client_secret_basic";
|
|
154
|
+
if (value === "client_secret_basic" ||
|
|
155
|
+
value === "client_secret_post" ||
|
|
156
|
+
value === "none") {
|
|
157
|
+
return value;
|
|
158
|
+
}
|
|
159
|
+
throw new OAuthError("invalid_client_metadata", `token_endpoint_auth_method ${String(value)} is not supported.`);
|
|
160
|
+
}
|
|
161
|
+
function readName(value) {
|
|
162
|
+
if (typeof value === "string" && value.trim() !== "")
|
|
163
|
+
return value.trim();
|
|
164
|
+
// A client with no name shows as one on a consent screen, which is worse
|
|
165
|
+
// than a placeholder nobody mistakes for a brand.
|
|
166
|
+
return "Unnamed client";
|
|
167
|
+
}
|
|
168
|
+
function isGrantType(value) {
|
|
169
|
+
return (value === "authorization_code" ||
|
|
170
|
+
value === "refresh_token" ||
|
|
171
|
+
value === "client_credentials");
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=register.js.map
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3D,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IACrC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,qBAAqB,CAAC;IACxE,IACC,KAAK,KAAK,qBAAqB;QAC/B,KAAK,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"}
|