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.
Files changed (153) hide show
  1. package/composition.json +17 -2
  2. package/dist/composition.json +17 -2
  3. package/dist/http.compile-check.d.ts +1 -0
  4. package/dist/http.compile-check.js +31 -0
  5. package/dist/http.d.ts +19 -0
  6. package/dist/http.js +62 -0
  7. package/dist/mcp.js +26 -11
  8. package/node_modules/jose/LICENSE.md +21 -0
  9. package/node_modules/jose/README.md +153 -0
  10. package/node_modules/jose/dist/types/index.d.ts +55 -0
  11. package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +31 -0
  12. package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +65 -0
  13. package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +31 -0
  14. package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +83 -0
  15. package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +38 -0
  16. package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +74 -0
  17. package/node_modules/jose/dist/types/jwk/embedded.d.ts +17 -0
  18. package/node_modules/jose/dist/types/jwk/thumbprint.d.ts +32 -0
  19. package/node_modules/jose/dist/types/jwks/local.d.ts +29 -0
  20. package/node_modules/jose/dist/types/jwks/remote.d.ts +237 -0
  21. package/node_modules/jose/dist/types/jws/compact/sign.d.ts +36 -0
  22. package/node_modules/jose/dist/types/jws/compact/verify.d.ts +33 -0
  23. package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +42 -0
  24. package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +33 -0
  25. package/node_modules/jose/dist/types/jws/general/sign.d.ts +53 -0
  26. package/node_modules/jose/dist/types/jws/general/verify.d.ts +41 -0
  27. package/node_modules/jose/dist/types/jwt/decrypt.d.ts +35 -0
  28. package/node_modules/jose/dist/types/jwt/encrypt.d.ts +91 -0
  29. package/node_modules/jose/dist/types/jwt/sign.d.ts +43 -0
  30. package/node_modules/jose/dist/types/jwt/unsecured.d.ts +43 -0
  31. package/node_modules/jose/dist/types/jwt/verify.d.ts +37 -0
  32. package/node_modules/jose/dist/types/key/export.d.ts +33 -0
  33. package/node_modules/jose/dist/types/key/generate_key_pair.d.ts +47 -0
  34. package/node_modules/jose/dist/types/key/generate_secret.d.ts +35 -0
  35. package/node_modules/jose/dist/types/key/import.d.ts +83 -0
  36. package/node_modules/jose/dist/types/types.d.ts +852 -0
  37. package/node_modules/jose/dist/types/util/base64url.d.ts +9 -0
  38. package/node_modules/jose/dist/types/util/decode_jwt.d.ts +18 -0
  39. package/node_modules/jose/dist/types/util/decode_protected_header.d.ts +17 -0
  40. package/node_modules/jose/dist/types/util/errors.d.ts +213 -0
  41. package/node_modules/jose/dist/webapi/index.js +32 -0
  42. package/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +27 -0
  43. package/node_modules/jose/dist/webapi/jwe/compact/encrypt.js +27 -0
  44. package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +159 -0
  45. package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +167 -0
  46. package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +31 -0
  47. package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +182 -0
  48. package/node_modules/jose/dist/webapi/jwk/embedded.js +17 -0
  49. package/node_modules/jose/dist/webapi/jwk/thumbprint.js +68 -0
  50. package/node_modules/jose/dist/webapi/jwks/local.js +119 -0
  51. package/node_modules/jose/dist/webapi/jwks/remote.js +179 -0
  52. package/node_modules/jose/dist/webapi/jws/compact/sign.js +18 -0
  53. package/node_modules/jose/dist/webapi/jws/compact/verify.js +21 -0
  54. package/node_modules/jose/dist/webapi/jws/flattened/sign.js +89 -0
  55. package/node_modules/jose/dist/webapi/jws/flattened/verify.js +110 -0
  56. package/node_modules/jose/dist/webapi/jws/general/sign.js +70 -0
  57. package/node_modules/jose/dist/webapi/jws/general/verify.js +24 -0
  58. package/node_modules/jose/dist/webapi/jwt/decrypt.js +23 -0
  59. package/node_modules/jose/dist/webapi/jwt/encrypt.js +101 -0
  60. package/node_modules/jose/dist/webapi/jwt/sign.js +52 -0
  61. package/node_modules/jose/dist/webapi/jwt/unsecured.js +63 -0
  62. package/node_modules/jose/dist/webapi/jwt/verify.js +15 -0
  63. package/node_modules/jose/dist/webapi/key/export.js +11 -0
  64. package/node_modules/jose/dist/webapi/key/generate_key_pair.js +97 -0
  65. package/node_modules/jose/dist/webapi/key/generate_secret.js +40 -0
  66. package/node_modules/jose/dist/webapi/key/import.js +57 -0
  67. package/node_modules/jose/dist/webapi/lib/aesgcmkw.js +15 -0
  68. package/node_modules/jose/dist/webapi/lib/aeskw.js +25 -0
  69. package/node_modules/jose/dist/webapi/lib/asn1.js +243 -0
  70. package/node_modules/jose/dist/webapi/lib/base64.js +22 -0
  71. package/node_modules/jose/dist/webapi/lib/buffer_utils.js +43 -0
  72. package/node_modules/jose/dist/webapi/lib/check_key_type.js +122 -0
  73. package/node_modules/jose/dist/webapi/lib/content_encryption.js +217 -0
  74. package/node_modules/jose/dist/webapi/lib/crypto_key.js +136 -0
  75. package/node_modules/jose/dist/webapi/lib/deflate.js +44 -0
  76. package/node_modules/jose/dist/webapi/lib/ecdhes.js +52 -0
  77. package/node_modules/jose/dist/webapi/lib/helpers.js +19 -0
  78. package/node_modules/jose/dist/webapi/lib/invalid_key_input.js +27 -0
  79. package/node_modules/jose/dist/webapi/lib/is_key_like.js +17 -0
  80. package/node_modules/jose/dist/webapi/lib/jwk_to_key.js +107 -0
  81. package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +238 -0
  82. package/node_modules/jose/dist/webapi/lib/key_management.js +186 -0
  83. package/node_modules/jose/dist/webapi/lib/key_to_jwk.js +31 -0
  84. package/node_modules/jose/dist/webapi/lib/normalize_key.js +166 -0
  85. package/node_modules/jose/dist/webapi/lib/pbes2kw.js +42 -0
  86. package/node_modules/jose/dist/webapi/lib/rsaes.js +24 -0
  87. package/node_modules/jose/dist/webapi/lib/signing.js +68 -0
  88. package/node_modules/jose/dist/webapi/lib/type_checks.js +40 -0
  89. package/node_modules/jose/dist/webapi/lib/validate_algorithms.js +10 -0
  90. package/node_modules/jose/dist/webapi/lib/validate_crit.js +33 -0
  91. package/node_modules/jose/dist/webapi/util/base64url.js +30 -0
  92. package/node_modules/jose/dist/webapi/util/decode_jwt.js +32 -0
  93. package/node_modules/jose/dist/webapi/util/decode_protected_header.js +34 -0
  94. package/node_modules/jose/dist/webapi/util/errors.js +99 -0
  95. package/node_modules/jose/package.json +200 -0
  96. package/node_modules/tiny-http-mcp-server/LICENSE +21 -0
  97. package/node_modules/tiny-http-mcp-server/README.md +778 -0
  98. package/node_modules/tiny-http-mcp-server/dist/auth.d.ts +69 -0
  99. package/node_modules/tiny-http-mcp-server/dist/auth.js +261 -0
  100. package/node_modules/tiny-http-mcp-server/dist/cli.d.ts +20 -0
  101. package/node_modules/tiny-http-mcp-server/dist/cli.js +465 -0
  102. package/node_modules/tiny-http-mcp-server/dist/composition.json +30 -0
  103. package/node_modules/tiny-http-mcp-server/dist/express-middleware.d.ts +18 -0
  104. package/node_modules/tiny-http-mcp-server/dist/express-middleware.js +90 -0
  105. package/node_modules/tiny-http-mcp-server/dist/http-server.d.ts +49 -0
  106. package/node_modules/tiny-http-mcp-server/dist/http-server.js +264 -0
  107. package/node_modules/tiny-http-mcp-server/dist/http-transport.d.ts +164 -0
  108. package/node_modules/tiny-http-mcp-server/dist/http-transport.js +897 -0
  109. package/node_modules/tiny-http-mcp-server/dist/index.d.ts +13 -0
  110. package/node_modules/tiny-http-mcp-server/dist/index.js +6 -0
  111. package/node_modules/tiny-http-mcp-server/dist/load-oauth-verifier.d.ts +6 -0
  112. package/node_modules/tiny-http-mcp-server/dist/load-oauth-verifier.js +43 -0
  113. package/node_modules/tiny-http-mcp-server/dist/parse-body.d.ts +22 -0
  114. package/node_modules/tiny-http-mcp-server/dist/parse-body.js +150 -0
  115. package/node_modules/tiny-http-mcp-server/dist/server.d.ts +9 -0
  116. package/node_modules/tiny-http-mcp-server/dist/server.js +4 -0
  117. package/node_modules/tiny-http-mcp-server/dist/session.d.ts +18 -0
  118. package/node_modules/tiny-http-mcp-server/dist/session.js +37 -0
  119. package/node_modules/tiny-http-mcp-server/dist/sse.d.ts +11 -0
  120. package/node_modules/tiny-http-mcp-server/dist/sse.js +22 -0
  121. package/node_modules/tiny-http-mcp-server/dist/test-support.d.ts +10 -0
  122. package/node_modules/tiny-http-mcp-server/dist/test-support.js +398 -0
  123. package/node_modules/tiny-http-mcp-server/dist/testing.d.ts +59 -0
  124. package/node_modules/tiny-http-mcp-server/dist/testing.js +191 -0
  125. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/LICENSE +21 -0
  126. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/README.md +70 -0
  127. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/auth-store-session-store.d.ts +14 -0
  128. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/auth-store-session-store.js +169 -0
  129. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/authorization-state.d.ts +8 -0
  130. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/authorization-state.js +47 -0
  131. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.d.ts +3 -0
  132. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.js +627 -0
  133. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/loopback-authorization.d.ts +20 -0
  134. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/loopback-authorization.js +207 -0
  135. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/pkce.d.ts +2 -0
  136. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/pkce.js +7 -0
  137. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-endpoint.d.ts +40 -0
  138. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-endpoint.js +164 -0
  139. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/types.d.ts +113 -0
  140. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/types.js +1 -0
  141. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.d.ts +10 -0
  142. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.js +7 -0
  143. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/resource-indicator.d.ts +1 -0
  144. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/resource-indicator.js +11 -0
  145. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/server/jwks-token-verifier.d.ts +32 -0
  146. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/server/jwks-token-verifier.js +388 -0
  147. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/types.compile-check.d.ts +1 -0
  148. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/types.compile-check.js +22 -0
  149. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/package.json +28 -0
  150. package/node_modules/tiny-http-mcp-server/package.json +59 -0
  151. package/node_modules/tiny-stdio-mcp-server/dist/composition.json +1 -1
  152. package/node_modules/toolcraft-schema/package.json +1 -1
  153. 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
+ }
@@ -0,0 +1,8 @@
1
+ export declare function createAuthorizationState(input: {
2
+ issuer: string;
3
+ requireIssuer: boolean;
4
+ }): string;
5
+ export declare function parseAuthorizationState(value: string | null): {
6
+ issuer: string;
7
+ requireIssuer: boolean;
8
+ } | null;
@@ -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;