toolcraft 0.0.119 → 0.0.121
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/composition.json +17 -2
- package/dist/composition.json +17 -2
- package/dist/http.compile-check.d.ts +1 -0
- package/dist/http.compile-check.js +31 -0
- package/dist/http.d.ts +19 -0
- package/dist/http.js +62 -0
- package/dist/mcp.js +26 -11
- package/node_modules/jose/LICENSE.md +21 -0
- package/node_modules/jose/README.md +153 -0
- package/node_modules/jose/dist/types/index.d.ts +55 -0
- package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +31 -0
- package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +65 -0
- package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +31 -0
- package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +83 -0
- package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +38 -0
- package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +74 -0
- package/node_modules/jose/dist/types/jwk/embedded.d.ts +17 -0
- package/node_modules/jose/dist/types/jwk/thumbprint.d.ts +32 -0
- package/node_modules/jose/dist/types/jwks/local.d.ts +29 -0
- package/node_modules/jose/dist/types/jwks/remote.d.ts +237 -0
- package/node_modules/jose/dist/types/jws/compact/sign.d.ts +36 -0
- package/node_modules/jose/dist/types/jws/compact/verify.d.ts +33 -0
- package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +42 -0
- package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +33 -0
- package/node_modules/jose/dist/types/jws/general/sign.d.ts +53 -0
- package/node_modules/jose/dist/types/jws/general/verify.d.ts +41 -0
- package/node_modules/jose/dist/types/jwt/decrypt.d.ts +35 -0
- package/node_modules/jose/dist/types/jwt/encrypt.d.ts +91 -0
- package/node_modules/jose/dist/types/jwt/sign.d.ts +43 -0
- package/node_modules/jose/dist/types/jwt/unsecured.d.ts +43 -0
- package/node_modules/jose/dist/types/jwt/verify.d.ts +37 -0
- package/node_modules/jose/dist/types/key/export.d.ts +33 -0
- package/node_modules/jose/dist/types/key/generate_key_pair.d.ts +47 -0
- package/node_modules/jose/dist/types/key/generate_secret.d.ts +35 -0
- package/node_modules/jose/dist/types/key/import.d.ts +83 -0
- package/node_modules/jose/dist/types/types.d.ts +852 -0
- package/node_modules/jose/dist/types/util/base64url.d.ts +9 -0
- package/node_modules/jose/dist/types/util/decode_jwt.d.ts +18 -0
- package/node_modules/jose/dist/types/util/decode_protected_header.d.ts +17 -0
- package/node_modules/jose/dist/types/util/errors.d.ts +213 -0
- package/node_modules/jose/dist/webapi/index.js +32 -0
- package/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +27 -0
- package/node_modules/jose/dist/webapi/jwe/compact/encrypt.js +27 -0
- package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +159 -0
- package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +167 -0
- package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +31 -0
- package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +182 -0
- package/node_modules/jose/dist/webapi/jwk/embedded.js +17 -0
- package/node_modules/jose/dist/webapi/jwk/thumbprint.js +68 -0
- package/node_modules/jose/dist/webapi/jwks/local.js +119 -0
- package/node_modules/jose/dist/webapi/jwks/remote.js +179 -0
- package/node_modules/jose/dist/webapi/jws/compact/sign.js +18 -0
- package/node_modules/jose/dist/webapi/jws/compact/verify.js +21 -0
- package/node_modules/jose/dist/webapi/jws/flattened/sign.js +89 -0
- package/node_modules/jose/dist/webapi/jws/flattened/verify.js +110 -0
- package/node_modules/jose/dist/webapi/jws/general/sign.js +70 -0
- package/node_modules/jose/dist/webapi/jws/general/verify.js +24 -0
- package/node_modules/jose/dist/webapi/jwt/decrypt.js +23 -0
- package/node_modules/jose/dist/webapi/jwt/encrypt.js +101 -0
- package/node_modules/jose/dist/webapi/jwt/sign.js +52 -0
- package/node_modules/jose/dist/webapi/jwt/unsecured.js +63 -0
- package/node_modules/jose/dist/webapi/jwt/verify.js +15 -0
- package/node_modules/jose/dist/webapi/key/export.js +11 -0
- package/node_modules/jose/dist/webapi/key/generate_key_pair.js +97 -0
- package/node_modules/jose/dist/webapi/key/generate_secret.js +40 -0
- package/node_modules/jose/dist/webapi/key/import.js +57 -0
- package/node_modules/jose/dist/webapi/lib/aesgcmkw.js +15 -0
- package/node_modules/jose/dist/webapi/lib/aeskw.js +25 -0
- package/node_modules/jose/dist/webapi/lib/asn1.js +243 -0
- package/node_modules/jose/dist/webapi/lib/base64.js +22 -0
- package/node_modules/jose/dist/webapi/lib/buffer_utils.js +43 -0
- package/node_modules/jose/dist/webapi/lib/check_key_type.js +122 -0
- package/node_modules/jose/dist/webapi/lib/content_encryption.js +217 -0
- package/node_modules/jose/dist/webapi/lib/crypto_key.js +136 -0
- package/node_modules/jose/dist/webapi/lib/deflate.js +44 -0
- package/node_modules/jose/dist/webapi/lib/ecdhes.js +52 -0
- package/node_modules/jose/dist/webapi/lib/helpers.js +19 -0
- package/node_modules/jose/dist/webapi/lib/invalid_key_input.js +27 -0
- package/node_modules/jose/dist/webapi/lib/is_key_like.js +17 -0
- package/node_modules/jose/dist/webapi/lib/jwk_to_key.js +107 -0
- package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +238 -0
- package/node_modules/jose/dist/webapi/lib/key_management.js +186 -0
- package/node_modules/jose/dist/webapi/lib/key_to_jwk.js +31 -0
- package/node_modules/jose/dist/webapi/lib/normalize_key.js +166 -0
- package/node_modules/jose/dist/webapi/lib/pbes2kw.js +42 -0
- package/node_modules/jose/dist/webapi/lib/rsaes.js +24 -0
- package/node_modules/jose/dist/webapi/lib/signing.js +68 -0
- package/node_modules/jose/dist/webapi/lib/type_checks.js +40 -0
- package/node_modules/jose/dist/webapi/lib/validate_algorithms.js +10 -0
- package/node_modules/jose/dist/webapi/lib/validate_crit.js +33 -0
- package/node_modules/jose/dist/webapi/util/base64url.js +30 -0
- package/node_modules/jose/dist/webapi/util/decode_jwt.js +32 -0
- package/node_modules/jose/dist/webapi/util/decode_protected_header.js +34 -0
- package/node_modules/jose/dist/webapi/util/errors.js +99 -0
- package/node_modules/jose/package.json +200 -0
- package/node_modules/tiny-http-mcp-server/LICENSE +21 -0
- package/node_modules/tiny-http-mcp-server/README.md +778 -0
- package/node_modules/tiny-http-mcp-server/dist/auth.d.ts +69 -0
- package/node_modules/tiny-http-mcp-server/dist/auth.js +261 -0
- package/node_modules/tiny-http-mcp-server/dist/cli.d.ts +20 -0
- package/node_modules/tiny-http-mcp-server/dist/cli.js +465 -0
- package/node_modules/tiny-http-mcp-server/dist/composition.json +30 -0
- package/node_modules/tiny-http-mcp-server/dist/express-middleware.d.ts +18 -0
- package/node_modules/tiny-http-mcp-server/dist/express-middleware.js +90 -0
- package/node_modules/tiny-http-mcp-server/dist/http-server.d.ts +49 -0
- package/node_modules/tiny-http-mcp-server/dist/http-server.js +264 -0
- package/node_modules/tiny-http-mcp-server/dist/http-transport.d.ts +164 -0
- package/node_modules/tiny-http-mcp-server/dist/http-transport.js +897 -0
- package/node_modules/tiny-http-mcp-server/dist/index.d.ts +13 -0
- package/node_modules/tiny-http-mcp-server/dist/index.js +6 -0
- package/node_modules/tiny-http-mcp-server/dist/load-oauth-verifier.d.ts +6 -0
- package/node_modules/tiny-http-mcp-server/dist/load-oauth-verifier.js +43 -0
- package/node_modules/tiny-http-mcp-server/dist/parse-body.d.ts +22 -0
- package/node_modules/tiny-http-mcp-server/dist/parse-body.js +150 -0
- package/node_modules/tiny-http-mcp-server/dist/server.d.ts +9 -0
- package/node_modules/tiny-http-mcp-server/dist/server.js +4 -0
- package/node_modules/tiny-http-mcp-server/dist/session.d.ts +18 -0
- package/node_modules/tiny-http-mcp-server/dist/session.js +37 -0
- package/node_modules/tiny-http-mcp-server/dist/sse.d.ts +11 -0
- package/node_modules/tiny-http-mcp-server/dist/sse.js +22 -0
- package/node_modules/tiny-http-mcp-server/dist/test-support.d.ts +10 -0
- package/node_modules/tiny-http-mcp-server/dist/test-support.js +398 -0
- package/node_modules/tiny-http-mcp-server/dist/testing.d.ts +59 -0
- package/node_modules/tiny-http-mcp-server/dist/testing.js +191 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/LICENSE +21 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/README.md +70 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/auth-store-session-store.d.ts +14 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/auth-store-session-store.js +169 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/authorization-state.d.ts +8 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/authorization-state.js +47 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.d.ts +3 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.js +627 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/loopback-authorization.d.ts +20 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/loopback-authorization.js +207 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/pkce.d.ts +2 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/pkce.js +7 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-endpoint.d.ts +40 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-endpoint.js +164 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/types.d.ts +113 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/types.js +1 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.d.ts +10 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.js +7 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/resource-indicator.d.ts +1 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/resource-indicator.js +11 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/server/jwks-token-verifier.d.ts +32 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/server/jwks-token-verifier.js +388 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/types.compile-check.d.ts +1 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/types.compile-check.js +22 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/package.json +28 -0
- package/node_modules/tiny-http-mcp-server/package.json +59 -0
- package/node_modules/tiny-stdio-mcp-server/dist/composition.json +1 -1
- package/node_modules/toolcraft-schema/package.json +1 -1
- package/package.json +11 -4
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# mcp-oauth
|
|
2
|
+
|
|
3
|
+
OAuth client primitives for MCP HTTP transports.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import {
|
|
9
|
+
createAuthStoreSessionStore,
|
|
10
|
+
createDefaultOAuthClientProvider,
|
|
11
|
+
createJwksTokenVerifier
|
|
12
|
+
} from "mcp-oauth";
|
|
13
|
+
|
|
14
|
+
const provider = createDefaultOAuthClientProvider({
|
|
15
|
+
client: { mode: "dynamic" },
|
|
16
|
+
browser: { openBrowser: async (url) => console.log(url) },
|
|
17
|
+
sessionStore: createAuthStoreSessionStore({ serviceName: "mcp-client" })
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const verifier = createJwksTokenVerifier({
|
|
21
|
+
jwksUrl: "https://example.com/.well-known/jwks.json"
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Public API
|
|
26
|
+
|
|
27
|
+
- `createDefaultOAuthClientProvider(options)`: default MCP OAuth client provider with dynamic or static client registration.
|
|
28
|
+
- `createOAuthClientProvider(options)`: lower-level provider constructor.
|
|
29
|
+
- `createAuthStoreSessionStore(options)`: persisted OAuth session store backed by `auth-store`.
|
|
30
|
+
- `createLoopbackAuthorizationSession(options)`: local callback server for browser authorization.
|
|
31
|
+
- `generateCodeVerifier()` and `generateCodeChallenge(...)`: PKCE helpers.
|
|
32
|
+
- `canonicalizeResourceIndicator(value)`: resource indicator canonicalization.
|
|
33
|
+
- `createJwksTokenVerifier(options)`: JWKS-backed access-token verifier for MCP servers.
|
|
34
|
+
- `OAuthError`: token endpoint error type.
|
|
35
|
+
|
|
36
|
+
## Configuration
|
|
37
|
+
|
|
38
|
+
`createDefaultOAuthClientProvider(options)` accepts:
|
|
39
|
+
|
|
40
|
+
- `client`
|
|
41
|
+
- `mode: "dynamic"` with optional `metadata`
|
|
42
|
+
- `mode: "static"` with `clientId`, optional `clientSecret`, optional `metadata`
|
|
43
|
+
- `browser.openBrowser(url)`
|
|
44
|
+
- `browser.readLine()` optional
|
|
45
|
+
- `browser.createServer()` optional
|
|
46
|
+
- `browser.landingPage` optional
|
|
47
|
+
- `sessionStore` optional
|
|
48
|
+
- `authStore` optional `auth-store` backend config for the default session store
|
|
49
|
+
- `now()` optional clock override
|
|
50
|
+
|
|
51
|
+
`createJwksTokenVerifier(options)` accepts:
|
|
52
|
+
|
|
53
|
+
| Option | Type | Default | Description |
|
|
54
|
+
| ------------------------ | ------------------- | -------------- | ---------------------------------------------------------------------------------------- |
|
|
55
|
+
| `jwksUrl` | `string \| URL` | none | Authorization server JWKS endpoint. |
|
|
56
|
+
| `clockSkewSeconds` | `number` | `30` | Allowed JWT time-claim clock skew. |
|
|
57
|
+
| `allowedAlgorithms` | `readonly string[]` | asymmetric set | Allowed JWT signature algorithms. |
|
|
58
|
+
| `jwksCacheTtlMs` | `number` | `300000` | Successful JWKS cache lifetime. |
|
|
59
|
+
| `jwksFetchTimeoutMs` | `number` | `5000` | Timeout for each JWKS HTTP fetch. |
|
|
60
|
+
| `jwksRefreshCooldownMs` | `number` | `30000` | Minimum interval between forced refreshes after an unknown key id. |
|
|
61
|
+
| `allowInsecureJwks` | `boolean` | `false` | Permit non-HTTPS JWKS URLs. Loopback HTTP URLs are allowed without enabling this option. |
|
|
62
|
+
| `requireAccessTokenType` | `boolean` | `false` | Require the JWT `typ` protected header to be `at+jwt`. |
|
|
63
|
+
| `fetch` | `typeof fetch` | global `fetch` | Custom fetch implementation. |
|
|
64
|
+
|
|
65
|
+
`createAuthStoreSessionStore(options)` accepts the standard `auth-store` config.
|
|
66
|
+
|
|
67
|
+
## Environment Variables
|
|
68
|
+
|
|
69
|
+
This package exposes no direct environment variables. When `authStore` is used,
|
|
70
|
+
`auth-store` honors its own backend environment variables.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type CreateSecretStoreInput } from "auth-store";
|
|
2
|
+
import type { OAuthSessionStore } from "./types.js";
|
|
3
|
+
interface StoredOAuthClient {
|
|
4
|
+
clientId: string;
|
|
5
|
+
clientSecret?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface OAuthClientStore {
|
|
8
|
+
load(issuer: string): Promise<StoredOAuthClient | null>;
|
|
9
|
+
save(issuer: string, client: StoredOAuthClient): Promise<void>;
|
|
10
|
+
clear(issuer: string): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare function createAuthStoreSessionStore(options?: CreateSecretStoreInput): OAuthSessionStore;
|
|
13
|
+
export declare function createAuthStoreClientStore(options: CreateSecretStoreInput): OAuthClientStore;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createSecretStore } from "auth-store";
|
|
4
|
+
import { canonicalizeResourceIndicator } from "../resource-indicator.js";
|
|
5
|
+
const DEFAULT_FILE_SALT = "poe-code:mcp-oauth:v1";
|
|
6
|
+
const DEFAULT_FILE_DIRECTORY = ".poe-code/mcp-oauth";
|
|
7
|
+
const DEFAULT_KEYCHAIN_SERVICE = "poe-code-mcp-oauth";
|
|
8
|
+
const DEFAULT_CLIENT_FILE_SALT = "poe-code:mcp-oauth:clients:v1";
|
|
9
|
+
const DEFAULT_CLIENT_FILE_DIRECTORY = ".poe-code/mcp-oauth/clients";
|
|
10
|
+
const DEFAULT_CLIENT_KEYCHAIN_SERVICE = "poe-code-mcp-oauth-clients";
|
|
11
|
+
const MAX_JS_DATE_MS = 8_640_000_000_000_000;
|
|
12
|
+
export function createAuthStoreSessionStore(options = {}) {
|
|
13
|
+
return {
|
|
14
|
+
async load(resource) {
|
|
15
|
+
const store = createResourceSecretStore(resource, options);
|
|
16
|
+
const value = await store.get();
|
|
17
|
+
if (value === null) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const parsed = JSON.parse(value);
|
|
21
|
+
if (isStoredOAuthSession(parsed)) {
|
|
22
|
+
return parsed;
|
|
23
|
+
}
|
|
24
|
+
throw new Error("Stored OAuth session must match the expected shape");
|
|
25
|
+
},
|
|
26
|
+
async save(resource, session) {
|
|
27
|
+
const store = createResourceSecretStore(resource, options);
|
|
28
|
+
await store.set(JSON.stringify(session));
|
|
29
|
+
},
|
|
30
|
+
async clear(resource) {
|
|
31
|
+
const store = createResourceSecretStore(resource, options);
|
|
32
|
+
await store.delete();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function createAuthStoreClientStore(options) {
|
|
37
|
+
return {
|
|
38
|
+
async load(issuer) {
|
|
39
|
+
const store = createIssuerSecretStore(issuer, options);
|
|
40
|
+
const value = await store.get();
|
|
41
|
+
if (value === null) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const parsed = JSON.parse(value);
|
|
45
|
+
const clientId = isObjectRecord(parsed) ? getOwnString(parsed, "clientId") : undefined;
|
|
46
|
+
if (clientId !== undefined) {
|
|
47
|
+
const client = { clientId };
|
|
48
|
+
if (isObjectRecord(parsed) &&
|
|
49
|
+
Object.prototype.hasOwnProperty.call(parsed, "clientSecret")) {
|
|
50
|
+
client.clientSecret = getOwnEntry(parsed, "clientSecret");
|
|
51
|
+
}
|
|
52
|
+
return client;
|
|
53
|
+
}
|
|
54
|
+
throw new Error("Stored OAuth client must be a JSON object with clientId");
|
|
55
|
+
},
|
|
56
|
+
async save(issuer, client) {
|
|
57
|
+
const store = createIssuerSecretStore(issuer, options);
|
|
58
|
+
await store.set(JSON.stringify(client));
|
|
59
|
+
},
|
|
60
|
+
async clear(issuer) {
|
|
61
|
+
const store = createIssuerSecretStore(issuer, options);
|
|
62
|
+
await store.delete();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function createNamedSecretStore(key, options, defaults) {
|
|
67
|
+
const hash = crypto.createHash("sha256").update(key).digest("hex");
|
|
68
|
+
const configuredFilePath = options.fileStore?.filePath;
|
|
69
|
+
const parsedFilePath = configuredFilePath === undefined ? null : path.parse(configuredFilePath);
|
|
70
|
+
const fileStore = {
|
|
71
|
+
...options.fileStore,
|
|
72
|
+
filePath: parsedFilePath === null
|
|
73
|
+
? undefined
|
|
74
|
+
: path.join(parsedFilePath.dir, `${parsedFilePath.name}-${hash}${parsedFilePath.ext || ".enc"}`),
|
|
75
|
+
salt: options.fileStore?.salt ?? defaults.salt,
|
|
76
|
+
defaultDirectory: options.fileStore?.defaultDirectory || defaults.directory,
|
|
77
|
+
defaultFileName: parsedFilePath === null
|
|
78
|
+
? `${hash}.enc`
|
|
79
|
+
: `${parsedFilePath.name}-${hash}${parsedFilePath.ext || ".enc"}`
|
|
80
|
+
};
|
|
81
|
+
const keychainStore = {
|
|
82
|
+
...options.keychainStore,
|
|
83
|
+
service: options.keychainStore?.service ?? defaults.service,
|
|
84
|
+
account: `${options.keychainStore?.account ?? defaults.accountPrefix}:${hash}`
|
|
85
|
+
};
|
|
86
|
+
return createSecretStore({ ...options, fileStore, keychainStore }).store;
|
|
87
|
+
}
|
|
88
|
+
function createResourceSecretStore(resource, options) {
|
|
89
|
+
return createNamedSecretStore(canonicalizeResourceIndicator(resource), options, {
|
|
90
|
+
salt: DEFAULT_FILE_SALT,
|
|
91
|
+
directory: DEFAULT_FILE_DIRECTORY,
|
|
92
|
+
service: DEFAULT_KEYCHAIN_SERVICE,
|
|
93
|
+
accountPrefix: "provider"
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function createIssuerSecretStore(issuer, options) {
|
|
97
|
+
return createNamedSecretStore(issuer, options, {
|
|
98
|
+
salt: DEFAULT_CLIENT_FILE_SALT,
|
|
99
|
+
directory: DEFAULT_CLIENT_FILE_DIRECTORY,
|
|
100
|
+
service: DEFAULT_CLIENT_KEYCHAIN_SERVICE,
|
|
101
|
+
accountPrefix: "issuer"
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function isObjectRecord(value) {
|
|
105
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
106
|
+
}
|
|
107
|
+
function getOwnEntry(record, key) {
|
|
108
|
+
return Object.prototype.hasOwnProperty.call(record, key) ? record[key] : undefined;
|
|
109
|
+
}
|
|
110
|
+
function getOwnString(record, key) {
|
|
111
|
+
const value = getOwnEntry(record, key);
|
|
112
|
+
return typeof value === "string" ? value : undefined;
|
|
113
|
+
}
|
|
114
|
+
function isStoredOAuthSession(value) {
|
|
115
|
+
if (!isObjectRecord(value)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
return (isNonBlankOwnString(value, "resource") &&
|
|
119
|
+
isNonBlankOwnString(value, "authorizationServer") &&
|
|
120
|
+
isStoredOAuthClient(getOwnEntry(value, "client")) &&
|
|
121
|
+
isStoredOAuthDiscovery(getOwnEntry(value, "discovery")) &&
|
|
122
|
+
isStoredOAuthTokensOrMissing(getOwnEntry(value, "tokens")));
|
|
123
|
+
}
|
|
124
|
+
function isStoredOAuthClient(value) {
|
|
125
|
+
if (!isObjectRecord(value) || !isNonBlankOwnString(value, "clientId")) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
const clientSecret = getOwnEntry(value, "clientSecret");
|
|
129
|
+
return (clientSecret === undefined ||
|
|
130
|
+
(typeof clientSecret === "string" && clientSecret.trim().length > 0));
|
|
131
|
+
}
|
|
132
|
+
function isStoredOAuthDiscovery(value) {
|
|
133
|
+
if (!isObjectRecord(value)) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
return (isNonBlankOwnString(value, "resourceMetadataUrl") &&
|
|
137
|
+
isObjectRecord(getOwnEntry(value, "resourceMetadata")) &&
|
|
138
|
+
isObjectRecord(getOwnEntry(value, "authorizationServerMetadata")));
|
|
139
|
+
}
|
|
140
|
+
function isStoredOAuthTokensOrMissing(value) {
|
|
141
|
+
if (value === undefined) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
if (!isObjectRecord(value)) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
if (!isNonBlankOwnString(value, "accessToken") || getOwnString(value, "tokenType") !== "Bearer") {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
const expiresAt = getOwnEntry(value, "expiresAt");
|
|
151
|
+
if (expiresAt !== null &&
|
|
152
|
+
(typeof expiresAt !== "number" ||
|
|
153
|
+
!Number.isSafeInteger(expiresAt) ||
|
|
154
|
+
expiresAt > MAX_JS_DATE_MS ||
|
|
155
|
+
!Number.isFinite(new Date(expiresAt).getTime()))) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
const refreshToken = getOwnEntry(value, "refreshToken");
|
|
159
|
+
if (refreshToken !== undefined &&
|
|
160
|
+
(typeof refreshToken !== "string" || refreshToken.trim().length === 0)) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
const scope = getOwnEntry(value, "scope");
|
|
164
|
+
return scope === undefined || (typeof scope === "string" && scope.trim().length > 0);
|
|
165
|
+
}
|
|
166
|
+
function isNonBlankOwnString(record, key) {
|
|
167
|
+
const value = getOwnString(record, key);
|
|
168
|
+
return value !== undefined && value.trim().length > 0;
|
|
169
|
+
}
|
package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/authorization-state.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
export function createAuthorizationState(input) {
|
|
3
|
+
const payload = {
|
|
4
|
+
v: 1,
|
|
5
|
+
n: crypto.randomBytes(16).toString("base64url"),
|
|
6
|
+
i: input.issuer,
|
|
7
|
+
r: input.requireIssuer,
|
|
8
|
+
};
|
|
9
|
+
return Buffer.from(JSON.stringify(payload), "utf8").toString("base64url");
|
|
10
|
+
}
|
|
11
|
+
export function parseAuthorizationState(value) {
|
|
12
|
+
if (value === null || value.length === 0) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const decoded = Buffer.from(value, "base64url").toString("utf8");
|
|
17
|
+
const parsed = JSON.parse(decoded);
|
|
18
|
+
if (!isObjectRecord(parsed)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const version = getOwnEntry(parsed, "v");
|
|
22
|
+
const nonce = getOwnEntry(parsed, "n");
|
|
23
|
+
const issuer = getOwnEntry(parsed, "i");
|
|
24
|
+
const requireIssuer = getOwnEntry(parsed, "r");
|
|
25
|
+
if (version !== 1
|
|
26
|
+
|| typeof nonce !== "string"
|
|
27
|
+
|| nonce.length === 0
|
|
28
|
+
|| typeof issuer !== "string"
|
|
29
|
+
|| issuer.length === 0
|
|
30
|
+
|| typeof requireIssuer !== "boolean") {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
issuer,
|
|
35
|
+
requireIssuer,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function isObjectRecord(value) {
|
|
43
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
44
|
+
}
|
|
45
|
+
function getOwnEntry(record, key) {
|
|
46
|
+
return Object.prototype.hasOwnProperty.call(record, key) ? record[key] : undefined;
|
|
47
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { DefaultOAuthClientProviderOptions, OAuthClientProvider, OAuthClientProviderOptions } from "./types.js";
|
|
2
|
+
export declare function createOAuthClientProvider(options: OAuthClientProviderOptions): OAuthClientProvider;
|
|
3
|
+
export declare function createDefaultOAuthClientProvider(options: DefaultOAuthClientProviderOptions): OAuthClientProvider;
|