@zgeoff/mcp-auth 0.0.0-stage → 0.0.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.
Files changed (197) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +55 -2
  3. package/dist/admin/build-admin.d.ts +4 -0
  4. package/dist/admin/build-client-admin.d.ts +4 -0
  5. package/dist/admin/build-grant-admin.d.ts +3 -0
  6. package/dist/admin/build-passkey-admin.d.ts +3 -0
  7. package/dist/admin/check-redirect-uris.d.ts +1 -0
  8. package/dist/admin/create-enrollment-token.d.ts +2 -0
  9. package/dist/admin/read-client-name.d.ts +1 -0
  10. package/dist/admin/read-sign-in-grants.d.ts +3 -0
  11. package/dist/admin/remove-expired.d.ts +2 -0
  12. package/dist/admin/to-client-view.d.ts +3 -0
  13. package/dist/default-paths.d.ts +18 -0
  14. package/dist/grants/collect-granted-scopes.d.ts +7 -0
  15. package/dist/grants/read-access-payload.d.ts +9 -0
  16. package/dist/grants/read-client-scopes.d.ts +2 -0
  17. package/dist/grants/verify-oauth-access.d.ts +13 -0
  18. package/dist/index.d.ts +7 -0
  19. package/dist/mcp-auth-error.d.ts +5 -0
  20. package/dist/open-mcp-auth-admin.d.ts +2 -0
  21. package/dist/open-mcp-auth.d.ts +2 -0
  22. package/dist/passkeys/answer-enroll-request.d.ts +3 -0
  23. package/dist/passkeys/create-enrollment-state.d.ts +6 -0
  24. package/dist/passkeys/create-passkey.d.ts +10 -0
  25. package/dist/passkeys/passkey-script.d.ts +4 -0
  26. package/dist/passkeys/read-enrollment-token.d.ts +2 -0
  27. package/dist/passkeys/read-passkey-rows.d.ts +13 -0
  28. package/dist/passkeys/render-enroll-page.d.ts +11 -0
  29. package/dist/passkeys/render-login-page.d.ts +11 -0
  30. package/dist/passkeys/update-passkey-use.d.ts +9 -0
  31. package/dist/passkeys/verify-passkey-assertion.d.ts +10 -0
  32. package/dist/passkeys/verify-passkey-registration.d.ts +15 -0
  33. package/dist/passkeys/verify-session-passkey.d.ts +8 -0
  34. package/dist/routes/build-routes.d.ts +3 -0
  35. package/dist/routes/with-form-origin.d.ts +4 -0
  36. package/dist/service-tokens/build-service-token-verifier.d.ts +13 -0
  37. package/dist/service-tokens/parse-service-token-file.d.ts +7 -0
  38. package/dist/sign-in/answer-authorize-request.d.ts +3 -0
  39. package/dist/sign-in/answer-consent-request.d.ts +3 -0
  40. package/dist/sign-in/answer-login-request.d.ts +3 -0
  41. package/dist/sign-in/build-consent-binding.d.ts +1 -0
  42. package/dist/sign-in/create-sign-in-state.d.ts +43 -0
  43. package/dist/sign-in/pick-consent-choice.d.ts +8 -0
  44. package/dist/sign-in/pick-consent-outcome.d.ts +4 -0
  45. package/dist/sign-in/read-session-id.d.ts +2 -0
  46. package/dist/sign-in/read-stored-client-name.d.ts +3 -0
  47. package/dist/sign-in/read-url-field.d.ts +1 -0
  48. package/dist/sign-in/render-consent-page.d.ts +11 -0
  49. package/dist/sign-in/route-context.d.ts +17 -0
  50. package/dist/sign-in/verify-oauth-query.d.ts +1 -0
  51. package/dist/store/check-cascade-keys.d.ts +2 -0
  52. package/dist/store/check-foreign-keys.d.ts +2 -0
  53. package/dist/store/check-table-names.d.ts +2 -0
  54. package/dist/store/check-user-columns.d.ts +2 -0
  55. package/dist/store/create-auth-server.d.ts +103 -0
  56. package/dist/store/create-grant-plugin.d.ts +28 -0
  57. package/dist/store/create-owned-tables.d.ts +3 -0
  58. package/dist/store/open-store.d.ts +15 -0
  59. package/dist/store/read-table-columns.d.ts +2 -0
  60. package/dist/store/remove-grant-rows.d.ts +3 -0
  61. package/dist/store/store-schema.d.ts +63 -0
  62. package/dist/test-utils/authorize-test-client.d.ts +12 -0
  63. package/dist/test-utils/build-form-request.d.ts +1 -0
  64. package/dist/test-utils/build-seeder.d.ts +13 -0
  65. package/dist/test-utils/build-stub-authenticator.d.ts +49 -0
  66. package/dist/test-utils/build-stub-clock.d.ts +5 -0
  67. package/dist/test-utils/build-test-requester.d.ts +2 -0
  68. package/dist/test-utils/create-test-database.d.ts +2 -0
  69. package/dist/test-utils/hook-sqlite-statements.d.ts +2 -0
  70. package/dist/test-utils/index.d.ts +12 -0
  71. package/dist/test-utils/open-test-auth.d.ts +21 -0
  72. package/dist/test-utils/parse-passkey-page.d.ts +21 -0
  73. package/dist/test-utils/read-json-record.d.ts +5 -0
  74. package/dist/test-utils/run-sign-in-to-consent.d.ts +13 -0
  75. package/dist/test-utils/seed-client.d.ts +7 -0
  76. package/dist/test-utils/seed-enrollment-token.d.ts +2 -0
  77. package/dist/test-utils/seed-passkey.d.ts +7 -0
  78. package/dist/tokens/answer-error-request.d.ts +2 -0
  79. package/dist/tokens/answer-metadata-request.d.ts +2 -0
  80. package/dist/tokens/answer-revoke-request.d.ts +2 -0
  81. package/dist/tokens/answer-token-request.d.ts +3 -0
  82. package/dist/tokens/build-better-auth-request.d.ts +6 -0
  83. package/dist/tokens/build-oauth-error.d.ts +1 -0
  84. package/dist/tokens/read-error-code.d.ts +1 -0
  85. package/dist/tokens/read-error-description.d.ts +1 -0
  86. package/dist/tokens/record-token-exchange.d.ts +10 -0
  87. package/dist/tokens/remove-token-sessions.d.ts +2 -0
  88. package/dist/types.d.ts +185 -0
  89. package/dist/utils/build-page-response.d.ts +5 -0
  90. package/dist/utils/derive-token-hash.d.ts +1 -0
  91. package/dist/utils/is-allowed-redirect-uri.d.ts +1 -0
  92. package/dist/utils/is-loopback-host.d.ts +1 -0
  93. package/dist/utils/normalize-client-name.d.ts +1 -0
  94. package/dist/utils/parse-approved-by.d.ts +2 -0
  95. package/dist/utils/parse-json-strings.d.ts +1 -0
  96. package/dist/utils/read-body-text.d.ts +1 -0
  97. package/dist/utils/read-form.d.ts +2 -0
  98. package/dist/utils/to-html-text.d.ts +1 -0
  99. package/dist/utils/to-script-json.d.ts +1 -0
  100. package/package.json +62 -4
  101. package/src/admin/build-admin.ts +22 -0
  102. package/src/admin/build-client-admin.ts +112 -0
  103. package/src/admin/build-grant-admin.ts +62 -0
  104. package/src/admin/build-passkey-admin.ts +53 -0
  105. package/src/admin/check-redirect-uris.ts +17 -0
  106. package/src/admin/create-enrollment-token.ts +18 -0
  107. package/src/admin/read-client-name.ts +13 -0
  108. package/src/admin/read-sign-in-grants.ts +22 -0
  109. package/src/admin/remove-expired.ts +47 -0
  110. package/src/admin/to-client-view.ts +12 -0
  111. package/src/default-paths.ts +21 -0
  112. package/src/grants/collect-granted-scopes.ts +19 -0
  113. package/src/grants/read-access-payload.ts +37 -0
  114. package/src/grants/read-client-scopes.ts +36 -0
  115. package/src/grants/verify-oauth-access.ts +113 -0
  116. package/src/index.ts +7 -0
  117. package/src/mcp-auth-error.ts +17 -0
  118. package/src/open-mcp-auth-admin.ts +14 -0
  119. package/src/open-mcp-auth.ts +89 -0
  120. package/src/passkeys/answer-enroll-request.ts +179 -0
  121. package/src/passkeys/create-enrollment-state.ts +54 -0
  122. package/src/passkeys/create-passkey.ts +39 -0
  123. package/src/passkeys/passkey-script.ts +48 -0
  124. package/src/passkeys/read-enrollment-token.ts +21 -0
  125. package/src/passkeys/read-passkey-rows.ts +30 -0
  126. package/src/passkeys/render-enroll-page.ts +58 -0
  127. package/src/passkeys/render-login-page.ts +59 -0
  128. package/src/passkeys/update-passkey-use.ts +24 -0
  129. package/src/passkeys/verify-passkey-assertion.ts +120 -0
  130. package/src/passkeys/verify-passkey-registration.ts +116 -0
  131. package/src/passkeys/verify-session-passkey.ts +42 -0
  132. package/src/routes/build-routes.ts +31 -0
  133. package/src/routes/with-form-origin.ts +18 -0
  134. package/src/service-tokens/build-service-token-verifier.ts +56 -0
  135. package/src/service-tokens/parse-service-token-file.ts +104 -0
  136. package/src/sign-in/answer-authorize-request.ts +133 -0
  137. package/src/sign-in/answer-consent-request.ts +220 -0
  138. package/src/sign-in/answer-login-request.ts +243 -0
  139. package/src/sign-in/build-consent-binding.ts +11 -0
  140. package/src/sign-in/create-sign-in-state.ts +229 -0
  141. package/src/sign-in/pick-consent-choice.ts +27 -0
  142. package/src/sign-in/pick-consent-outcome.ts +14 -0
  143. package/src/sign-in/read-session-id.ts +11 -0
  144. package/src/sign-in/read-stored-client-name.ts +15 -0
  145. package/src/sign-in/read-url-field.ts +12 -0
  146. package/src/sign-in/render-consent-page.ts +57 -0
  147. package/src/sign-in/route-context.ts +25 -0
  148. package/src/sign-in/verify-oauth-query.ts +39 -0
  149. package/src/store/check-cascade-keys.ts +36 -0
  150. package/src/store/check-foreign-keys.ts +20 -0
  151. package/src/store/check-table-names.ts +13 -0
  152. package/src/store/check-user-columns.ts +22 -0
  153. package/src/store/create-auth-server.ts +97 -0
  154. package/src/store/create-grant-plugin.ts +68 -0
  155. package/src/store/create-owned-tables.ts +45 -0
  156. package/src/store/open-store.ts +72 -0
  157. package/src/store/read-table-columns.ts +12 -0
  158. package/src/store/remove-grant-rows.ts +27 -0
  159. package/src/store/store-schema.ts +61 -0
  160. package/src/test-utils/authorize-test-client.ts +93 -0
  161. package/src/test-utils/build-form-request.ts +12 -0
  162. package/src/test-utils/build-seeder.ts +19 -0
  163. package/src/test-utils/build-stub-authenticator.ts +244 -0
  164. package/src/test-utils/build-stub-clock.ts +21 -0
  165. package/src/test-utils/build-test-requester.ts +5 -0
  166. package/src/test-utils/create-test-database.ts +7 -0
  167. package/src/test-utils/hook-sqlite-statements.ts +17 -0
  168. package/src/test-utils/index.ts +12 -0
  169. package/src/test-utils/open-test-auth.ts +72 -0
  170. package/src/test-utils/parse-passkey-page.ts +25 -0
  171. package/src/test-utils/read-json-record.ts +15 -0
  172. package/src/test-utils/run-sign-in-to-consent.ts +100 -0
  173. package/src/test-utils/seed-client.ts +16 -0
  174. package/src/test-utils/seed-enrollment-token.ts +5 -0
  175. package/src/test-utils/seed-passkey.ts +51 -0
  176. package/src/tokens/answer-error-request.ts +26 -0
  177. package/src/tokens/answer-metadata-request.ts +51 -0
  178. package/src/tokens/answer-revoke-request.ts +47 -0
  179. package/src/tokens/answer-token-request.ts +133 -0
  180. package/src/tokens/build-better-auth-request.ts +23 -0
  181. package/src/tokens/build-oauth-error.ts +7 -0
  182. package/src/tokens/read-error-code.ts +12 -0
  183. package/src/tokens/read-error-description.ts +11 -0
  184. package/src/tokens/record-token-exchange.ts +73 -0
  185. package/src/tokens/remove-token-sessions.ts +32 -0
  186. package/src/types.ts +247 -0
  187. package/src/utils/build-page-response.ts +24 -0
  188. package/src/utils/derive-token-hash.ts +5 -0
  189. package/src/utils/is-allowed-redirect-uri.ts +17 -0
  190. package/src/utils/is-loopback-host.ts +8 -0
  191. package/src/utils/normalize-client-name.ts +20 -0
  192. package/src/utils/parse-approved-by.ts +9 -0
  193. package/src/utils/parse-json-strings.ts +13 -0
  194. package/src/utils/read-body-text.ts +23 -0
  195. package/src/utils/read-form.ts +16 -0
  196. package/src/utils/to-html-text.ts +8 -0
  197. package/src/utils/to-script-json.ts +6 -0
