mcp-trellis 1.0.0 → 2.2.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/README.md +65 -93
- package/dist/adapters/node-request.d.ts +53 -0
- package/dist/adapters/node-request.d.ts.map +1 -0
- package/dist/adapters/node-request.js +165 -0
- package/dist/adapters/node-request.js.map +1 -0
- package/dist/adapters/node.d.ts +13 -30
- package/dist/adapters/node.d.ts.map +1 -1
- package/dist/adapters/node.js +55 -101
- package/dist/adapters/node.js.map +1 -1
- package/dist/advanced.d.ts +18 -0
- package/dist/advanced.d.ts.map +1 -0
- package/dist/advanced.js +18 -0
- package/dist/advanced.js.map +1 -0
- package/dist/app-options.d.ts +132 -0
- package/dist/app-options.d.ts.map +1 -0
- package/dist/app-options.js +2 -0
- package/dist/app-options.js.map +1 -0
- package/dist/app.d.ts +2 -89
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +143 -63
- package/dist/app.js.map +1 -1
- package/dist/audit.d.ts +5 -5
- package/dist/audit.d.ts.map +1 -1
- package/dist/audit.js +19 -8
- package/dist/audit.js.map +1 -1
- package/dist/auth/bearer.d.ts +4 -1
- package/dist/auth/bearer.d.ts.map +1 -1
- package/dist/auth/bearer.js +19 -4
- package/dist/auth/bearer.js.map +1 -1
- package/dist/auth/signed-token.d.ts +26 -0
- package/dist/auth/signed-token.d.ts.map +1 -0
- package/dist/auth/signed-token.js +96 -0
- package/dist/auth/signed-token.js.map +1 -0
- package/dist/clients.js +1 -1
- package/dist/clients.js.map +1 -1
- package/dist/deprecated.d.ts +42 -0
- package/dist/deprecated.d.ts.map +1 -0
- package/dist/deprecated.js +35 -0
- package/dist/deprecated.js.map +1 -0
- package/dist/{body.d.ts → http/body.d.ts} +27 -6
- package/dist/http/body.d.ts.map +1 -0
- package/dist/{body.js → http/body.js} +33 -13
- package/dist/http/body.js.map +1 -0
- package/dist/http/http.d.ts +42 -0
- package/dist/http/http.d.ts.map +1 -0
- package/dist/http/http.js +100 -0
- package/dist/http/http.js.map +1 -0
- package/dist/http/origins.d.ts +37 -0
- package/dist/http/origins.d.ts.map +1 -0
- package/dist/http/origins.js +87 -0
- package/dist/http/origins.js.map +1 -0
- package/dist/{dispatch.d.ts → mcp/dispatch.d.ts} +1 -1
- package/dist/mcp/dispatch.d.ts.map +1 -0
- package/dist/mcp/dispatch.js +99 -0
- package/dist/mcp/dispatch.js.map +1 -0
- package/dist/{jsonrpc.d.ts → mcp/jsonrpc.d.ts} +9 -0
- package/dist/mcp/jsonrpc.d.ts.map +1 -0
- package/dist/mcp/jsonrpc.js +88 -0
- package/dist/mcp/jsonrpc.js.map +1 -0
- package/dist/{methods.d.ts → mcp/methods.d.ts} +60 -11
- package/dist/mcp/methods.d.ts.map +1 -0
- package/dist/mcp/methods.js +84 -0
- package/dist/mcp/methods.js.map +1 -0
- package/dist/{protocol.d.ts → mcp/protocol.d.ts} +1 -3
- package/dist/mcp/protocol.d.ts.map +1 -0
- package/dist/{protocol.js → mcp/protocol.js} +1 -3
- package/dist/mcp/protocol.js.map +1 -0
- package/dist/mcp/registry.d.ts +58 -0
- package/dist/mcp/registry.d.ts.map +1 -0
- package/dist/mcp/registry.js +81 -0
- package/dist/mcp/registry.js.map +1 -0
- package/dist/mcp/rpc-handlers.d.ts +11 -0
- package/dist/mcp/rpc-handlers.d.ts.map +1 -0
- package/dist/mcp/rpc-handlers.js +133 -0
- package/dist/mcp/rpc-handlers.js.map +1 -0
- package/dist/{tools.d.ts → mcp/tools.d.ts} +20 -1
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +166 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/{validate.d.ts → mcp/validate.d.ts} +18 -21
- package/dist/mcp/validate.d.ts.map +1 -0
- package/dist/{validate.js → mcp/validate.js} +59 -41
- package/dist/mcp/validate.js.map +1 -0
- package/dist/oauth/audit.d.ts +20 -0
- package/dist/oauth/audit.d.ts.map +1 -0
- package/dist/oauth/audit.js +29 -0
- package/dist/oauth/audit.js.map +1 -0
- package/dist/oauth/cimd/cimd-parse.d.ts +4 -0
- package/dist/oauth/cimd/cimd-parse.d.ts.map +1 -0
- package/dist/oauth/cimd/cimd-parse.js +70 -0
- package/dist/oauth/cimd/cimd-parse.js.map +1 -0
- package/dist/oauth/cimd/cimd-ssrf.d.ts +8 -0
- package/dist/oauth/cimd/cimd-ssrf.d.ts.map +1 -0
- package/dist/oauth/cimd/cimd-ssrf.js +193 -0
- package/dist/oauth/cimd/cimd-ssrf.js.map +1 -0
- package/dist/oauth/cimd/cimd.d.ts +36 -0
- package/dist/oauth/cimd/cimd.d.ts.map +1 -0
- package/dist/oauth/cimd/cimd.js +132 -0
- package/dist/oauth/cimd/cimd.js.map +1 -0
- package/dist/oauth/cimd/types.d.ts +12 -0
- package/dist/oauth/cimd/types.d.ts.map +1 -0
- package/dist/oauth/cimd/types.js +3 -0
- package/dist/oauth/cimd/types.js.map +1 -0
- package/dist/oauth/config.d.ts +51 -0
- package/dist/oauth/config.d.ts.map +1 -0
- package/dist/oauth/config.js +108 -0
- package/dist/oauth/config.js.map +1 -0
- package/dist/oauth/constants.d.ts +11 -0
- package/dist/oauth/constants.d.ts.map +1 -1
- package/dist/oauth/constants.js +11 -0
- package/dist/oauth/constants.js.map +1 -1
- package/dist/oauth/{base64url.d.ts → crypto/base64url.d.ts} +0 -1
- package/dist/oauth/crypto/base64url.d.ts.map +1 -0
- package/dist/oauth/{base64url.js → crypto/base64url.js} +0 -1
- package/dist/oauth/crypto/base64url.js.map +1 -0
- package/dist/oauth/crypto/clientauth.d.ts +13 -0
- package/dist/oauth/crypto/clientauth.d.ts.map +1 -0
- package/dist/oauth/crypto/clientauth.js +195 -0
- package/dist/oauth/crypto/clientauth.js.map +1 -0
- package/dist/oauth/crypto/codes.d.ts +65 -0
- package/dist/oauth/crypto/codes.d.ts.map +1 -0
- package/dist/oauth/crypto/codes.js +121 -0
- package/dist/oauth/crypto/codes.js.map +1 -0
- package/dist/oauth/crypto/hkdf.d.ts +13 -0
- package/dist/oauth/crypto/hkdf.d.ts.map +1 -0
- package/dist/oauth/crypto/hkdf.js +30 -0
- package/dist/oauth/crypto/hkdf.js.map +1 -0
- package/dist/oauth/crypto/keycache.d.ts +19 -0
- package/dist/oauth/crypto/keycache.d.ts.map +1 -0
- package/dist/oauth/crypto/keycache.js +44 -0
- package/dist/oauth/crypto/keycache.js.map +1 -0
- package/dist/oauth/crypto/pkce.d.ts.map +1 -0
- package/dist/oauth/{pkce.js → crypto/pkce.js} +1 -1
- package/dist/oauth/crypto/pkce.js.map +1 -0
- package/dist/oauth/{sealed.d.ts → crypto/sealed.d.ts} +12 -3
- package/dist/oauth/crypto/sealed.d.ts.map +1 -0
- package/dist/oauth/{sealed.js → crypto/sealed.js} +22 -14
- package/dist/oauth/crypto/sealed.js.map +1 -0
- package/dist/oauth/{secrethash.d.ts → crypto/secrethash.d.ts} +14 -0
- package/dist/oauth/crypto/secrethash.d.ts.map +1 -0
- package/dist/oauth/{secrethash.js → crypto/secrethash.js} +27 -11
- package/dist/oauth/crypto/secrethash.js.map +1 -0
- package/dist/oauth/deprecated.d.ts +52 -0
- package/dist/oauth/deprecated.d.ts.map +1 -0
- package/dist/oauth/deprecated.js +49 -0
- package/dist/oauth/deprecated.js.map +1 -0
- package/dist/oauth/endpoints/authorize.d.ts +3 -0
- package/dist/oauth/endpoints/authorize.d.ts.map +1 -0
- package/dist/oauth/endpoints/authorize.js +209 -0
- package/dist/oauth/endpoints/authorize.js.map +1 -0
- package/dist/oauth/endpoints/callback.d.ts +20 -0
- package/dist/oauth/endpoints/callback.d.ts.map +1 -0
- package/dist/oauth/endpoints/callback.js +31 -0
- package/dist/oauth/endpoints/callback.js.map +1 -0
- package/dist/oauth/endpoints/consent-page.d.ts +5 -0
- package/dist/oauth/endpoints/consent-page.d.ts.map +1 -0
- package/dist/oauth/endpoints/consent-page.js +63 -0
- package/dist/oauth/endpoints/consent-page.js.map +1 -0
- package/dist/oauth/endpoints/consent.d.ts +29 -0
- package/dist/oauth/endpoints/consent.d.ts.map +1 -0
- package/dist/oauth/endpoints/consent.js +98 -0
- package/dist/oauth/endpoints/consent.js.map +1 -0
- package/dist/oauth/{metadata.d.ts → endpoints/metadata.d.ts} +8 -2
- package/dist/oauth/endpoints/metadata.d.ts.map +1 -0
- package/dist/oauth/{metadata.js → endpoints/metadata.js} +10 -4
- package/dist/oauth/endpoints/metadata.js.map +1 -0
- package/dist/oauth/endpoints/register.d.ts +10 -0
- package/dist/oauth/endpoints/register.d.ts.map +1 -0
- package/dist/oauth/endpoints/register.js +96 -0
- package/dist/oauth/endpoints/register.js.map +1 -0
- package/dist/oauth/{revoke.d.ts → endpoints/revoke.d.ts} +1 -1
- package/dist/oauth/endpoints/revoke.d.ts.map +1 -0
- package/dist/oauth/{revoke.js → endpoints/revoke.js} +8 -18
- package/dist/oauth/endpoints/revoke.js.map +1 -0
- package/dist/oauth/endpoints/token.d.ts +3 -0
- package/dist/oauth/endpoints/token.d.ts.map +1 -0
- package/dist/oauth/{token.js → endpoints/token.js} +32 -25
- package/dist/oauth/endpoints/token.js.map +1 -0
- package/dist/oauth/{wellknown.d.ts → endpoints/wellknown.d.ts} +1 -1
- package/dist/oauth/endpoints/wellknown.d.ts.map +1 -0
- package/dist/oauth/{wellknown.js → endpoints/wellknown.js} +7 -9
- package/dist/oauth/endpoints/wellknown.js.map +1 -0
- package/dist/oauth/policy/redirect.d.ts.map +1 -0
- package/dist/oauth/policy/redirect.js.map +1 -0
- package/dist/oauth/policy/reqbody.d.ts +18 -0
- package/dist/oauth/policy/reqbody.d.ts.map +1 -0
- package/dist/oauth/policy/reqbody.js +68 -0
- package/dist/oauth/policy/reqbody.js.map +1 -0
- package/dist/oauth/{resource.d.ts → policy/resource.d.ts} +1 -1
- package/dist/oauth/policy/resource.d.ts.map +1 -0
- package/dist/oauth/{resource.js → policy/resource.js} +2 -2
- package/dist/oauth/policy/resource.js.map +1 -0
- package/dist/oauth/{scope.d.ts → policy/scope.d.ts} +2 -2
- package/dist/oauth/policy/scope.d.ts.map +1 -0
- package/dist/oauth/{scope.js → policy/scope.js} +3 -3
- package/dist/oauth/policy/scope.js.map +1 -0
- package/dist/oauth/router.d.ts +10 -13
- package/dist/oauth/router.d.ts.map +1 -1
- package/dist/oauth/router.js +93 -115
- package/dist/oauth/router.js.map +1 -1
- package/dist/oauth/types.d.ts +99 -45
- package/dist/oauth/types.d.ts.map +1 -1
- package/dist/oauth/types.js +1 -90
- package/dist/oauth/types.js.map +1 -1
- package/dist/server.d.ts +13 -12
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +10 -8
- package/dist/server.js.map +1 -1
- package/dist/util/defined.d.ts +11 -0
- package/dist/util/defined.d.ts.map +1 -0
- package/dist/util/defined.js +15 -0
- package/dist/util/defined.js.map +1 -0
- package/dist/util/json.d.ts +3 -0
- package/dist/util/json.d.ts.map +1 -0
- package/dist/util/json.js +3 -0
- package/dist/util/json.js.map +1 -0
- package/docs/ROADMAP.md +37 -47
- package/docs/compatibility.md +86 -0
- package/docs/diagrams/demo-tool-result.png +0 -0
- package/docs/diagrams/mcp-trellis-architecture.html +305 -0
- package/docs/guide.md +46 -16
- package/docs/reference.md +55 -22
- package/docs/security.md +58 -9
- package/docs/troubleshooting.md +19 -0
- package/package.json +27 -10
- package/dist/adapters/origins.d.ts +0 -19
- package/dist/adapters/origins.d.ts.map +0 -1
- package/dist/adapters/origins.js +0 -52
- package/dist/adapters/origins.js.map +0 -1
- package/dist/body.d.ts.map +0 -1
- package/dist/body.js.map +0 -1
- package/dist/dispatch.d.ts.map +0 -1
- package/dist/dispatch.js +0 -119
- package/dist/dispatch.js.map +0 -1
- package/dist/http.d.ts +0 -17
- package/dist/http.d.ts.map +0 -1
- package/dist/http.js +0 -38
- package/dist/http.js.map +0 -1
- package/dist/jsonrpc.d.ts.map +0 -1
- package/dist/jsonrpc.js +0 -18
- package/dist/jsonrpc.js.map +0 -1
- package/dist/methods.d.ts.map +0 -1
- package/dist/methods.js +0 -130
- package/dist/methods.js.map +0 -1
- package/dist/oauth/authorize.d.ts +0 -3
- package/dist/oauth/authorize.d.ts.map +0 -1
- package/dist/oauth/authorize.js +0 -141
- package/dist/oauth/authorize.js.map +0 -1
- package/dist/oauth/base64url.d.ts.map +0 -1
- package/dist/oauth/base64url.js.map +0 -1
- package/dist/oauth/clientauth.d.ts +0 -24
- package/dist/oauth/clientauth.d.ts.map +0 -1
- package/dist/oauth/clientauth.js +0 -119
- package/dist/oauth/clientauth.js.map +0 -1
- package/dist/oauth/codes.d.ts +0 -30
- package/dist/oauth/codes.d.ts.map +0 -1
- package/dist/oauth/codes.js +0 -85
- package/dist/oauth/codes.js.map +0 -1
- package/dist/oauth/consent.d.ts +0 -65
- package/dist/oauth/consent.d.ts.map +0 -1
- package/dist/oauth/consent.js +0 -173
- package/dist/oauth/consent.js.map +0 -1
- package/dist/oauth/metadata.d.ts.map +0 -1
- package/dist/oauth/metadata.js.map +0 -1
- package/dist/oauth/pkce.d.ts.map +0 -1
- package/dist/oauth/pkce.js.map +0 -1
- package/dist/oauth/redirect.d.ts.map +0 -1
- package/dist/oauth/redirect.js.map +0 -1
- package/dist/oauth/reqbody.d.ts +0 -10
- package/dist/oauth/reqbody.d.ts.map +0 -1
- package/dist/oauth/reqbody.js +0 -29
- package/dist/oauth/reqbody.js.map +0 -1
- package/dist/oauth/resource.d.ts.map +0 -1
- package/dist/oauth/resource.js.map +0 -1
- package/dist/oauth/revoke.d.ts.map +0 -1
- package/dist/oauth/revoke.js.map +0 -1
- package/dist/oauth/scope.d.ts.map +0 -1
- package/dist/oauth/scope.js.map +0 -1
- package/dist/oauth/sealed.d.ts.map +0 -1
- package/dist/oauth/sealed.js.map +0 -1
- package/dist/oauth/secrethash.d.ts.map +0 -1
- package/dist/oauth/secrethash.js.map +0 -1
- package/dist/oauth/token.d.ts +0 -3
- package/dist/oauth/token.d.ts.map +0 -1
- package/dist/oauth/token.js.map +0 -1
- package/dist/oauth/wellknown.d.ts.map +0 -1
- package/dist/oauth/wellknown.js.map +0 -1
- package/dist/protocol.d.ts.map +0 -1
- package/dist/protocol.js.map +0 -1
- package/dist/registry.d.ts +0 -37
- package/dist/registry.d.ts.map +0 -1
- package/dist/registry.js +0 -77
- package/dist/registry.js.map +0 -1
- package/dist/tools.d.ts.map +0 -1
- package/dist/tools.js +0 -98
- package/dist/tools.js.map +0 -1
- package/dist/validate.d.ts.map +0 -1
- package/dist/validate.js.map +0 -1
- /package/dist/oauth/{pkce.d.ts → crypto/pkce.d.ts} +0 -0
- /package/dist/oauth/{redirect.d.ts → policy/redirect.d.ts} +0 -0
- /package/dist/oauth/{redirect.js → policy/redirect.js} +0 -0
package/dist/oauth/router.js
CHANGED
|
@@ -1,119 +1,103 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { handleToken } from "./token.js";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
const text = await readBoundedText(request, DEFAULT_OAUTH_BODY_LIMIT);
|
|
22
|
-
const body = JSON.parse(text);
|
|
23
|
-
const raw = body.redirect_uris;
|
|
24
|
-
if (Array.isArray(raw)) {
|
|
25
|
-
suppliedRedirectUris = true;
|
|
26
|
-
redirectUris = raw
|
|
27
|
-
.map((u) => String(u))
|
|
28
|
-
.filter((uri) => isAllowedRedirectUri(uri, options.redirect));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
catch (exc) {
|
|
32
|
-
if (exc instanceof BodyTooLargeError) {
|
|
33
|
-
return oauthError(OAUTH_ERRORS.invalidRequest, 413, "request body too large");
|
|
34
|
-
}
|
|
35
|
-
redirectUris = [];
|
|
36
|
-
}
|
|
37
|
-
// No redirect_uris in the body: fall back to the Claude callback only if
|
|
38
|
-
// this server's own allowlist actually accepts it — never advertise a
|
|
39
|
-
// redirect_uri that `/authorize` would go on to reject (e.g. `clients`
|
|
40
|
-
// without `"claude"`, where `createMcpApp` sets `allowClaude: false`).
|
|
41
|
-
if (!suppliedRedirectUris && isAllowedRedirectUri(CLAUDE_CALLBACK, options.redirect)) {
|
|
42
|
-
redirectUris = [CLAUDE_CALLBACK];
|
|
43
|
-
}
|
|
44
|
-
if (redirectUris.length === 0) {
|
|
45
|
-
return oauthError(OAUTH_ERRORS.invalidRedirectUri, 400, suppliedRedirectUris
|
|
46
|
-
? "no allowed redirect_uris"
|
|
47
|
-
: "redirect_uris required — this server has no default redirect_uri");
|
|
48
|
-
}
|
|
49
|
-
// Zero storage: the client_id *is* the registration record — a sealed,
|
|
50
|
-
// self-verifying assertion of the redirect_uris this call just validated.
|
|
51
|
-
// `/authorize` unseals it and binds the client to exactly this list,
|
|
52
|
-
// the same protection a stored registration would give a pre-registered id.
|
|
53
|
-
const secret = await resolveSecret(options.ports, request);
|
|
54
|
-
const clientId = await seal(secret, "client", { redirectUris });
|
|
55
|
-
return jsonResponse({
|
|
56
|
-
client_id: clientId,
|
|
57
|
-
client_id_issued_at: Math.floor(Date.now() / 1000),
|
|
58
|
-
token_endpoint_auth_method: "none",
|
|
59
|
-
redirect_uris: redirectUris,
|
|
60
|
-
grant_types: [GRANT_TYPES.authorizationCode],
|
|
61
|
-
response_types: ["code"],
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
export const createOAuthRouter = (options) => {
|
|
1
|
+
import { errorReason, INTERNAL_ERROR } from "../http/http.js";
|
|
2
|
+
import { safeOAuthAudit } from "./audit.js";
|
|
3
|
+
import { assertCodeSecret, assertScopeConfig, oauthError, unregisteredClientsAllowed, } from "./config.js";
|
|
4
|
+
import { DEFAULT_OAUTH_PATH, OAUTH_ERRORS } from "./constants.js";
|
|
5
|
+
import { processCodeStore } from "./crypto/codes.js";
|
|
6
|
+
import { handleAuthorize } from "./endpoints/authorize.js";
|
|
7
|
+
import { handleConsent } from "./endpoints/consent.js";
|
|
8
|
+
import { handleRegister } from "./endpoints/register.js";
|
|
9
|
+
import { handleRevoke } from "./endpoints/revoke.js";
|
|
10
|
+
import { handleToken } from "./endpoints/token.js";
|
|
11
|
+
import { handleWellKnown } from "./endpoints/wellknown.js";
|
|
12
|
+
import { DEFAULT_RESOURCE_PATH, normalizeConfiguredPath } from "./policy/resource.js";
|
|
13
|
+
/**
|
|
14
|
+
* Function-form `codeSecret` is re-validated on every call in
|
|
15
|
+
* `resolveSecrets`, since its value can vary per request; a string or array
|
|
16
|
+
* form is fixed for the life of this router, so fail fast at construction
|
|
17
|
+
* instead of at the first request.
|
|
18
|
+
*/
|
|
19
|
+
const assertRouterOptions = (options) => {
|
|
65
20
|
if (!unregisteredClientsAllowed(options) && !options.ports.clientStore) {
|
|
66
21
|
throw new Error("allowUnregisteredClients: false requires ports.clientStore " +
|
|
67
22
|
"so pre-registered clients can be resolved");
|
|
68
23
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
24
|
+
if (!options.ports.codeStore && !options.allowInMemoryCodeStore) {
|
|
25
|
+
throw new Error("ports.codeStore is required (shared jti store for auth-code / consent single-use). " +
|
|
26
|
+
"Pass a CodeStore, or set allowInMemoryCodeStore: true for single-process demos/tests only");
|
|
27
|
+
}
|
|
73
28
|
if (typeof options.ports.codeSecret === "string") {
|
|
74
29
|
assertCodeSecret(options.ports.codeSecret);
|
|
75
30
|
}
|
|
31
|
+
if (Array.isArray(options.ports.codeSecret)) {
|
|
32
|
+
if (options.ports.codeSecret.length === 0) {
|
|
33
|
+
throw new Error("codeSecret array must not be empty — at least one key is required");
|
|
34
|
+
}
|
|
35
|
+
options.ports.codeSecret.forEach(assertCodeSecret);
|
|
36
|
+
}
|
|
76
37
|
assertScopeConfig(options);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Normalized once, not per request, so "/mcp/" and "/mcp" yield one
|
|
41
|
+
* canonical resource, and the routing table, discovery documents and the
|
|
42
|
+
* consent form action all agree on `oauthPath`.
|
|
43
|
+
*/
|
|
44
|
+
const normalizeRouterPaths = (options) => {
|
|
81
45
|
const resourcePath = normalizeConfiguredPath(options.resourcePath ?? DEFAULT_RESOURCE_PATH);
|
|
82
|
-
const oauthPath = options.oauthPath ??
|
|
46
|
+
const oauthPath = normalizeConfiguredPath(options.oauthPath ?? DEFAULT_OAUTH_PATH);
|
|
83
47
|
if (oauthPath === resourcePath) {
|
|
84
48
|
throw new Error(`oauthPath (${oauthPath}) must not equal resourcePath — they would shadow each other`);
|
|
85
49
|
}
|
|
86
50
|
if (resourcePath.startsWith("/.well-known")) {
|
|
87
51
|
throw new Error(`resourcePath (${resourcePath}) must not start with /.well-known — reserved for OAuth discovery documents`);
|
|
88
52
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
53
|
+
return {
|
|
54
|
+
resourcePath,
|
|
55
|
+
oauthPath,
|
|
56
|
+
prmPaths: new Set([
|
|
57
|
+
"/.well-known/oauth-protected-resource",
|
|
58
|
+
`/.well-known/oauth-protected-resource${resourcePath}`,
|
|
59
|
+
]),
|
|
60
|
+
asPaths: new Set([
|
|
61
|
+
"/.well-known/oauth-authorization-server",
|
|
62
|
+
`/.well-known/oauth-authorization-server${resourcePath}`,
|
|
63
|
+
]),
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
const buildRoutes = (options, normalizedOptions, oauthPath) => ({
|
|
67
|
+
...(unregisteredClientsAllowed(options)
|
|
68
|
+
? {
|
|
69
|
+
[`${oauthPath}/register`]: (request) => handleRegister(request, normalizedOptions),
|
|
70
|
+
}
|
|
71
|
+
: {}),
|
|
72
|
+
[`${oauthPath}/authorize`]: (request) => handleAuthorize(request, normalizedOptions),
|
|
73
|
+
[`${oauthPath}/consent`]: (request) => handleConsent(request, normalizedOptions),
|
|
74
|
+
[`${oauthPath}/token`]: (request) => handleToken(request, normalizedOptions),
|
|
75
|
+
...(options.ports.revokeToken
|
|
76
|
+
? {
|
|
77
|
+
[`${oauthPath}/revoke`]: (request) => handleRevoke(request, normalizedOptions),
|
|
78
|
+
}
|
|
79
|
+
: {}),
|
|
80
|
+
});
|
|
81
|
+
export const createOAuthRouter = (options) => {
|
|
82
|
+
assertRouterOptions(options);
|
|
83
|
+
// Resolved once; `assertRouterOptions` already required
|
|
84
|
+
// `allowInMemoryCodeStore` before the process store can be reached.
|
|
85
|
+
const codeStore = options.ports.codeStore ?? processCodeStore;
|
|
86
|
+
const ports = { ...options.ports, codeStore };
|
|
87
|
+
const { resourcePath, oauthPath, prmPaths, asPaths } = normalizeRouterPaths(options);
|
|
88
|
+
// Handlers read paths from here, never from the caller's raw options.
|
|
89
|
+
const normalizedOptions = {
|
|
90
|
+
...options,
|
|
91
|
+
resourcePath,
|
|
92
|
+
oauthPath,
|
|
93
|
+
ports,
|
|
111
94
|
};
|
|
95
|
+
const routes = buildRoutes(options, normalizedOptions, oauthPath);
|
|
112
96
|
return {
|
|
113
97
|
tryHandle: async (request) => {
|
|
114
98
|
try {
|
|
115
99
|
const path = new URL(request.url).pathname;
|
|
116
|
-
const known = await handleWellKnown(request,
|
|
100
|
+
const known = await handleWellKnown(request, normalizedOptions, {
|
|
117
101
|
prmPaths,
|
|
118
102
|
asPaths,
|
|
119
103
|
resourcePath,
|
|
@@ -124,31 +108,25 @@ export const createOAuthRouter = (options) => {
|
|
|
124
108
|
const route = routes[path];
|
|
125
109
|
return route ? await route(request) : null;
|
|
126
110
|
}
|
|
127
|
-
catch (
|
|
128
|
-
// A host port
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
// real error instead of throwing out of `tryHandle` — the caller
|
|
133
|
-
// gets the generic server_error; ports.audit gets the real reason.
|
|
134
|
-
await safeOAuthAudit(options, {
|
|
111
|
+
catch (caught) {
|
|
112
|
+
// A host port threw, or a per-request codeSecret failed validation.
|
|
113
|
+
// Only routes this router owns get here: the caller sees a generic
|
|
114
|
+
// server_error, ports.audit gets the real reason.
|
|
115
|
+
await safeOAuthAudit(normalizedOptions, {
|
|
135
116
|
event: "server_error",
|
|
136
|
-
reason:
|
|
117
|
+
reason: errorReason(caught),
|
|
137
118
|
});
|
|
138
119
|
return oauthError(OAUTH_ERRORS.serverError, 500, INTERNAL_ERROR);
|
|
139
120
|
}
|
|
140
121
|
},
|
|
141
122
|
};
|
|
142
123
|
};
|
|
143
|
-
export {
|
|
144
|
-
export { consumeAuthCode, issueAuthCode, newClientId, } from "./codes.js";
|
|
145
|
-
export { buildErrorRedirectUrl } from "./consent.js";
|
|
124
|
+
export { isCimdClientId, resolveCimdClient, } from "./cimd/cimd.js";
|
|
146
125
|
export { DEFAULT_SCOPE, GRANT_TYPES, OAUTH_ERRORS, TOKEN_ENDPOINT_AUTH_METHODS, } from "./constants.js";
|
|
147
|
-
export {
|
|
148
|
-
|
|
149
|
-
export
|
|
150
|
-
export {
|
|
151
|
-
export {
|
|
152
|
-
export {
|
|
153
|
-
export { advertisedScopes, defaultScopes, registeredClientsRequired, unregisteredClientsAllowed, } from "./types.js";
|
|
126
|
+
export { hashClientSecret, verifyClientSecret } from "./crypto/secrethash.js";
|
|
127
|
+
// Moved to `mcp-trellis/advanced`; deprecated aliases until 3.0.
|
|
128
|
+
export * from "./deprecated.js";
|
|
129
|
+
export { authorizationServerMetadata, mcpWwwAuthenticate, protectedResourceMetadata, } from "./endpoints/metadata.js";
|
|
130
|
+
export { CLAUDE_CALLBACK, isAllowedRedirectUri } from "./policy/redirect.js";
|
|
131
|
+
export { canonicalResource, DEFAULT_RESOURCE_PATH, resourcesEqual, } from "./policy/resource.js";
|
|
154
132
|
//# sourceMappingURL=router.js.map
|
package/dist/oauth/router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/oauth/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/oauth/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAkBtF;;;;;GAKG;AACH,MAAM,mBAAmB,GAAG,CAAC,OAA2B,EAAQ,EAAE;IAChE,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QACvE,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AAE,GAAG,EAAE,cAAc,CAAC,CAAC;YACnE,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,EAGL,cAAc,EACd,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,aAAa,EACb,WAAW,EACX,YAAY,EACZ,2BAA2B,GAE5B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC9E,iEAAiE;AACjE,cAAc,iBAAiB,CAAC;AAChC,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,GACf,MAAM,sBAAsB,CAAC"}
|
package/dist/oauth/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import type { RedirectAllowlistOptions } from "./redirect.js";
|
|
1
|
+
import type { CimdCache } from "./cimd/types.js";
|
|
2
|
+
import type { TokenEndpointAuthMethod } from "./constants.js";
|
|
3
|
+
import type { CodeStore } from "./crypto/codes.js";
|
|
4
|
+
import type { RedirectAllowlistOptions } from "./policy/redirect.js";
|
|
5
5
|
export type OAuthUser = {
|
|
6
6
|
id: string;
|
|
7
7
|
};
|
|
@@ -16,6 +16,35 @@ export type RegisteredClient = {
|
|
|
16
16
|
redirectUris: string[];
|
|
17
17
|
tokenEndpointAuthMethod: TokenEndpointAuthMethod;
|
|
18
18
|
};
|
|
19
|
+
export type ConsentRequest = {
|
|
20
|
+
clientId: string;
|
|
21
|
+
registeredClient: RegisteredClient | null;
|
|
22
|
+
redirectUri: string;
|
|
23
|
+
scope: string[];
|
|
24
|
+
resource: string;
|
|
25
|
+
user: OAuthUser;
|
|
26
|
+
/** Embed this in your form's `consent_ticket` field (hidden input or POST body). */
|
|
27
|
+
ticket: string;
|
|
28
|
+
oauthPath: string;
|
|
29
|
+
};
|
|
30
|
+
export type ConsentOptions = {
|
|
31
|
+
/**
|
|
32
|
+
* Render the approval page yourself. Return any `Response` — HTML, or a
|
|
33
|
+
* redirect to your own route. Omit for the built-in hardened interstitial.
|
|
34
|
+
*
|
|
35
|
+
* If your page sets its own `Content-Security-Policy` with `form-action`,
|
|
36
|
+
* include `new URL(input.redirectUri).origin` in it — Chromium enforces
|
|
37
|
+
* `form-action` across the redirect your approval POST triggers, not just
|
|
38
|
+
* the immediate submission target, so `'self'` alone blocks the eventual
|
|
39
|
+
* redirect back to the client's own callback.
|
|
40
|
+
*/
|
|
41
|
+
render?: (input: ConsentRequest) => Response | Promise<Response>;
|
|
42
|
+
/**
|
|
43
|
+
* Client ids that skip approval. Only honored when `clientStore` actually
|
|
44
|
+
* resolves the id — a DCR or self-invented id is never trusted.
|
|
45
|
+
*/
|
|
46
|
+
preApprovedClientIds?: string[];
|
|
47
|
+
};
|
|
19
48
|
/**
|
|
20
49
|
* The payload sealed into a `client_id` this server itself issued via
|
|
21
50
|
* `/register` (see `sealed.ts`, type `"client"`). Zero storage: the id
|
|
@@ -23,6 +52,13 @@ export type RegisteredClient = {
|
|
|
23
52
|
*/
|
|
24
53
|
export type ClientAssertion = {
|
|
25
54
|
redirectUris: string[];
|
|
55
|
+
/**
|
|
56
|
+
* Unix seconds when `/register` sealed this assertion. Informational only
|
|
57
|
+
* — not enforced as an expiry — so it can help an operator judge how old
|
|
58
|
+
* a still-valid DCR client is. Optional on read: an assertion sealed
|
|
59
|
+
* before this field existed still unseals and works.
|
|
60
|
+
*/
|
|
61
|
+
iat?: number;
|
|
26
62
|
};
|
|
27
63
|
export type ClientStore = {
|
|
28
64
|
/** Resolve a pre-registered client, or null when unknown. */
|
|
@@ -66,6 +102,13 @@ export type RefreshAccessTokenInput = {
|
|
|
66
102
|
* Implementations MUST reject refresh tokens not originally issued for this resource.
|
|
67
103
|
*/
|
|
68
104
|
resource: string;
|
|
105
|
+
/**
|
|
106
|
+
* RFC 6749 §6 — optional scope reduction requested by the client.
|
|
107
|
+
* When set, the library validates against advertised `scopes` only.
|
|
108
|
+
* Implementations MUST also reject any scope outside what was originally
|
|
109
|
+
* granted to this refresh token (the library cannot see opaque RTs).
|
|
110
|
+
*/
|
|
111
|
+
scope?: string;
|
|
69
112
|
};
|
|
70
113
|
export type RevokeTokenInput = {
|
|
71
114
|
token: string;
|
|
@@ -88,8 +131,18 @@ export type OAuthAuditEntry = {
|
|
|
88
131
|
reason: string;
|
|
89
132
|
};
|
|
90
133
|
export type OAuthPorts = {
|
|
91
|
-
/**
|
|
92
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Secret(s) that seal auth codes, consent tickets, and self-issued DCR
|
|
136
|
+
* client assertions (`sealed.ts`), and key `ClientStore.secretHash`.
|
|
137
|
+
*
|
|
138
|
+
* Pass a single string, or for key rotation an array: the **first** entry seals new material and hashes new client
|
|
139
|
+
* secrets; **every** entry is tried when unsealing/verifying, so material
|
|
140
|
+
* sealed under an older key keeps working until you drop it from the
|
|
141
|
+
* array. `ports.audit` sees a `"legacy_code_secret_used"` event whenever
|
|
142
|
+
* anything but the first entry was the one that actually verified,
|
|
143
|
+
* so you know when it's safe to remove.
|
|
144
|
+
*/
|
|
145
|
+
codeSecret: string | string[] | ((req: Request) => string | string[] | Promise<string | string[]>);
|
|
93
146
|
/** Resolve the logged-in user, or null → redirect to login. */
|
|
94
147
|
resolveUser: (req: Request) => Promise<OAuthUser | null>;
|
|
95
148
|
/** Where to send unauthenticated authorize requests. */
|
|
@@ -106,7 +159,7 @@ export type OAuthPorts = {
|
|
|
106
159
|
* tokens not issued to `clientId` MUST no-op (not throw).
|
|
107
160
|
*/
|
|
108
161
|
revokeToken?: ((input: RevokeTokenInput) => Promise<void>) | undefined;
|
|
109
|
-
/** Shared single-use jti store for multi-instance
|
|
162
|
+
/** Shared single-use jti store for multi-instance. Required unless `allowInMemoryCodeStore`. */
|
|
110
163
|
codeStore?: CodeStore | undefined;
|
|
111
164
|
/** Pre-registered clients. Required to serve confidential clients. */
|
|
112
165
|
clientStore?: ClientStore | undefined;
|
|
@@ -118,14 +171,6 @@ export type OAuthPorts = {
|
|
|
118
171
|
*/
|
|
119
172
|
audit?: ((entry: OAuthAuditEntry) => void | Promise<void>) | undefined;
|
|
120
173
|
};
|
|
121
|
-
/**
|
|
122
|
-
* Invoke `ports.audit`, swallowing any failure — the OAuth-side twin of
|
|
123
|
-
* `methods.ts`'s `safeAudit`. No timeout wrapper here: unlike the MCP
|
|
124
|
-
* side, nothing here is expected to be a slow, request-scoped metrics
|
|
125
|
-
* call in the same way, and adding one would be complexity without a
|
|
126
|
-
* demonstrated need — revisit if that changes.
|
|
127
|
-
*/
|
|
128
|
-
export declare const safeOAuthAudit: (options: OAuthRouterOptions, entry: OAuthAuditEntry) => Promise<void>;
|
|
129
174
|
export type OAuthRouterOptions = {
|
|
130
175
|
ports: OAuthPorts;
|
|
131
176
|
resourcePath?: string;
|
|
@@ -169,44 +214,53 @@ export type OAuthRouterOptions = {
|
|
|
169
214
|
* not under `ports`. Omit for the built-in hardened interstitial.
|
|
170
215
|
*/
|
|
171
216
|
consent?: ConsentOptions;
|
|
217
|
+
/**
|
|
218
|
+
* Max time to wait for `ports.audit` before responding anyway. Default
|
|
219
|
+
* 1000ms — same guarantee as `McpHandlerOptions.auditTimeoutMs`.
|
|
220
|
+
*/
|
|
221
|
+
auditTimeoutMs?: number;
|
|
222
|
+
/**
|
|
223
|
+
* Allow the process-local in-memory jti Map when `ports.codeStore` is
|
|
224
|
+
* omitted. Default **false** since 2.0 — multi-instance deploys silently
|
|
225
|
+
* double-redeem auth codes without a shared store. Set true only for
|
|
226
|
+
* single-process demos and tests.
|
|
227
|
+
*/
|
|
228
|
+
allowInMemoryCodeStore?: boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Resolve Client ID Metadata Documents (HTTPS URL `client_id`s).
|
|
231
|
+
* Default **false** — opt in with `cimd: true`. Off until connect-pinned
|
|
232
|
+
* fetch exists; see `cimd.ts` ponytail.
|
|
233
|
+
*/
|
|
234
|
+
cimd?: boolean;
|
|
235
|
+
/**
|
|
236
|
+
* CIMD document cache (respects Cache-Control max-age, capped at 1 h).
|
|
237
|
+
* **Strongly recommended with `cimd: true`:** without it `/token` and
|
|
238
|
+
* `/revoke` re-fetch the client's document on every call, so a flaky
|
|
239
|
+
* document host fails refresh/revoke (audited as `cimd_resolve_failed`).
|
|
240
|
+
*/
|
|
241
|
+
cimdCache?: CimdCache;
|
|
242
|
+
/** Optional DNS lookup for CIMD SSRF checks — see `CimdFetchOptions.lookup`. */
|
|
243
|
+
cimdLookup?: (hostname: string) => Promise<string[]>;
|
|
172
244
|
};
|
|
173
|
-
/** Default true — see `OAuthRouterOptions.allowUnregisteredClients`. */
|
|
174
|
-
export declare const unregisteredClientsAllowed: (options: OAuthRouterOptions) => boolean;
|
|
175
|
-
/** Default true since 1.0 — see `OAuthRouterOptions.requireRegisteredClients`. */
|
|
176
|
-
export declare const registeredClientsRequired: (options: OAuthRouterOptions) => boolean;
|
|
177
|
-
/** Scopes this AS advertises and is willing to grant. */
|
|
178
|
-
export declare const advertisedScopes: (options: OAuthRouterOptions) => string[];
|
|
179
245
|
/**
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* construction instead of silently over-granting here.
|
|
246
|
+
* `OAuthRouterOptions` after `createOAuthRouter` has resolved them: paths
|
|
247
|
+
* normalized and `ports.codeStore` always present, so no endpoint handler
|
|
248
|
+
* can fall back to a store of its own. Internal — not re-exported.
|
|
184
249
|
*/
|
|
185
|
-
export
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
export declare const assertCodeSecret: (secret: string) => void;
|
|
193
|
-
export declare const resolveSecret: (ports: OAuthPorts, req: Request) => Promise<string>;
|
|
250
|
+
export type ResolvedOAuthRouterOptions = OAuthRouterOptions & {
|
|
251
|
+
resourcePath: string;
|
|
252
|
+
oauthPath: string;
|
|
253
|
+
ports: OAuthPorts & {
|
|
254
|
+
codeStore: CodeStore;
|
|
255
|
+
};
|
|
256
|
+
};
|
|
194
257
|
/**
|
|
195
258
|
* An OAuth error's code and description without a `Response` built yet —
|
|
196
|
-
* lets a caller choose delivery: `oauthError`
|
|
197
|
-
*
|
|
198
|
-
* see `authorize.ts` and `consent.ts`).
|
|
259
|
+
* lets a caller choose delivery: `oauthError` for a direct JSON body, or a
|
|
260
|
+
* redirect to the client's own callback (RFC 6749 §4.1.2.1).
|
|
199
261
|
*/
|
|
200
262
|
export type OAuthErrorInfo = {
|
|
201
263
|
code: string;
|
|
202
264
|
description: string;
|
|
203
265
|
};
|
|
204
|
-
export declare const oauthError: (error: string, status: number, description?: string) => Response;
|
|
205
|
-
/** Direct JSON error when this AS does not serve unknown `client_id`s. */
|
|
206
|
-
export declare const unregisteredClientError: (options: OAuthRouterOptions, reject: {
|
|
207
|
-
code: string;
|
|
208
|
-
status: number;
|
|
209
|
-
}) => Response | null;
|
|
210
|
-
/** `grantedScope` is what the auth code carried; the port may narrow it further. */
|
|
211
|
-
export declare const tokenResponse: (minted: MintedToken, grantedScope?: string) => Response;
|
|
212
266
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/oauth/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/oauth/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KA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C,+EAA+E;IAC/E,wBAAwB,CAAC,EAAE,uBAAuB,EAAE,CAAC;IACrD;;;;;;;;;;OAUG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC;;;;;;;;OAQG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;;OAKG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,gFAAgF;IAChF,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACtD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,GAAG,kBAAkB,GAAG;IAC5D,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,UAAU,GAAG;QAAE,SAAS,EAAE,SAAS,CAAA;KAAE,CAAC;CAC9C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
package/dist/oauth/types.js
CHANGED
|
@@ -1,91 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { DEFAULT_SCOPE } from "./constants.js";
|
|
3
|
-
/**
|
|
4
|
-
* Invoke `ports.audit`, swallowing any failure — the OAuth-side twin of
|
|
5
|
-
* `methods.ts`'s `safeAudit`. No timeout wrapper here: unlike the MCP
|
|
6
|
-
* side, nothing here is expected to be a slow, request-scoped metrics
|
|
7
|
-
* call in the same way, and adding one would be complexity without a
|
|
8
|
-
* demonstrated need — revisit if that changes.
|
|
9
|
-
*/
|
|
10
|
-
export const safeOAuthAudit = async (options, entry) => {
|
|
11
|
-
try {
|
|
12
|
-
await options.ports.audit?.(entry);
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
// Intentionally ignored.
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
/** Default true — see `OAuthRouterOptions.allowUnregisteredClients`. */
|
|
19
|
-
export const unregisteredClientsAllowed = (options) => options.allowUnregisteredClients !== false;
|
|
20
|
-
/** Default true since 1.0 — see `OAuthRouterOptions.requireRegisteredClients`. */
|
|
21
|
-
export const registeredClientsRequired = (options) => options.requireRegisteredClients !== false;
|
|
22
|
-
/** Scopes this AS advertises and is willing to grant. */
|
|
23
|
-
export const advertisedScopes = (options) => options.scopes ?? [DEFAULT_SCOPE];
|
|
24
|
-
/**
|
|
25
|
-
* Scopes granted when a client omits `scope`. Falls back to the full
|
|
26
|
-
* advertised set only when that set has at most one entry — see
|
|
27
|
-
* `assertScopeConfig`, which forbids the ambiguous multi-scope case at
|
|
28
|
-
* construction instead of silently over-granting here.
|
|
29
|
-
*/
|
|
30
|
-
export const defaultScopes = (options) => options.defaultScopes ?? advertisedScopes(options);
|
|
31
|
-
/**
|
|
32
|
-
* A multi-scope server MUST say what an omitted `scope` grants — the
|
|
33
|
-
* alternative (silently granting everything advertised) is exactly the
|
|
34
|
-
* escalation least-privilege scoping exists to prevent.
|
|
35
|
-
*/
|
|
36
|
-
export const assertScopeConfig = (options) => {
|
|
37
|
-
const advertised = advertisedScopes(options);
|
|
38
|
-
if (advertised.length > 1 && !options.defaultScopes) {
|
|
39
|
-
throw new Error("scopes has more than one entry — defaultScopes must say what an omitted " +
|
|
40
|
-
"scope request grants (e.g. defaultScopes: [] for least privilege)");
|
|
41
|
-
}
|
|
42
|
-
const unknown = (options.defaultScopes ?? []).find((scope) => !advertised.includes(scope));
|
|
43
|
-
if (unknown !== undefined) {
|
|
44
|
-
throw new Error(`defaultScopes contains "${unknown}", which is not in scopes`);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* `codeSecret` can forge an auth code for any userId/scope/resource, so a
|
|
49
|
-
* weak or copy-pasted one is a full authorization bypass, not a footgun.
|
|
50
|
-
* The literals here are the exact strings this package's own docs/examples
|
|
51
|
-
* publish — copy-paste is the realistic failure mode.
|
|
52
|
-
*/
|
|
53
|
-
const MIN_CODE_SECRET_LENGTH = 32;
|
|
54
|
-
const DENYLISTED_CODE_SECRETS = new Set([
|
|
55
|
-
"e2e-code-secret-value",
|
|
56
|
-
"change-me",
|
|
57
|
-
"test-secret-value",
|
|
58
|
-
]);
|
|
59
|
-
const GENERATE_HINT = "generate one with `openssl rand -base64 32`";
|
|
60
|
-
export const assertCodeSecret = (secret) => {
|
|
61
|
-
// Checked before the length rule so a denylisted literal is always named
|
|
62
|
-
// for what it is, even if a future literal happens to be 32+ characters.
|
|
63
|
-
if (DENYLISTED_CODE_SECRETS.has(secret)) {
|
|
64
|
-
throw new Error(`codeSecret must not be a literal published in this package's own docs or examples — ${GENERATE_HINT}`);
|
|
65
|
-
}
|
|
66
|
-
if (secret.length < MIN_CODE_SECRET_LENGTH) {
|
|
67
|
-
throw new Error(`codeSecret must be at least ${MIN_CODE_SECRET_LENGTH} characters (got ${secret.length}) — ${GENERATE_HINT}`);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
export const resolveSecret = async (ports, req) => {
|
|
71
|
-
const secret = typeof ports.codeSecret === "string" ? ports.codeSecret : await ports.codeSecret(req);
|
|
72
|
-
assertCodeSecret(secret);
|
|
73
|
-
return secret;
|
|
74
|
-
};
|
|
75
|
-
export const oauthError = (error, status, description) => jsonResponse(description ? { error, error_description: description } : { error }, status, undefined, { cors: false });
|
|
76
|
-
const UNREGISTERED_CLIENT_DESCRIPTION = "unknown client_id — this server only serves pre-registered clients";
|
|
77
|
-
/** Direct JSON error when this AS does not serve unknown `client_id`s. */
|
|
78
|
-
export const unregisteredClientError = (options, reject) => {
|
|
79
|
-
if (unregisteredClientsAllowed(options))
|
|
80
|
-
return null;
|
|
81
|
-
return oauthError(reject.code, reject.status, UNREGISTERED_CLIENT_DESCRIPTION);
|
|
82
|
-
};
|
|
83
|
-
/** `grantedScope` is what the auth code carried; the port may narrow it further. */
|
|
84
|
-
export const tokenResponse = (minted, grantedScope) => jsonResponse({
|
|
85
|
-
access_token: minted.accessToken,
|
|
86
|
-
token_type: minted.tokenType ?? "bearer",
|
|
87
|
-
expires_in: minted.expiresIn,
|
|
88
|
-
scope: minted.scope ?? grantedScope ?? DEFAULT_SCOPE,
|
|
89
|
-
...(minted.refreshToken ? { refresh_token: minted.refreshToken } : {}),
|
|
90
|
-
}, 200, undefined, { cors: false });
|
|
1
|
+
export {};
|
|
91
2
|
//# sourceMappingURL=types.js.map
|
package/dist/oauth/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/oauth/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/oauth/types.ts"],"names":[],"mappings":""}
|