@zgeoff/mcp-auth 0.0.0-stage → 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 +76 -2
- package/dist/admin/build-admin.d.ts +4 -0
- package/dist/admin/build-client-admin.d.ts +4 -0
- package/dist/admin/build-grant-admin.d.ts +3 -0
- package/dist/admin/build-passkey-admin.d.ts +3 -0
- package/dist/admin/check-redirect-uris.d.ts +1 -0
- package/dist/admin/create-enrollment-token.d.ts +2 -0
- package/dist/admin/read-client-name.d.ts +1 -0
- package/dist/admin/read-sign-in-grants.d.ts +3 -0
- package/dist/admin/remove-expired.d.ts +2 -0
- package/dist/admin/to-client-view.d.ts +3 -0
- package/dist/default-paths.d.ts +18 -0
- package/dist/elysia/create-mcp-http-app.d.ts +17 -0
- package/dist/elysia/find-bearer-token.d.ts +1 -0
- package/dist/elysia/index.d.ts +2 -0
- package/dist/elysia/is-beside-prefix.d.ts +1 -0
- package/dist/grants/collect-granted-scopes.d.ts +7 -0
- package/dist/grants/read-access-payload.d.ts +9 -0
- package/dist/grants/read-client-scopes.d.ts +2 -0
- package/dist/grants/verify-oauth-access.d.ts +13 -0
- package/dist/index.d.ts +7 -0
- package/dist/mcp-auth-error.d.ts +5 -0
- package/dist/open-mcp-auth-admin.d.ts +2 -0
- package/dist/open-mcp-auth.d.ts +2 -0
- package/dist/passkeys/answer-enroll-request.d.ts +3 -0
- package/dist/passkeys/create-enrollment-state.d.ts +6 -0
- package/dist/passkeys/create-passkey.d.ts +10 -0
- package/dist/passkeys/passkey-script.d.ts +4 -0
- package/dist/passkeys/read-enrollment-token.d.ts +2 -0
- package/dist/passkeys/read-passkey-rows.d.ts +13 -0
- package/dist/passkeys/render-enroll-page.d.ts +11 -0
- package/dist/passkeys/render-login-page.d.ts +11 -0
- package/dist/passkeys/update-passkey-use.d.ts +9 -0
- package/dist/passkeys/verify-passkey-assertion.d.ts +10 -0
- package/dist/passkeys/verify-passkey-registration.d.ts +15 -0
- package/dist/passkeys/verify-session-passkey.d.ts +8 -0
- package/dist/routes/build-routes.d.ts +3 -0
- package/dist/routes/with-form-origin.d.ts +4 -0
- package/dist/service-tokens/build-service-token-verifier.d.ts +13 -0
- package/dist/service-tokens/parse-service-token-file.d.ts +7 -0
- package/dist/sign-in/answer-authorize-request.d.ts +3 -0
- package/dist/sign-in/answer-consent-request.d.ts +3 -0
- package/dist/sign-in/answer-login-request.d.ts +3 -0
- package/dist/sign-in/build-consent-binding.d.ts +1 -0
- package/dist/sign-in/create-sign-in-state.d.ts +43 -0
- package/dist/sign-in/pick-consent-choice.d.ts +8 -0
- package/dist/sign-in/pick-consent-outcome.d.ts +4 -0
- package/dist/sign-in/read-session-id.d.ts +2 -0
- package/dist/sign-in/read-stored-client-name.d.ts +3 -0
- package/dist/sign-in/read-url-field.d.ts +1 -0
- package/dist/sign-in/render-consent-page.d.ts +11 -0
- package/dist/sign-in/route-context.d.ts +17 -0
- package/dist/sign-in/verify-oauth-query.d.ts +1 -0
- package/dist/store/check-cascade-keys.d.ts +2 -0
- package/dist/store/check-foreign-keys.d.ts +2 -0
- package/dist/store/check-table-names.d.ts +2 -0
- package/dist/store/check-user-columns.d.ts +2 -0
- package/dist/store/create-auth-server.d.ts +103 -0
- package/dist/store/create-grant-plugin.d.ts +28 -0
- package/dist/store/create-owned-tables.d.ts +3 -0
- package/dist/store/open-store.d.ts +15 -0
- package/dist/store/read-table-columns.d.ts +2 -0
- package/dist/store/remove-grant-rows.d.ts +3 -0
- package/dist/store/store-schema.d.ts +63 -0
- package/dist/test-utils/authorize-test-client.d.ts +12 -0
- package/dist/test-utils/build-form-request.d.ts +1 -0
- package/dist/test-utils/build-seeder.d.ts +13 -0
- package/dist/test-utils/build-stub-authenticator.d.ts +49 -0
- package/dist/test-utils/build-stub-clock.d.ts +5 -0
- package/dist/test-utils/build-test-requester.d.ts +2 -0
- package/dist/test-utils/create-test-database.d.ts +2 -0
- package/dist/test-utils/hook-sqlite-statements.d.ts +2 -0
- package/dist/test-utils/index.d.ts +12 -0
- package/dist/test-utils/open-test-auth.d.ts +21 -0
- package/dist/test-utils/parse-passkey-page.d.ts +21 -0
- package/dist/test-utils/read-json-record.d.ts +5 -0
- package/dist/test-utils/run-sign-in-to-consent.d.ts +13 -0
- package/dist/test-utils/seed-client.d.ts +7 -0
- package/dist/test-utils/seed-enrollment-token.d.ts +2 -0
- package/dist/test-utils/seed-passkey.d.ts +7 -0
- package/dist/tokens/answer-error-request.d.ts +2 -0
- package/dist/tokens/answer-metadata-request.d.ts +2 -0
- package/dist/tokens/answer-revoke-request.d.ts +2 -0
- package/dist/tokens/answer-token-request.d.ts +3 -0
- package/dist/tokens/build-better-auth-request.d.ts +6 -0
- package/dist/tokens/build-oauth-error.d.ts +1 -0
- package/dist/tokens/read-error-code.d.ts +1 -0
- package/dist/tokens/read-error-description.d.ts +1 -0
- package/dist/tokens/record-token-exchange.d.ts +10 -0
- package/dist/tokens/remove-token-sessions.d.ts +2 -0
- package/dist/types.d.ts +185 -0
- package/dist/utils/build-page-response.d.ts +5 -0
- package/dist/utils/derive-token-hash.d.ts +1 -0
- package/dist/utils/is-allowed-redirect-uri.d.ts +1 -0
- package/dist/utils/is-loopback-host.d.ts +1 -0
- package/dist/utils/normalize-client-name.d.ts +1 -0
- package/dist/utils/parse-approved-by.d.ts +2 -0
- package/dist/utils/parse-json-strings.d.ts +1 -0
- package/dist/utils/read-body-text.d.ts +1 -0
- package/dist/utils/read-form.d.ts +2 -0
- package/dist/utils/to-html-text.d.ts +1 -0
- package/dist/utils/to-script-json.d.ts +1 -0
- package/package.json +73 -4
- package/src/admin/build-admin.ts +22 -0
- package/src/admin/build-client-admin.ts +112 -0
- package/src/admin/build-grant-admin.ts +62 -0
- package/src/admin/build-passkey-admin.ts +53 -0
- package/src/admin/check-redirect-uris.ts +17 -0
- package/src/admin/create-enrollment-token.ts +18 -0
- package/src/admin/read-client-name.ts +13 -0
- package/src/admin/read-sign-in-grants.ts +22 -0
- package/src/admin/remove-expired.ts +47 -0
- package/src/admin/to-client-view.ts +12 -0
- package/src/default-paths.ts +21 -0
- package/src/elysia/create-mcp-http-app.ts +218 -0
- package/src/elysia/find-bearer-token.ts +6 -0
- package/src/elysia/index.ts +2 -0
- package/src/elysia/is-beside-prefix.ts +7 -0
- package/src/grants/collect-granted-scopes.ts +19 -0
- package/src/grants/read-access-payload.ts +37 -0
- package/src/grants/read-client-scopes.ts +36 -0
- package/src/grants/verify-oauth-access.ts +113 -0
- package/src/index.ts +7 -0
- package/src/mcp-auth-error.ts +17 -0
- package/src/open-mcp-auth-admin.ts +14 -0
- package/src/open-mcp-auth.ts +89 -0
- package/src/passkeys/answer-enroll-request.ts +179 -0
- package/src/passkeys/create-enrollment-state.ts +54 -0
- package/src/passkeys/create-passkey.ts +39 -0
- package/src/passkeys/passkey-script.ts +48 -0
- package/src/passkeys/read-enrollment-token.ts +21 -0
- package/src/passkeys/read-passkey-rows.ts +30 -0
- package/src/passkeys/render-enroll-page.ts +58 -0
- package/src/passkeys/render-login-page.ts +59 -0
- package/src/passkeys/update-passkey-use.ts +24 -0
- package/src/passkeys/verify-passkey-assertion.ts +120 -0
- package/src/passkeys/verify-passkey-registration.ts +116 -0
- package/src/passkeys/verify-session-passkey.ts +42 -0
- package/src/routes/build-routes.ts +31 -0
- package/src/routes/with-form-origin.ts +18 -0
- package/src/service-tokens/build-service-token-verifier.ts +56 -0
- package/src/service-tokens/parse-service-token-file.ts +104 -0
- package/src/sign-in/answer-authorize-request.ts +133 -0
- package/src/sign-in/answer-consent-request.ts +220 -0
- package/src/sign-in/answer-login-request.ts +243 -0
- package/src/sign-in/build-consent-binding.ts +11 -0
- package/src/sign-in/create-sign-in-state.ts +229 -0
- package/src/sign-in/pick-consent-choice.ts +27 -0
- package/src/sign-in/pick-consent-outcome.ts +14 -0
- package/src/sign-in/read-session-id.ts +11 -0
- package/src/sign-in/read-stored-client-name.ts +15 -0
- package/src/sign-in/read-url-field.ts +12 -0
- package/src/sign-in/render-consent-page.ts +57 -0
- package/src/sign-in/route-context.ts +25 -0
- package/src/sign-in/verify-oauth-query.ts +39 -0
- package/src/store/check-cascade-keys.ts +36 -0
- package/src/store/check-foreign-keys.ts +20 -0
- package/src/store/check-table-names.ts +13 -0
- package/src/store/check-user-columns.ts +22 -0
- package/src/store/create-auth-server.ts +97 -0
- package/src/store/create-grant-plugin.ts +68 -0
- package/src/store/create-owned-tables.ts +45 -0
- package/src/store/open-store.ts +72 -0
- package/src/store/read-table-columns.ts +12 -0
- package/src/store/remove-grant-rows.ts +27 -0
- package/src/store/store-schema.ts +61 -0
- package/src/test-utils/authorize-test-client.ts +93 -0
- package/src/test-utils/build-form-request.ts +12 -0
- package/src/test-utils/build-seeder.ts +19 -0
- package/src/test-utils/build-stub-authenticator.ts +244 -0
- package/src/test-utils/build-stub-clock.ts +21 -0
- package/src/test-utils/build-test-requester.ts +5 -0
- package/src/test-utils/create-test-database.ts +7 -0
- package/src/test-utils/hook-sqlite-statements.ts +17 -0
- package/src/test-utils/index.ts +12 -0
- package/src/test-utils/open-test-auth.ts +72 -0
- package/src/test-utils/parse-passkey-page.ts +25 -0
- package/src/test-utils/read-json-record.ts +15 -0
- package/src/test-utils/run-sign-in-to-consent.ts +100 -0
- package/src/test-utils/seed-client.ts +16 -0
- package/src/test-utils/seed-enrollment-token.ts +5 -0
- package/src/test-utils/seed-passkey.ts +51 -0
- package/src/tokens/answer-error-request.ts +26 -0
- package/src/tokens/answer-metadata-request.ts +51 -0
- package/src/tokens/answer-revoke-request.ts +47 -0
- package/src/tokens/answer-token-request.ts +133 -0
- package/src/tokens/build-better-auth-request.ts +23 -0
- package/src/tokens/build-oauth-error.ts +7 -0
- package/src/tokens/read-error-code.ts +12 -0
- package/src/tokens/read-error-description.ts +11 -0
- package/src/tokens/record-token-exchange.ts +73 -0
- package/src/tokens/remove-token-sessions.ts +32 -0
- package/src/types.ts +247 -0
- package/src/utils/build-page-response.ts +24 -0
- package/src/utils/derive-token-hash.ts +5 -0
- package/src/utils/is-allowed-redirect-uri.ts +17 -0
- package/src/utils/is-loopback-host.ts +8 -0
- package/src/utils/normalize-client-name.ts +20 -0
- package/src/utils/parse-approved-by.ts +9 -0
- package/src/utils/parse-json-strings.ts +13 -0
- package/src/utils/read-body-text.ts +23 -0
- package/src/utils/read-form.ts +16 -0
- package/src/utils/to-html-text.ts +8 -0
- package/src/utils/to-script-json.ts +6 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { BetterAuthPlugin } from 'better-auth';
|
|
2
|
+
import type { Kysely } from 'kysely';
|
|
3
|
+
import type { MCPAuthPaths } from '../types.ts';
|
|
4
|
+
import type { StoreSchema } from './store-schema.ts';
|
|
5
|
+
export declare const ACCESS_TOKEN_SECONDS: number;
|
|
6
|
+
export declare const REFRESH_TOKEN_SECONDS: number;
|
|
7
|
+
export declare const CODE_SECONDS: number;
|
|
8
|
+
export declare const SESSION_SECONDS: number;
|
|
9
|
+
interface AuthServerOptions {
|
|
10
|
+
readonly db: Kysely<StoreSchema>;
|
|
11
|
+
readonly origin: string | null;
|
|
12
|
+
readonly paths: MCPAuthPaths;
|
|
13
|
+
readonly scopes: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
export declare function createAuthServer(options: AuthServerOptions): import("better-auth").Auth<{
|
|
16
|
+
baseURL: string;
|
|
17
|
+
basePath: string;
|
|
18
|
+
secret: string;
|
|
19
|
+
database: {
|
|
20
|
+
db: Kysely<StoreSchema>;
|
|
21
|
+
type: "sqlite";
|
|
22
|
+
};
|
|
23
|
+
telemetry: {
|
|
24
|
+
enabled: false;
|
|
25
|
+
};
|
|
26
|
+
logger: {
|
|
27
|
+
disabled: true;
|
|
28
|
+
};
|
|
29
|
+
rateLimit: {
|
|
30
|
+
enabled: false;
|
|
31
|
+
};
|
|
32
|
+
advanced: {
|
|
33
|
+
database: {
|
|
34
|
+
validateSchema: false;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
trustedOrigins: string[];
|
|
38
|
+
onAPIError: {
|
|
39
|
+
errorURL: string;
|
|
40
|
+
};
|
|
41
|
+
session: {
|
|
42
|
+
expiresIn: number;
|
|
43
|
+
disableSessionRefresh: true;
|
|
44
|
+
};
|
|
45
|
+
user: {
|
|
46
|
+
additionalFields: {
|
|
47
|
+
clientId: {
|
|
48
|
+
type: "string";
|
|
49
|
+
required: true;
|
|
50
|
+
input: false;
|
|
51
|
+
};
|
|
52
|
+
scopes: {
|
|
53
|
+
type: "string";
|
|
54
|
+
required: false;
|
|
55
|
+
input: false;
|
|
56
|
+
};
|
|
57
|
+
approvedBy: {
|
|
58
|
+
type: "string";
|
|
59
|
+
required: true;
|
|
60
|
+
input: false;
|
|
61
|
+
};
|
|
62
|
+
limits: {
|
|
63
|
+
type: "string";
|
|
64
|
+
required: false;
|
|
65
|
+
input: false;
|
|
66
|
+
};
|
|
67
|
+
lastUsedAt: {
|
|
68
|
+
type: "date";
|
|
69
|
+
required: false;
|
|
70
|
+
input: false;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
plugins: [BetterAuthPlugin, {
|
|
75
|
+
id: "mcp-auth-grant";
|
|
76
|
+
endpoints: {
|
|
77
|
+
signInGrant: import("better-auth").StrictEndpoint<"/mcp-auth/sign-in-grant", {
|
|
78
|
+
method: "POST";
|
|
79
|
+
body: import("zod").ZodObject<{
|
|
80
|
+
oauth_query: import("zod").ZodOptional<import("zod").ZodString>;
|
|
81
|
+
clientID: import("zod").ZodString;
|
|
82
|
+
clientName: import("zod").ZodString;
|
|
83
|
+
}, import("zod/v4/core").$strip>;
|
|
84
|
+
metadata: {
|
|
85
|
+
SERVER_ONLY: true;
|
|
86
|
+
};
|
|
87
|
+
}, {
|
|
88
|
+
signedIn: boolean;
|
|
89
|
+
}>;
|
|
90
|
+
verifyAccessToken: import("better-auth").StrictEndpoint<"/mcp-auth/verify-access-token", {
|
|
91
|
+
method: "POST";
|
|
92
|
+
body: import("zod").ZodObject<{
|
|
93
|
+
token: import("zod").ZodString;
|
|
94
|
+
}, import("zod/v4/core").$strip>;
|
|
95
|
+
metadata: {
|
|
96
|
+
SERVER_ONLY: true;
|
|
97
|
+
};
|
|
98
|
+
}, import("@better-auth/oauth-provider").ActiveAccessTokenPayload>;
|
|
99
|
+
};
|
|
100
|
+
}];
|
|
101
|
+
}>;
|
|
102
|
+
export type AuthServer = ReturnType<typeof createAuthServer>;
|
|
103
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare function createGrantPlugin(): {
|
|
3
|
+
id: "mcp-auth-grant";
|
|
4
|
+
endpoints: {
|
|
5
|
+
signInGrant: import("better-auth").StrictEndpoint<"/mcp-auth/sign-in-grant", {
|
|
6
|
+
method: "POST";
|
|
7
|
+
body: z.ZodObject<{
|
|
8
|
+
oauth_query: z.ZodOptional<z.ZodString>;
|
|
9
|
+
clientID: z.ZodString;
|
|
10
|
+
clientName: z.ZodString;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
metadata: {
|
|
13
|
+
SERVER_ONLY: true;
|
|
14
|
+
};
|
|
15
|
+
}, {
|
|
16
|
+
signedIn: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
verifyAccessToken: import("better-auth").StrictEndpoint<"/mcp-auth/verify-access-token", {
|
|
19
|
+
method: "POST";
|
|
20
|
+
body: z.ZodObject<{
|
|
21
|
+
token: z.ZodString;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
metadata: {
|
|
24
|
+
SERVER_ONLY: true;
|
|
25
|
+
};
|
|
26
|
+
}, import("@better-auth/oauth-provider").ActiveAccessTokenPayload>;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Kysely } from 'kysely';
|
|
2
|
+
import type { MCPAuthAdminOptions, MCPAuthPaths } from '../types.ts';
|
|
3
|
+
import type { AuthServer } from './create-auth-server.ts';
|
|
4
|
+
import type { StoreSchema } from './store-schema.ts';
|
|
5
|
+
export interface Store {
|
|
6
|
+
readonly db: Kysely<StoreSchema>;
|
|
7
|
+
readonly auth: AuthServer;
|
|
8
|
+
readonly options: MCPAuthAdminOptions<string>;
|
|
9
|
+
}
|
|
10
|
+
interface StoreOptions {
|
|
11
|
+
readonly origin: string | null;
|
|
12
|
+
readonly paths: MCPAuthPaths;
|
|
13
|
+
}
|
|
14
|
+
export declare function openStore(admin: MCPAuthAdminOptions<string>, options: StoreOptions): Promise<Store>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { GrantID, OAuthClientID } from '../types.ts';
|
|
2
|
+
export interface StoreSchema {
|
|
3
|
+
readonly user: {
|
|
4
|
+
readonly id: GrantID;
|
|
5
|
+
readonly email: string;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly emailVerified: number;
|
|
8
|
+
readonly createdAt: string;
|
|
9
|
+
readonly updatedAt: string;
|
|
10
|
+
readonly clientId: OAuthClientID;
|
|
11
|
+
readonly scopes: string | null;
|
|
12
|
+
readonly approvedBy: string;
|
|
13
|
+
readonly limits: string | null;
|
|
14
|
+
readonly lastUsedAt: string | null;
|
|
15
|
+
};
|
|
16
|
+
readonly session: {
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly expiresAt: string;
|
|
19
|
+
readonly userId: GrantID;
|
|
20
|
+
};
|
|
21
|
+
readonly verification: {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly expiresAt: string;
|
|
24
|
+
};
|
|
25
|
+
readonly oauthClient: {
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly clientId: OAuthClientID;
|
|
28
|
+
readonly name: string | null;
|
|
29
|
+
readonly redirectUris: string;
|
|
30
|
+
readonly scopes: string;
|
|
31
|
+
readonly clientCredentialsScopes: string;
|
|
32
|
+
readonly tokenEndpointAuthMethod: string;
|
|
33
|
+
readonly grantTypes: string;
|
|
34
|
+
readonly responseTypes: string;
|
|
35
|
+
readonly applicationType: string;
|
|
36
|
+
readonly requirePKCE: number;
|
|
37
|
+
readonly disabled: number;
|
|
38
|
+
readonly createdAt: string | null;
|
|
39
|
+
readonly updatedAt: string | null;
|
|
40
|
+
};
|
|
41
|
+
readonly oauthAccessToken: {
|
|
42
|
+
readonly id: string;
|
|
43
|
+
readonly token: string;
|
|
44
|
+
readonly clientId: OAuthClientID;
|
|
45
|
+
readonly sessionId: string | null;
|
|
46
|
+
readonly userId: GrantID | null;
|
|
47
|
+
readonly expiresAt: string;
|
|
48
|
+
};
|
|
49
|
+
readonly oauthRefreshToken: {
|
|
50
|
+
readonly id: string;
|
|
51
|
+
readonly token: string;
|
|
52
|
+
readonly clientId: OAuthClientID;
|
|
53
|
+
readonly sessionId: string | null;
|
|
54
|
+
readonly userId: GrantID;
|
|
55
|
+
readonly expiresAt: string;
|
|
56
|
+
readonly createdAt: string;
|
|
57
|
+
readonly revoked: string | null;
|
|
58
|
+
readonly rotatedAt: string | null;
|
|
59
|
+
};
|
|
60
|
+
readonly oauthResource: {
|
|
61
|
+
readonly identifier: string;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { GrantID, MCPAuth, OAuthClientID } from '../types.ts';
|
|
2
|
+
export interface TestClientInput {
|
|
3
|
+
readonly scopes: readonly string[];
|
|
4
|
+
readonly consentFields?: URLSearchParams;
|
|
5
|
+
}
|
|
6
|
+
export interface TestClientAuthorization {
|
|
7
|
+
readonly accessToken: string;
|
|
8
|
+
readonly refreshToken: string;
|
|
9
|
+
readonly grantID: GrantID;
|
|
10
|
+
readonly clientID: OAuthClientID;
|
|
11
|
+
}
|
|
12
|
+
export declare function authorizeTestClient(auth: MCPAuth<string, unknown>, input: TestClientInput): Promise<TestClientAuthorization>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function buildFormRequest(url: string, fields: URLSearchParams, headers?: Readonly<Record<string, string>>): Request;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MCPAuth } from '../types.ts';
|
|
2
|
+
import { authorizeTestClient } from './authorize-test-client.ts';
|
|
3
|
+
import { seedClient } from './seed-client.ts';
|
|
4
|
+
import { seedPasskey } from './seed-passkey.ts';
|
|
5
|
+
export interface TestDeps {
|
|
6
|
+
readonly auth: MCPAuth<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export declare function buildSeeder(deps: TestDeps): {
|
|
9
|
+
client: (input?: Parameters<typeof seedClient>[1]) => Promise<import("../types.ts").ClientView>;
|
|
10
|
+
enrollmentToken: () => Promise<string>;
|
|
11
|
+
passkey: (input: Parameters<typeof seedPasskey>[1]) => Promise<void>;
|
|
12
|
+
grant: (input: Parameters<typeof authorizeTestClient>[1]) => Promise<import("./authorize-test-client.ts").TestClientAuthorization>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { PasskeyID } from '../types.ts';
|
|
2
|
+
interface CreationOptions {
|
|
3
|
+
readonly challenge: string;
|
|
4
|
+
readonly rp: {
|
|
5
|
+
readonly id?: string;
|
|
6
|
+
};
|
|
7
|
+
readonly user: {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
interface RequestOptions {
|
|
12
|
+
readonly challenge: string;
|
|
13
|
+
readonly rpId?: string;
|
|
14
|
+
}
|
|
15
|
+
interface Ceremony {
|
|
16
|
+
readonly origin: string;
|
|
17
|
+
readonly rpID?: string;
|
|
18
|
+
readonly userVerified?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface StubRegistration {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly rawId: string;
|
|
23
|
+
readonly type: 'public-key';
|
|
24
|
+
readonly response: {
|
|
25
|
+
readonly clientDataJSON: string;
|
|
26
|
+
readonly attestationObject: string;
|
|
27
|
+
readonly transports: readonly string[];
|
|
28
|
+
};
|
|
29
|
+
readonly clientExtensionResults: Readonly<Record<string, never>>;
|
|
30
|
+
readonly authenticatorAttachment: 'platform';
|
|
31
|
+
}
|
|
32
|
+
export interface StubAssertion {
|
|
33
|
+
readonly id: string;
|
|
34
|
+
readonly rawId: string;
|
|
35
|
+
readonly type: 'public-key';
|
|
36
|
+
readonly response: {
|
|
37
|
+
readonly clientDataJSON: string;
|
|
38
|
+
readonly authenticatorData: string;
|
|
39
|
+
readonly signature: string;
|
|
40
|
+
readonly userHandle: string;
|
|
41
|
+
};
|
|
42
|
+
readonly clientExtensionResults: Readonly<Record<string, never>>;
|
|
43
|
+
}
|
|
44
|
+
export declare function buildStubAuthenticator(): {
|
|
45
|
+
credentialID: PasskeyID;
|
|
46
|
+
create(options: CreationOptions, ceremony: Ceremony): Promise<StubRegistration>;
|
|
47
|
+
signAssertion(options: RequestOptions, ceremony: Ceremony): Promise<StubAssertion>;
|
|
48
|
+
};
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { authorizeTestClient } from './authorize-test-client.ts';
|
|
2
|
+
export { buildSeeder } from './build-seeder.ts';
|
|
3
|
+
export type { TestDeps } from './build-seeder.ts';
|
|
4
|
+
export { buildStubAuthenticator } from './build-stub-authenticator.ts';
|
|
5
|
+
export { buildStubClock } from './build-stub-clock.ts';
|
|
6
|
+
export { buildTestRequester } from './build-test-requester.ts';
|
|
7
|
+
export { createTestDatabase } from './create-test-database.ts';
|
|
8
|
+
export { hookSQLiteStatements } from './hook-sqlite-statements.ts';
|
|
9
|
+
export { openTestAuth } from './open-test-auth.ts';
|
|
10
|
+
export { seedClient } from './seed-client.ts';
|
|
11
|
+
export { seedEnrollmentToken } from './seed-enrollment-token.ts';
|
|
12
|
+
export { seedPasskey } from './seed-passkey.ts';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Database } from 'bun:sqlite';
|
|
2
|
+
import type { GrantID, GrantLimits, MCPAuth, SecurityEvent, ServiceTokenFile } from '../types.ts';
|
|
3
|
+
import { buildStubClock } from './build-stub-clock.ts';
|
|
4
|
+
interface TestAuthInput<Limits> {
|
|
5
|
+
readonly database?: Database;
|
|
6
|
+
readonly grantLimits?: GrantLimits<Limits>;
|
|
7
|
+
readonly serviceTokens?: {
|
|
8
|
+
readonly prefix: string;
|
|
9
|
+
readonly file: ServiceTokenFile<'read' | 'write'>;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
interface TestAuth<Limits> {
|
|
13
|
+
readonly auth: MCPAuth<'read' | 'write', Limits>;
|
|
14
|
+
readonly database: Database;
|
|
15
|
+
readonly clock: ReturnType<typeof buildStubClock>;
|
|
16
|
+
readonly events: SecurityEvent[];
|
|
17
|
+
readonly revoked: GrantID[];
|
|
18
|
+
readonly close: () => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare function openTestAuth<Limits = null>(input?: TestAuthInput<Limits>): Promise<TestAuth<Limits>>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
declare const PASSKEY_PAGE: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
3
|
+
mode: z.ZodLiteral<"get">;
|
|
4
|
+
options: z.ZodObject<{
|
|
5
|
+
challenge: z.ZodString;
|
|
6
|
+
rpId: z.ZodString;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
9
|
+
mode: z.ZodLiteral<"create">;
|
|
10
|
+
options: z.ZodObject<{
|
|
11
|
+
challenge: z.ZodString;
|
|
12
|
+
rp: z.ZodObject<{
|
|
13
|
+
id: z.ZodString;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
user: z.ZodObject<{
|
|
16
|
+
id: z.ZodString;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
}, z.core.$strip>], "mode">;
|
|
20
|
+
export declare function parsePasskeyPage(html: string): z.infer<typeof PASSKEY_PAGE>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MCPAuth, OAuthClientID } from '../types.ts';
|
|
2
|
+
export declare const TEST_REDIRECT_URI = "https://client.example/callback";
|
|
3
|
+
interface SignInInput {
|
|
4
|
+
readonly scopes: readonly string[];
|
|
5
|
+
}
|
|
6
|
+
export interface SignInAtConsent {
|
|
7
|
+
readonly clientID: OAuthClientID;
|
|
8
|
+
readonly verifier: string;
|
|
9
|
+
readonly consent: URL;
|
|
10
|
+
readonly cookie: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function runSignInToConsent(auth: MCPAuth<string, unknown>, input: SignInInput): Promise<SignInAtConsent>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ClientView, MCPAuthAdmin } from '../types.ts';
|
|
2
|
+
interface ClientInput {
|
|
3
|
+
readonly name?: string;
|
|
4
|
+
readonly redirectURIs?: readonly string[];
|
|
5
|
+
}
|
|
6
|
+
export declare function seedClient(admin: Pick<MCPAuthAdmin, 'clients'>, input?: ClientInput): Promise<ClientView>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MCPAuth } from '../types.ts';
|
|
2
|
+
import type { buildStubAuthenticator } from './build-stub-authenticator.ts';
|
|
3
|
+
interface PasskeyInput {
|
|
4
|
+
readonly authenticator: Pick<ReturnType<typeof buildStubAuthenticator>, 'create'>;
|
|
5
|
+
}
|
|
6
|
+
export declare function seedPasskey(auth: Pick<MCPAuth<string, unknown>, 'issuer' | 'paths' | 'routes' | 'passkeys'>, input: PasskeyInput): Promise<void>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function buildOAuthError(status: number, error: string, description: string): Response;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function readErrorCode(response: Response): Promise<string | null>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function readErrorDescription(answer: unknown): string | null;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RouteContext } from '../sign-in/route-context.ts';
|
|
2
|
+
import type { Requester } from '../types.ts';
|
|
3
|
+
interface TokenExchange {
|
|
4
|
+
readonly form: Readonly<URLSearchParams>;
|
|
5
|
+
readonly response: Response;
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly requester: Requester;
|
|
8
|
+
}
|
|
9
|
+
export declare function recordTokenExchange(ctx: RouteContext, exchange: TokenExchange): Promise<void>;
|
|
10
|
+
export {};
|