tiny-http-mcp-server 0.1.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/LICENSE +21 -0
- package/README.md +778 -0
- package/dist/auth.d.ts +69 -0
- package/dist/auth.js +261 -0
- package/dist/cli.d.ts +20 -0
- package/dist/cli.js +465 -0
- package/dist/composition.json +25 -0
- package/dist/express-middleware.d.ts +18 -0
- package/dist/express-middleware.js +91 -0
- package/dist/http-server.d.ts +48 -0
- package/dist/http-server.js +263 -0
- package/dist/http-transport.d.ts +164 -0
- package/dist/http-transport.js +897 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +6 -0
- package/dist/load-oauth-verifier.d.ts +6 -0
- package/dist/load-oauth-verifier.js +43 -0
- package/dist/parse-body.d.ts +22 -0
- package/dist/parse-body.js +150 -0
- package/dist/session.d.ts +18 -0
- package/dist/session.js +37 -0
- package/dist/sse.d.ts +11 -0
- package/dist/sse.js +22 -0
- package/dist/test-support.d.ts +10 -0
- package/dist/test-support.js +398 -0
- package/dist/testing.d.ts +59 -0
- package/dist/testing.js +191 -0
- package/node_modules/auth-store/LICENSE +21 -0
- package/node_modules/auth-store/README.md +62 -0
- package/node_modules/auth-store/dist/create-secret-store.d.ts +2 -0
- package/node_modules/auth-store/dist/create-secret-store.js +44 -0
- package/node_modules/auth-store/dist/encrypted-file-store.d.ts +47 -0
- package/node_modules/auth-store/dist/encrypted-file-store.js +303 -0
- package/node_modules/auth-store/dist/error-codes.d.ts +1 -0
- package/node_modules/auth-store/dist/error-codes.js +5 -0
- package/node_modules/auth-store/dist/index.d.ts +7 -0
- package/node_modules/auth-store/dist/index.js +4 -0
- package/node_modules/auth-store/dist/keychain-store.d.ts +25 -0
- package/node_modules/auth-store/dist/keychain-store.js +154 -0
- package/node_modules/auth-store/dist/provider-store.d.ts +14 -0
- package/node_modules/auth-store/dist/provider-store.js +78 -0
- package/node_modules/auth-store/dist/types.d.ts +22 -0
- package/node_modules/auth-store/dist/types.js +1 -0
- package/node_modules/auth-store/package.json +27 -0
- package/node_modules/mcp-oauth/LICENSE +21 -0
- package/node_modules/mcp-oauth/README.md +70 -0
- package/node_modules/mcp-oauth/dist/client/auth-store-session-store.d.ts +14 -0
- package/node_modules/mcp-oauth/dist/client/auth-store-session-store.js +169 -0
- package/node_modules/mcp-oauth/dist/client/authorization-state.d.ts +8 -0
- package/node_modules/mcp-oauth/dist/client/authorization-state.js +47 -0
- package/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.d.ts +3 -0
- package/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.js +627 -0
- package/node_modules/mcp-oauth/dist/client/loopback-authorization.d.ts +20 -0
- package/node_modules/mcp-oauth/dist/client/loopback-authorization.js +207 -0
- package/node_modules/mcp-oauth/dist/client/pkce.d.ts +2 -0
- package/node_modules/mcp-oauth/dist/client/pkce.js +7 -0
- package/node_modules/mcp-oauth/dist/client/token-endpoint.d.ts +40 -0
- package/node_modules/mcp-oauth/dist/client/token-endpoint.js +164 -0
- package/node_modules/mcp-oauth/dist/client/types.d.ts +113 -0
- package/node_modules/mcp-oauth/dist/client/types.js +1 -0
- package/node_modules/mcp-oauth/dist/index.d.ts +10 -0
- package/node_modules/mcp-oauth/dist/index.js +7 -0
- package/node_modules/mcp-oauth/dist/resource-indicator.d.ts +1 -0
- package/node_modules/mcp-oauth/dist/resource-indicator.js +11 -0
- package/node_modules/mcp-oauth/dist/server/jwks-token-verifier.d.ts +32 -0
- package/node_modules/mcp-oauth/dist/server/jwks-token-verifier.js +388 -0
- package/node_modules/mcp-oauth/dist/types.compile-check.d.ts +1 -0
- package/node_modules/mcp-oauth/dist/types.compile-check.js +22 -0
- package/node_modules/mcp-oauth/package.json +33 -0
- package/node_modules/tiny-mcp-client/LICENSE +21 -0
- package/node_modules/tiny-mcp-client/README.md +104 -0
- package/node_modules/tiny-mcp-client/dist/index.d.ts +660 -0
- package/node_modules/tiny-mcp-client/dist/index.js +3870 -0
- package/node_modules/tiny-mcp-client/package.json +30 -0
- package/package.json +63 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export function key(providerId) {
|
|
2
|
+
return `provider:${providerId}`;
|
|
3
|
+
}
|
|
4
|
+
export class MigratingSecretStore {
|
|
5
|
+
store;
|
|
6
|
+
legacyStore;
|
|
7
|
+
pendingMutation = Promise.resolve();
|
|
8
|
+
constructor(store, legacyStore = null) {
|
|
9
|
+
this.store = store;
|
|
10
|
+
this.legacyStore = legacyStore;
|
|
11
|
+
}
|
|
12
|
+
async get(options = {}) {
|
|
13
|
+
const value = await this.store.get();
|
|
14
|
+
if (value !== null || !this.legacyStore) {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
const legacyValue = await this.legacyStore.get();
|
|
18
|
+
if (legacyValue !== null && !options.readOnly) {
|
|
19
|
+
await this.mutate(async () => {
|
|
20
|
+
if (await this.store.get() === null) {
|
|
21
|
+
try {
|
|
22
|
+
await this.store.set(legacyValue);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return legacyValue;
|
|
31
|
+
}
|
|
32
|
+
async set(value) {
|
|
33
|
+
await this.mutate(async () => {
|
|
34
|
+
const previousValue = await this.store.get();
|
|
35
|
+
const previousLegacyValue = await this.legacyStore?.get() ?? null;
|
|
36
|
+
await this.store.set(value);
|
|
37
|
+
try {
|
|
38
|
+
await this.legacyStore?.set(value);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
await restore(this.store, previousValue);
|
|
42
|
+
if (this.legacyStore) {
|
|
43
|
+
await restore(this.legacyStore, previousLegacyValue);
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async delete() {
|
|
50
|
+
await this.mutate(async () => {
|
|
51
|
+
const previousValue = await this.store.get();
|
|
52
|
+
const previousLegacyValue = await this.legacyStore?.get() ?? null;
|
|
53
|
+
await this.store.delete();
|
|
54
|
+
try {
|
|
55
|
+
await this.legacyStore?.delete();
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
await restore(this.store, previousValue);
|
|
59
|
+
if (this.legacyStore) {
|
|
60
|
+
await restore(this.legacyStore, previousLegacyValue);
|
|
61
|
+
}
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async mutate(action) {
|
|
67
|
+
const operation = this.pendingMutation.then(action, action);
|
|
68
|
+
this.pendingMutation = operation.catch(() => undefined);
|
|
69
|
+
await operation;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async function restore(store, value) {
|
|
73
|
+
if (value === null) {
|
|
74
|
+
await store.delete();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
await store.set(value);
|
|
78
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { EncryptedFileStoreInput } from "./encrypted-file-store.js";
|
|
2
|
+
import type { KeychainStoreInput } from "./keychain-store.js";
|
|
3
|
+
export interface SecretStore {
|
|
4
|
+
get(options?: {
|
|
5
|
+
readOnly?: boolean;
|
|
6
|
+
}): Promise<string | null>;
|
|
7
|
+
set(value: string): Promise<void>;
|
|
8
|
+
delete(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export type StoreBackend = "file" | "keychain";
|
|
11
|
+
export interface CreateSecretStoreInput {
|
|
12
|
+
backend?: StoreBackend;
|
|
13
|
+
env?: NodeJS.ProcessEnv;
|
|
14
|
+
platform?: NodeJS.Platform;
|
|
15
|
+
backendEnvVar?: string;
|
|
16
|
+
fileStore?: EncryptedFileStoreInput;
|
|
17
|
+
keychainStore?: KeychainStoreInput;
|
|
18
|
+
}
|
|
19
|
+
export interface CreateSecretStoreResult {
|
|
20
|
+
store: SecretStore;
|
|
21
|
+
backend: StoreBackend;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "auth-store",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": true,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "node ../../scripts/guard-package-dist.mjs && tsc"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/poe-platform/poe-code.git",
|
|
25
|
+
"directory": "packages/auth-store"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Poe Platform
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -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,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;
|