@@ -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,3 @@
1
+ import type { Database } from 'bun:sqlite';
2
+ import type { MCPAuthTables } from '../types.ts';
3
+ export declare function createOwnedTables(sqlite: Database, tables: MCPAuthTables): void;
@@ -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,2 @@
1
+ import type { Database } from 'bun:sqlite';
2
+ export declare function readTableColumns(sqlite: Database, table: string): string[];
@@ -0,0 +1,3 @@
1
+ import type { GrantID } from '../types.ts';
2
+ import type { Store } from './open-store.ts';
3
+ export declare function removeGrantRows(store: Store, grantIDs: readonly GrantID[]): Promise<GrantID[]>;
@@ -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,5 @@
1
+ import type { Clock } from '../types.ts';
2
+ export declare function buildStubClock(startMs?: number): Clock & {
3
+ readonly setTime: (timeMs: number) => void;
4
+ readonly advance: (durationMs: number) => void;
5
+ };
@@ -0,0 +1,2 @@
1
+ import type { Requester } from '../types.ts';
2
+ export declare function buildTestRequester(overrides?: Partial<Requester>): Requester;
@@ -0,0 +1,2 @@
1
+ import { Database } from 'bun:sqlite';
2
+ export declare function createTestDatabase(path?: string): Database;
@@ -0,0 +1,2 @@
1
+ import type { Database } from 'bun:sqlite';
2
+ export declare function hookSQLiteStatements(sqlite: Database, onStatement: (statement: string) => void): void;
@@ -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,5 @@
1
+ interface JSONBody {
2
+ readonly json: () => Promise<unknown>;
3
+ }
4
+ export declare function readJSONRecord(response: JSONBody): Promise<Record<string, unknown>>;
5
+ 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,2 @@
1
+ import type { MCPAuthAdmin } from '../types.ts';
2
+ export declare function seedEnrollmentToken(admin: Pick<MCPAuthAdmin, 'passkeys'>): Promise<string>;
@@ -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,2 @@
1
+ import type { RouteContext } from '../sign-in/route-context.ts';
2
+ export declare function answerErrorRequest(ctx: RouteContext, request: Request): Response;
@@ -0,0 +1,2 @@
1
+ import type { RouteContext } from '../sign-in/route-context.ts';
2
+ export declare function answerMetadataRequest(ctx: RouteContext, kind: 'authorization-server' | 'resource'): Promise<Response>;
@@ -0,0 +1,2 @@
1
+ import type { RouteContext } from '../sign-in/route-context.ts';
2
+ export declare function answerRevokeRequest(ctx: RouteContext, request: Request): Promise<Response>;
@@ -0,0 +1,3 @@
1
+ import type { RouteContext } from '../sign-in/route-context.ts';
2
+ import type { Requester } from '../types.ts';
3
+ export declare function answerTokenRequest(ctx: RouteContext, request: Request, requester: Requester): Promise<Response>;
@@ -0,0 +1,6 @@
1
+ interface BetterAuthTarget {
2
+ readonly path: string;
3
+ readonly body: string | null;
4
+ }
5
+ export declare function buildBetterAuthRequest(origin: string, request: Request, target: BetterAuthTarget): Request;
6
+ 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 {};
@@ -0,0 +1,2 @@
1
+ import type { Store } from '../store/open-store.ts';
2
+ export declare function removeTokenSessions(store: Store): Promise<void>;
@@ -0,0 +1,185 @@
1
+ import type { Database } from 'bun:sqlite';
2
+ import type { Tagged } from 'type-fest';
3
+ export type GrantID = Tagged<string, 'GrantID'>;
4
+ export type OAuthClientID = Tagged<string, 'OAuthClientID'>;
5
+ export type PasskeyID = Tagged<string, 'PasskeyID'>;
6
+ export type CorrelationID = Tagged<string, 'CorrelationID'>;
7
+ export type ApprovedBy = 'passkey' | `token:${string}`;
8
+ export interface MCPAuthPaths {
9
+ readonly browser: {
10
+ readonly authorize: string;
11
+ readonly login: string;
12
+ readonly enroll: string;
13
+ readonly consent: string;
14
+ readonly error: string;
15
+ };
16
+ readonly machine: {
17
+ readonly mcp: string;
18
+ readonly root: string;
19
+ readonly token: string;
20
+ readonly revoke: string;
21
+ readonly authorizationServerMetadata: string;
22
+ readonly resourceMetadata: string;
23
+ readonly mcpResourceMetadata: string;
24
+ };
25
+ }
26
+ export interface MCPAuthTables {
27
+ readonly passkey: string;
28
+ readonly enrollmentToken: string;
29
+ }
30
+ export interface Clock {
31
+ readonly now: () => number;
32
+ }
33
+ export interface Requester {
34
+ readonly socketAddress: string | null;
35
+ readonly connectingIP: {
36
+ readonly address: string;
37
+ readonly provenance: 'trusted' | 'unverified';
38
+ } | null;
39
+ readonly userAgent: string | null;
40
+ }
41
+ export interface SecurityEvent {
42
+ readonly kind: 'authorize_started' | 'authorize_invalid' | 'owner_auth' | 'consent' | 'token_exchange' | 'bearer' | 'bad_host' | 'bad_origin';
43
+ readonly outcome: 'accepted' | 'rejected' | 'succeeded' | 'failed' | 'allowed' | 'denied';
44
+ readonly reason?: string;
45
+ readonly path: string;
46
+ readonly requester: Requester;
47
+ readonly client?: {
48
+ readonly id: OAuthClientID;
49
+ readonly name: string;
50
+ };
51
+ readonly correlationID?: CorrelationID;
52
+ }
53
+ export interface SecuritySink {
54
+ readonly record: (event: SecurityEvent) => void;
55
+ }
56
+ export interface MCPAuthAdminOptions<Scope extends string> {
57
+ readonly database: Database;
58
+ readonly scopes: readonly Scope[];
59
+ readonly tables: MCPAuthTables;
60
+ readonly clock: Clock;
61
+ readonly onGrantRevoked: (grantID: GrantID) => void;
62
+ }
63
+ export interface ServiceClient<Scope extends string> {
64
+ readonly name: string;
65
+ readonly scopes: readonly Scope[];
66
+ readonly tokens: readonly string[];
67
+ }
68
+ export interface ServiceTokenFile<Scope extends string> {
69
+ readonly resource: string;
70
+ readonly clients: readonly ServiceClient<Scope>[];
71
+ }
72
+ export type ParsedServiceTokenFile<Scope extends string> = {
73
+ readonly ok: true;
74
+ readonly file: ServiceTokenFile<Scope>;
75
+ } | {
76
+ readonly ok: false;
77
+ readonly reason: string;
78
+ };
79
+ export interface MCPAuthOptions<Scope extends string, Limits> extends MCPAuthAdminOptions<Scope> {
80
+ readonly origin: string;
81
+ readonly productName: string;
82
+ readonly paths: MCPAuthPaths;
83
+ readonly serviceTokens?: {
84
+ readonly prefix: string;
85
+ readonly file: ServiceTokenFile<Scope>;
86
+ };
87
+ readonly grantLimits?: GrantLimits<Limits>;
88
+ readonly security: SecuritySink;
89
+ }
90
+ export interface ClientView {
91
+ readonly clientID: OAuthClientID;
92
+ readonly name: string;
93
+ readonly redirectURIs: readonly string[];
94
+ readonly createdAt: string;
95
+ }
96
+ export interface GrantView {
97
+ readonly grantID: GrantID;
98
+ readonly clientID: OAuthClientID;
99
+ readonly clientName: string;
100
+ readonly scopes: readonly string[];
101
+ readonly approvedBy: ApprovedBy;
102
+ readonly createdAt: string;
103
+ readonly lastUsedAt: string | null;
104
+ }
105
+ export interface PasskeyView {
106
+ readonly id: PasskeyID;
107
+ readonly createdAt: string;
108
+ readonly lastUsedAt: string | null;
109
+ }
110
+ export interface MCPAuthAdmin {
111
+ readonly clients: {
112
+ readonly list: () => Promise<ClientView[]>;
113
+ readonly add: (name: string, redirectURIs: readonly string[]) => Promise<ClientView>;
114
+ readonly update: (name: string, redirectURIs: readonly string[]) => Promise<ClientView>;
115
+ readonly remove: (name: string) => Promise<number>;
116
+ };
117
+ readonly grants: {
118
+ readonly list: () => Promise<GrantView[]>;
119
+ readonly revoke: (grantID: GrantID) => Promise<boolean>;
120
+ };
121
+ readonly passkeys: {
122
+ readonly createEnrollmentToken: () => Promise<string>;
123
+ readonly list: () => Promise<PasskeyView[]>;
124
+ readonly remove: (id: PasskeyID) => Promise<void>;
125
+ readonly reset: () => Promise<void>;
126
+ };
127
+ readonly removeExpired: () => Promise<void>;
128
+ readonly close: () => Promise<void>;
129
+ }
130
+ export type MCPAuthRouteName = 'authorize' | 'login' | 'enroll' | 'consent' | 'error' | 'token' | 'revoke' | 'authorizationServerMetadata' | 'resourceMetadata';
131
+ export type MCPAuthRoutes = Record<MCPAuthRouteName, (request: Request, requester: Requester) => Promise<Response>>;
132
+ export type Access<Scope extends string, Limits> = {
133
+ readonly kind: 'oauth';
134
+ readonly grantID: GrantID;
135
+ readonly clientID: OAuthClientID;
136
+ readonly clientName: string;
137
+ readonly scopes: readonly Scope[];
138
+ readonly limits: Limits | null;
139
+ } | {
140
+ readonly kind: 'service';
141
+ readonly clientID: `service:${string}`;
142
+ readonly clientName: `service:${string}`;
143
+ readonly scopes: readonly Scope[];
144
+ };
145
+ export interface MCPAuth<Scope extends string, Limits = null> extends MCPAuthAdmin {
146
+ readonly resource: string;
147
+ readonly issuer: string;
148
+ readonly paths: MCPAuthPaths;
149
+ readonly routes: MCPAuthRoutes;
150
+ readonly verify: (bearer: string) => Promise<Access<Scope, Limits> | null>;
151
+ readonly findClientScopes: (clientID: string) => Promise<readonly Scope[] | null>;
152
+ }
153
+ export interface ConsentRequest {
154
+ readonly clientID: OAuthClientID;
155
+ readonly clientName: string;
156
+ readonly scopes: readonly string[];
157
+ }
158
+ export interface StoredGrant<Limits> {
159
+ readonly grantID: GrantID;
160
+ readonly clientID: OAuthClientID;
161
+ readonly scopes: readonly string[];
162
+ readonly approvedBy: ApprovedBy;
163
+ readonly limits: Limits | null;
164
+ readonly createdAt: number;
165
+ readonly lastUsedAt: number | null;
166
+ }
167
+ export type GrantCheck = {
168
+ readonly kind: 'allow';
169
+ readonly scopes: readonly string[];
170
+ } | {
171
+ readonly kind: 'revoke';
172
+ readonly reason: string;
173
+ };
174
+ export interface GrantLimits<Limits> {
175
+ readonly renderConsentFields: (request: ConsentRequest) => string;
176
+ readonly parseConsentFields: (form: URLSearchParams) => {
177
+ ok: true;
178
+ limits: Limits;
179
+ } | {
180
+ ok: false;
181
+ error: string;
182
+ };
183
+ readonly parseStored: (json: unknown) => Limits | null;
184
+ readonly check: (grant: StoredGrant<Limits>) => Promise<GrantCheck>;
185
+ }
@@ -0,0 +1,5 @@
1
+ export declare function buildPageResponse(status: number, body: {
2
+ readonly page: string;
3
+ } | {
4
+ readonly message: string;
5
+ }, formTargets?: readonly string[], scriptSources?: readonly string[]): Response;
@@ -0,0 +1 @@
1
+ export declare function deriveTokenHash(token: string): string;
@@ -0,0 +1 @@
1
+ export declare function isAllowedRedirectURI(raw: string): boolean;
@@ -0,0 +1 @@
1
+ export declare function isLoopbackHost(host: string): boolean;
@@ -0,0 +1 @@
1
+ export declare function normalizeClientName(raw: unknown, fallback?: string, maxLength?: number): string;
@@ -0,0 +1,2 @@
1
+ import type { ApprovedBy } from '../types.ts';
2
+ export declare function parseApprovedBy(text: string): ApprovedBy | null;
@@ -0,0 +1 @@
1
+ export declare function parseJSONStrings(raw: string): string[] | null;
@@ -0,0 +1 @@
1
+ export declare function readBodyText(request: Request, maxBytes: number): Promise<string | null>;
@@ -0,0 +1,2 @@
1
+ export declare const MAX_FORM_BYTES: number;
2
+ export declare function readForm(request: Request): Promise<URLSearchParams>;
@@ -0,0 +1 @@
1
+ export declare function toHTMLText(text: string): string;
@@ -0,0 +1 @@
1
+ export declare function toScriptJSON(value: unknown): string;