@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.
- package/LICENSE +21 -0
- package/README.md +55 -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/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 +62 -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/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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 zgeoff
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,56 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zgeoff/mcp-auth
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An OAuth server that lets a hosted MCP client, such as a Claude.ai connector, reach an app's `/mcp`
|
|
4
|
+
route. It is built on better-auth and `bun:sqlite`, and holds the OAuth routes and pages, passkey
|
|
5
|
+
login for the owner, pre-registered clients, service tokens and grant revoke. Each app passes in its
|
|
6
|
+
own scopes, paths, table names and grant limits.
|
|
7
|
+
|
|
8
|
+
The package exports the core from `@zgeoff/mcp-auth` and the test helpers from
|
|
9
|
+
`@zgeoff/mcp-auth/testing`. The package needs Bun.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
bun add @zgeoff/mcp-auth kysely
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Kysely is a peer dependency.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
The app opens the server once at start, on a `bun:sqlite` connection that it owns. Each route is a
|
|
22
|
+
function from `Request` to `Response`, and `verify` turns a bearer token into an `Access` or `null`.
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { DEFAULT_PATHS, openMCPAuth } from '@zgeoff/mcp-auth';
|
|
26
|
+
|
|
27
|
+
const auth = await openMCPAuth({
|
|
28
|
+
database: sqlite,
|
|
29
|
+
origin: 'https://app.example.com',
|
|
30
|
+
productName: 'app',
|
|
31
|
+
scopes: ['read', 'write'],
|
|
32
|
+
paths: DEFAULT_PATHS,
|
|
33
|
+
tables: { passkey: 'app_passkey', enrollmentToken: 'app_enrollment_token' },
|
|
34
|
+
clock: { now: () => Date.now() },
|
|
35
|
+
security: { record: (event) => console.log(event) },
|
|
36
|
+
onGrantRevoked: (grantID) => closeStreamsOf(grantID),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const access = await auth.verify(bearerToken);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
A command that only manages clients, grants and passkeys calls `openMCPAuthAdmin`, with no origin.
|
|
43
|
+
|
|
44
|
+
## Features
|
|
45
|
+
|
|
46
|
+
- OAuth authorization code flow with PKCE for clients the owner adds by name.
|
|
47
|
+
- Passkey login and consent pages, with the scopes the owner ticks.
|
|
48
|
+
- Refresh tokens that rotate, and a grant that ends when a client replays a replaced token.
|
|
49
|
+
- A revoke that ends every token of a grant with one delete, even in the middle of a refresh.
|
|
50
|
+
- Bearer tokens only: the token route drops DPoP, and `verify` refuses a token bound to a key.
|
|
51
|
+
- Service tokens for clients that cannot run the browser flow.
|
|
52
|
+
- Test helpers: `openTestAuth`, `authorizeTestClient`, and seeds for clients and passkeys.
|
|
53
|
+
|
|
54
|
+
## Documentation
|
|
55
|
+
|
|
56
|
+
The [design](../../docs/design/mcp-auth/README.md) holds the contracts and constraints.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SignInState } from '../sign-in/create-sign-in-state.ts';
|
|
2
|
+
import type { Store } from '../store/open-store.ts';
|
|
3
|
+
import type { MCPAuthAdmin } from '../types.ts';
|
|
4
|
+
export declare function buildAdmin(store: Store, signIns: Pick<SignInState, 'removeClient'> | null): MCPAuthAdmin;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SignInState } from '../sign-in/create-sign-in-state.ts';
|
|
2
|
+
import type { Store } from '../store/open-store.ts';
|
|
3
|
+
import type { MCPAuthAdmin } from '../types.ts';
|
|
4
|
+
export declare function buildClientAdmin(store: Store, signIns: Pick<SignInState, 'removeClient'> | null): MCPAuthAdmin['clients'];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkRedirectURIs(redirectURIs: readonly string[]): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function readClientName(raw: string): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const DEFAULT_PATHS: {
|
|
2
|
+
readonly browser: {
|
|
3
|
+
readonly authorize: '/oauth2/authorize';
|
|
4
|
+
readonly login: '/login';
|
|
5
|
+
readonly enroll: '/enroll';
|
|
6
|
+
readonly consent: '/consent';
|
|
7
|
+
readonly error: '/error';
|
|
8
|
+
};
|
|
9
|
+
readonly machine: {
|
|
10
|
+
readonly mcp: '/mcp';
|
|
11
|
+
readonly root: '/';
|
|
12
|
+
readonly token: '/oauth2/token';
|
|
13
|
+
readonly revoke: '/oauth2/revoke';
|
|
14
|
+
readonly authorizationServerMetadata: '/.well-known/oauth-authorization-server';
|
|
15
|
+
readonly resourceMetadata: '/.well-known/oauth-protected-resource';
|
|
16
|
+
readonly mcpResourceMetadata: '/.well-known/oauth-protected-resource/mcp';
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface HeldScopes {
|
|
2
|
+
readonly grant: readonly string[];
|
|
3
|
+
readonly token: readonly string[];
|
|
4
|
+
readonly allowed: readonly string[] | null;
|
|
5
|
+
}
|
|
6
|
+
export declare function collectGrantedScopes<Scope extends string>(known: readonly Scope[], held: HeldScopes): Scope[];
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { GrantID, OAuthClientID } from '../types.ts';
|
|
2
|
+
interface AccessPayload {
|
|
3
|
+
readonly grantID: GrantID;
|
|
4
|
+
readonly clientID: OAuthClientID;
|
|
5
|
+
readonly audiences: readonly string[];
|
|
6
|
+
readonly scopes: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
export declare function readAccessPayload(payload: unknown): AccessPayload | null;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Store } from '../store/open-store.ts';
|
|
2
|
+
import type { Access, GrantLimits } from '../types.ts';
|
|
3
|
+
interface OAuthVerification<Scope extends string, Limits> {
|
|
4
|
+
readonly store: Store;
|
|
5
|
+
readonly resource: string;
|
|
6
|
+
readonly scopes: readonly Scope[];
|
|
7
|
+
readonly grantLimits: GrantLimits<Limits> | null;
|
|
8
|
+
}
|
|
9
|
+
type OAuthAccess<Scope extends string, Limits> = Extract<Access<Scope, Limits>, {
|
|
10
|
+
kind: 'oauth';
|
|
11
|
+
}>;
|
|
12
|
+
export declare function verifyOAuthAccess<Scope extends string, Limits>(deps: OAuthVerification<Scope, Limits>, bearer: string): Promise<OAuthAccess<Scope, Limits> | null>;
|
|
13
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { DEFAULT_PATHS } from './default-paths.ts';
|
|
2
|
+
export { MCPAuthError } from './mcp-auth-error.ts';
|
|
3
|
+
export type { MCPAuthErrorCode } from './mcp-auth-error.ts';
|
|
4
|
+
export { openMCPAuth } from './open-mcp-auth.ts';
|
|
5
|
+
export { openMCPAuthAdmin } from './open-mcp-auth-admin.ts';
|
|
6
|
+
export { parseServiceTokenFile } from './service-tokens/parse-service-token-file.ts';
|
|
7
|
+
export type * from './types.ts';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TakenChallenge } from '../sign-in/create-sign-in-state.ts';
|
|
2
|
+
export interface EnrollmentState {
|
|
3
|
+
readonly mintChallenge: (tokenHash: string) => string;
|
|
4
|
+
readonly claimChallenge: (tokenHash: string) => TakenChallenge;
|
|
5
|
+
}
|
|
6
|
+
export declare function createEnrollmentState(now: () => number): EnrollmentState;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Store } from '../store/open-store.ts';
|
|
2
|
+
import type { PasskeyID } from '../types.ts';
|
|
3
|
+
export interface NewPasskey {
|
|
4
|
+
readonly tokenHash: string;
|
|
5
|
+
readonly id: PasskeyID;
|
|
6
|
+
readonly publicKey: string;
|
|
7
|
+
readonly counter: number;
|
|
8
|
+
readonly transports: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function createPasskey(store: Store, passkey: NewPasskey): Promise<boolean>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const PASSKEY_SCRIPT: {
|
|
2
|
+
readonly source: "(() => {\n const data = document.getElementById('mcp-auth-passkey');\n const form = document.getElementById('mcp-auth-passkey-form');\n const button = document.getElementById('mcp-auth-passkey-start');\n const status = document.getElementById('mcp-auth-passkey-status');\n if (data === null || form === null || button === null || status === null) return;\n const spec = JSON.parse(data.textContent);\n const toBytes = (value) => {\n const base64 = value.replace(/-/g, '+').replace(/_/g, '/');\n const padded = base64 + '='.repeat((4 - (base64.length % 4)) % 4);\n return Uint8Array.from(atob(padded), (c) => c.charCodeAt(0));\n };\n const toText = (buffer) => {\n let text = '';\n for (const byte of new Uint8Array(buffer)) text += String.fromCharCode(byte);\n return btoa(text).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '');\n };\n const toDescriptors = (list) => (list || []).map((item) => ({ ...item, id: toBytes(item.id) }));\n button.addEventListener('click', async () => {\n button.disabled = true;\n status.textContent = '';\n try {\n const options = spec.options;\n const credential = spec.mode === 'create'\n ? await navigator.credentials.create({ publicKey: { ...options, challenge: toBytes(options.challenge), user: { ...options.user, id: toBytes(options.user.id) }, excludeCredentials: toDescriptors(options.excludeCredentials) } })\n : await navigator.credentials.get({ publicKey: { ...options, challenge: toBytes(options.challenge), allowCredentials: toDescriptors(options.allowCredentials) } });\n const reply = credential.response;\n const response = spec.mode === 'create'\n ? { clientDataJSON: toText(reply.clientDataJSON), attestationObject: toText(reply.attestationObject), transports: typeof reply.getTransports === 'function' ? reply.getTransports() : [] }\n : { clientDataJSON: toText(reply.clientDataJSON), authenticatorData: toText(reply.authenticatorData), signature: toText(reply.signature), userHandle: reply.userHandle ? toText(reply.userHandle) : undefined };\n form.elements.namedItem('credential').value = JSON.stringify({ id: credential.id, rawId: toText(credential.rawId), type: credential.type, response, clientExtensionResults: credential.getClientExtensionResults(), authenticatorAttachment: credential.authenticatorAttachment || undefined });\n form.submit();\n } catch (error) {\n status.textContent = 'The passkey prompt ended without a passkey (' + (error && error.name ? error.name : 'Error') + '). Try again.';\n button.disabled = false;\n }\n });\n})();";
|
|
3
|
+
readonly policySource: `'sha256-${string}'`;
|
|
4
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { StoreSchema } from '../store/store-schema.ts';
|
|
4
|
+
declare const PasskeyRowsSchema: z.ZodArray<z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
public_key: z.ZodString;
|
|
7
|
+
counter: z.ZodNumber;
|
|
8
|
+
transports: z.ZodString;
|
|
9
|
+
created_at: z.ZodString;
|
|
10
|
+
last_used_at: z.ZodNullable<z.ZodString>;
|
|
11
|
+
}, z.core.$strip>>;
|
|
12
|
+
export declare function readPasskeyRows(executor: Kysely<StoreSchema>, table: string, id: string | null): Promise<z.infer<typeof PasskeyRowsSchema>>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface EnrollPageView {
|
|
2
|
+
readonly productName: string;
|
|
3
|
+
readonly enrollPath: string;
|
|
4
|
+
readonly ceremony: {
|
|
5
|
+
readonly token: string;
|
|
6
|
+
readonly options: unknown;
|
|
7
|
+
} | null;
|
|
8
|
+
readonly error: string | null;
|
|
9
|
+
}
|
|
10
|
+
export declare function renderEnrollPage(view: EnrollPageView): string;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface LoginPageView {
|
|
2
|
+
readonly productName: string;
|
|
3
|
+
readonly loginPath: string;
|
|
4
|
+
readonly oauthQuery: string;
|
|
5
|
+
readonly clientName: string;
|
|
6
|
+
readonly redirectURI: string;
|
|
7
|
+
readonly options: unknown;
|
|
8
|
+
readonly error: string | null;
|
|
9
|
+
}
|
|
10
|
+
export declare function renderLoginPage(view: LoginPageView): string;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Store } from '../store/open-store.ts';
|
|
2
|
+
import type { PasskeyID } from '../types.ts';
|
|
3
|
+
interface PasskeyUse {
|
|
4
|
+
readonly id: PasskeyID;
|
|
5
|
+
readonly counter: number;
|
|
6
|
+
readonly newCounter: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function updatePasskeyUse(store: Store, use: PasskeyUse): Promise<boolean>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Store } from '../store/open-store.ts';
|
|
2
|
+
import type { PasskeyID } from '../types.ts';
|
|
3
|
+
interface AssertionCheck {
|
|
4
|
+
readonly credential: string;
|
|
5
|
+
readonly challenge: string;
|
|
6
|
+
readonly origin: string;
|
|
7
|
+
readonly rpID: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function verifyPasskeyAssertion(store: Store, check: AssertionCheck): Promise<PasskeyID | null>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PasskeyID } from '../types.ts';
|
|
2
|
+
interface RegistrationCheck {
|
|
3
|
+
readonly credential: string;
|
|
4
|
+
readonly challenge: string;
|
|
5
|
+
readonly origin: string;
|
|
6
|
+
readonly rpID: string;
|
|
7
|
+
}
|
|
8
|
+
export interface RegisteredPasskey {
|
|
9
|
+
readonly id: PasskeyID;
|
|
10
|
+
readonly publicKey: Uint8Array;
|
|
11
|
+
readonly counter: number;
|
|
12
|
+
readonly transports: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
export declare function verifyPasskeyRegistration(check: RegistrationCheck): Promise<RegisteredPasskey | null>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Store } from '../store/open-store.ts';
|
|
2
|
+
import type { PasskeyID } from '../types.ts';
|
|
3
|
+
interface SessionPasskey {
|
|
4
|
+
readonly sessionID: string;
|
|
5
|
+
readonly passkeyID: PasskeyID;
|
|
6
|
+
}
|
|
7
|
+
export declare function verifySessionPasskey(store: Store, check: SessionPasskey): Promise<boolean>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Access, ServiceTokenFile } from '../types.ts';
|
|
2
|
+
interface StoredToken<Scope extends string> {
|
|
3
|
+
readonly digest: Buffer;
|
|
4
|
+
readonly access: Extract<Access<Scope, never>, {
|
|
5
|
+
kind: 'service';
|
|
6
|
+
}>;
|
|
7
|
+
}
|
|
8
|
+
export interface ServiceTokenVerifier<Scope extends string> {
|
|
9
|
+
readonly verify: (token: string) => StoredToken<Scope>['access'] | null;
|
|
10
|
+
readonly findScopes: (clientID: string) => readonly Scope[] | null;
|
|
11
|
+
}
|
|
12
|
+
export declare function buildServiceTokenVerifier<Scope extends string>(file: ServiceTokenFile<Scope>): ServiceTokenVerifier<Scope>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ParsedServiceTokenFile } from '../types.ts';
|
|
2
|
+
interface ServiceTokenRules<Scope extends string> {
|
|
3
|
+
readonly prefix: string;
|
|
4
|
+
readonly scopes: readonly Scope[];
|
|
5
|
+
}
|
|
6
|
+
export declare function parseServiceTokenFile<Scope extends string>(text: string, rules: ServiceTokenRules<Scope>): ParsedServiceTokenFile<Scope>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function buildConsentBinding(oauthQuery: string): string;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { CorrelationID, OAuthClientID } from '../types.ts';
|
|
2
|
+
interface SignInRequest {
|
|
3
|
+
readonly key: string;
|
|
4
|
+
readonly clientID: OAuthClientID;
|
|
5
|
+
readonly clientName: string;
|
|
6
|
+
readonly redirectURI: string;
|
|
7
|
+
}
|
|
8
|
+
export interface PendingSignIn extends SignInRequest {
|
|
9
|
+
readonly correlationID: CorrelationID;
|
|
10
|
+
failures: number;
|
|
11
|
+
readonly expiresAt: number;
|
|
12
|
+
challenge: {
|
|
13
|
+
readonly value: string;
|
|
14
|
+
readonly expiresAt: number;
|
|
15
|
+
} | null;
|
|
16
|
+
}
|
|
17
|
+
export type TakenChallenge = {
|
|
18
|
+
readonly kind: 'taken';
|
|
19
|
+
readonly challenge: string;
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: 'expired';
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: 'missing';
|
|
24
|
+
};
|
|
25
|
+
interface ApprovedSignIn {
|
|
26
|
+
readonly binding: string;
|
|
27
|
+
readonly correlationID: CorrelationID;
|
|
28
|
+
readonly expiresAt: number;
|
|
29
|
+
}
|
|
30
|
+
export interface SignInState {
|
|
31
|
+
readonly createPending: (request: SignInRequest) => PendingSignIn | null;
|
|
32
|
+
readonly findPending: (key: string) => PendingSignIn | null;
|
|
33
|
+
readonly mintChallenge: (key: string) => string | null;
|
|
34
|
+
readonly claimChallenge: (key: string) => TakenChallenge;
|
|
35
|
+
readonly recordFailure: (key: string) => 'retry' | 'locked';
|
|
36
|
+
readonly removePending: (key: string) => void;
|
|
37
|
+
readonly removeClient: (clientID: OAuthClientID) => void;
|
|
38
|
+
readonly recordApproved: (sessionID: string, approved: Omit<ApprovedSignIn, 'expiresAt'>) => void;
|
|
39
|
+
readonly findApproved: (sessionID: string) => ApprovedSignIn | null;
|
|
40
|
+
readonly removeApproved: (sessionID: string) => void;
|
|
41
|
+
}
|
|
42
|
+
export declare function createSignInState(pendingMs: number, now: () => number): SignInState;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface ConsentChoice {
|
|
2
|
+
readonly accept: boolean;
|
|
3
|
+
readonly scopes: readonly string[];
|
|
4
|
+
readonly scope: string | null;
|
|
5
|
+
readonly noneTicked: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function pickConsentChoice(known: readonly string[], ticked: readonly string[], decision: string | null): ConsentChoice;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function readURLField(body: unknown): string | null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface ConsentPageView {
|
|
2
|
+
readonly consentPath: string;
|
|
3
|
+
readonly oauthQuery: string;
|
|
4
|
+
readonly clientName: string;
|
|
5
|
+
readonly redirectURI: string;
|
|
6
|
+
readonly scopes: readonly string[];
|
|
7
|
+
readonly extraFields: string;
|
|
8
|
+
readonly error: string | null;
|
|
9
|
+
}
|
|
10
|
+
export declare function renderConsentPage(view: ConsentPageView): string;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { EnrollmentState } from '../passkeys/create-enrollment-state.ts';
|
|
2
|
+
import type { Store } from '../store/open-store.ts';
|
|
3
|
+
import type { Clock, GrantLimits, MCPAuthPaths, SecuritySink } from '../types.ts';
|
|
4
|
+
import type { SignInState } from './create-sign-in-state.ts';
|
|
5
|
+
export interface RouteContext {
|
|
6
|
+
readonly store: Store;
|
|
7
|
+
readonly origin: string;
|
|
8
|
+
readonly resource: string;
|
|
9
|
+
readonly paths: MCPAuthPaths;
|
|
10
|
+
readonly productName: string;
|
|
11
|
+
readonly scopes: readonly string[];
|
|
12
|
+
readonly clock: Clock;
|
|
13
|
+
readonly security: SecuritySink;
|
|
14
|
+
readonly signIns: SignInState;
|
|
15
|
+
readonly enrollments: EnrollmentState;
|
|
16
|
+
readonly consentFields: Pick<GrantLimits<unknown>, 'renderConsentFields' | 'parseConsentFields'> | null;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function verifyOAuthQuery(oauthQuery: string, secret: string, now: number): Promise<boolean>;
|
|
@@ -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 {};
|