@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
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { isAPIError } from 'better-auth/api';
|
|
2
|
+
import { readStoredClientName } from '../sign-in/read-stored-client-name.ts';
|
|
3
|
+
import type { Store } from '../store/open-store.ts';
|
|
4
|
+
import { removeGrantRows } from '../store/remove-grant-rows.ts';
|
|
5
|
+
import type { Access, GrantLimits } from '../types.ts';
|
|
6
|
+
import { parseApprovedBy } from '../utils/parse-approved-by.ts';
|
|
7
|
+
import { parseJSONStrings } from '../utils/parse-json-strings.ts';
|
|
8
|
+
import { collectGrantedScopes } from './collect-granted-scopes.ts';
|
|
9
|
+
import { readAccessPayload } from './read-access-payload.ts';
|
|
10
|
+
|
|
11
|
+
// verify stamps the grant's last use at most this often.
|
|
12
|
+
const TOUCH_MS = 60_000;
|
|
13
|
+
|
|
14
|
+
interface OAuthVerification<Scope extends string, Limits> {
|
|
15
|
+
readonly store: Store;
|
|
16
|
+
readonly resource: string;
|
|
17
|
+
readonly scopes: readonly Scope[];
|
|
18
|
+
readonly grantLimits: GrantLimits<Limits> | null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type OAuthAccess<Scope extends string, Limits> = Extract<Access<Scope, Limits>, { kind: 'oauth' }>;
|
|
22
|
+
|
|
23
|
+
// An unknown, expired or revoked token, one bound to another resource or to a
|
|
24
|
+
// key, and one whose grant the app's limits end, all read as null.
|
|
25
|
+
export async function verifyOAuthAccess<Scope extends string, Limits>(
|
|
26
|
+
deps: OAuthVerification<Scope, Limits>,
|
|
27
|
+
bearer: string,
|
|
28
|
+
): Promise<OAuthAccess<Scope, Limits> | null> {
|
|
29
|
+
let payload: unknown;
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
payload = await deps.store.auth.api.verifyAccessToken({ body: { token: bearer } });
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (isAPIError(error)) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const access = readAccessPayload(payload);
|
|
42
|
+
|
|
43
|
+
if (access === null || !access.audiences.includes(deps.resource)) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const grant = await deps.store.db
|
|
48
|
+
.selectFrom('user')
|
|
49
|
+
.selectAll()
|
|
50
|
+
.where('id', '=', access.grantID)
|
|
51
|
+
.executeTakeFirst();
|
|
52
|
+
|
|
53
|
+
const approvedBy = grant === undefined ? null : parseApprovedBy(grant.approvedBy);
|
|
54
|
+
|
|
55
|
+
if (grant === undefined || approvedBy === null) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const held = parseJSONStrings(grant.scopes ?? '[]') ?? [];
|
|
60
|
+
const createdAt = Date.parse(grant.createdAt);
|
|
61
|
+
const lastUsedAt = grant.lastUsedAt === null ? null : Date.parse(grant.lastUsedAt);
|
|
62
|
+
let limits: Limits | null = null;
|
|
63
|
+
let allowed: readonly string[] | null = null;
|
|
64
|
+
|
|
65
|
+
if (deps.grantLimits !== null) {
|
|
66
|
+
const stored: unknown = grant.limits === null ? null : JSON.parse(grant.limits);
|
|
67
|
+
|
|
68
|
+
limits = deps.grantLimits.parseStored(stored);
|
|
69
|
+
|
|
70
|
+
if (limits === null) {
|
|
71
|
+
await removeGrantRows(deps.store, [grant.id]);
|
|
72
|
+
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const check = await deps.grantLimits.check({
|
|
77
|
+
grantID: grant.id,
|
|
78
|
+
clientID: grant.clientId,
|
|
79
|
+
scopes: held,
|
|
80
|
+
approvedBy,
|
|
81
|
+
limits,
|
|
82
|
+
createdAt,
|
|
83
|
+
lastUsedAt,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (check.kind === 'revoke') {
|
|
87
|
+
await removeGrantRows(deps.store, [grant.id]);
|
|
88
|
+
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
allowed = check.scopes;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const now = deps.store.options.clock.now();
|
|
96
|
+
|
|
97
|
+
if (lastUsedAt === null || now - lastUsedAt >= TOUCH_MS) {
|
|
98
|
+
await deps.store.db
|
|
99
|
+
.updateTable('user')
|
|
100
|
+
.set({ lastUsedAt: new Date(now).toISOString() })
|
|
101
|
+
.where('id', '=', grant.id)
|
|
102
|
+
.execute();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
kind: 'oauth',
|
|
107
|
+
grantID: grant.id,
|
|
108
|
+
clientID: access.clientID,
|
|
109
|
+
clientName: await readStoredClientName(deps.store, access.clientID),
|
|
110
|
+
scopes: collectGrantedScopes(deps.scopes, { grant: held, token: access.scopes, allowed }),
|
|
111
|
+
limits,
|
|
112
|
+
};
|
|
113
|
+
}
|
package/src/index.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,17 @@
|
|
|
1
|
+
export type MCPAuthErrorCode =
|
|
2
|
+
| 'conflict'
|
|
3
|
+
| 'not-found'
|
|
4
|
+
| 'invalid-client-name'
|
|
5
|
+
| 'invalid-redirect-uri'
|
|
6
|
+
| 'invalid-setup';
|
|
7
|
+
|
|
8
|
+
export class MCPAuthError extends Error {
|
|
9
|
+
readonly code: MCPAuthErrorCode;
|
|
10
|
+
|
|
11
|
+
constructor(code: MCPAuthErrorCode, message: string) {
|
|
12
|
+
super(message);
|
|
13
|
+
|
|
14
|
+
this.name = 'MCPAuthError';
|
|
15
|
+
this.code = code;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { buildAdmin } from './admin/build-admin.ts';
|
|
2
|
+
import { DEFAULT_PATHS } from './default-paths.ts';
|
|
3
|
+
import { openStore } from './store/open-store.ts';
|
|
4
|
+
import type { MCPAuthAdmin, MCPAuthAdminOptions } from './types.ts';
|
|
5
|
+
|
|
6
|
+
// An admin command opens the database with no origin, and gets only the admin
|
|
7
|
+
// calls.
|
|
8
|
+
export async function openMCPAuthAdmin<Scope extends string>(
|
|
9
|
+
options: MCPAuthAdminOptions<Scope>,
|
|
10
|
+
): Promise<MCPAuthAdmin> {
|
|
11
|
+
const store = await openStore(options, { origin: null, paths: DEFAULT_PATHS });
|
|
12
|
+
|
|
13
|
+
return buildAdmin(store, null);
|
|
14
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { buildAdmin } from './admin/build-admin.ts';
|
|
2
|
+
import { readClientScopes } from './grants/read-client-scopes.ts';
|
|
3
|
+
import { verifyOAuthAccess } from './grants/verify-oauth-access.ts';
|
|
4
|
+
import { MCPAuthError } from './mcp-auth-error.ts';
|
|
5
|
+
import { createEnrollmentState } from './passkeys/create-enrollment-state.ts';
|
|
6
|
+
import { buildRoutes } from './routes/build-routes.ts';
|
|
7
|
+
import { buildServiceTokenVerifier } from './service-tokens/build-service-token-verifier.ts';
|
|
8
|
+
import { createSignInState } from './sign-in/create-sign-in-state.ts';
|
|
9
|
+
import type { RouteContext } from './sign-in/route-context.ts';
|
|
10
|
+
import { CODE_SECONDS } from './store/create-auth-server.ts';
|
|
11
|
+
import { openStore } from './store/open-store.ts';
|
|
12
|
+
import type { MCPAuth, MCPAuthOptions } from './types.ts';
|
|
13
|
+
|
|
14
|
+
export async function openMCPAuth<Scope extends string, Limits = null>(
|
|
15
|
+
options: MCPAuthOptions<Scope, Limits>,
|
|
16
|
+
): Promise<MCPAuth<Scope, Limits>> {
|
|
17
|
+
const resource = `${options.origin}${options.paths.machine.mcp}`;
|
|
18
|
+
|
|
19
|
+
if (options.serviceTokens !== undefined && options.serviceTokens.file.resource !== resource) {
|
|
20
|
+
throw new MCPAuthError(
|
|
21
|
+
'invalid-setup',
|
|
22
|
+
`the service token file names another resource than ${resource}`,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const store = await openStore(options, { origin: options.origin, paths: options.paths });
|
|
27
|
+
|
|
28
|
+
// A resource served under an earlier origin stays a valid token target until
|
|
29
|
+
// its row goes.
|
|
30
|
+
await store.db.deleteFrom('oauthResource').where('identifier', '!=', resource).execute();
|
|
31
|
+
|
|
32
|
+
const signIns = createSignInState(CODE_SECONDS * 1000, options.clock.now);
|
|
33
|
+
|
|
34
|
+
const routes = buildRoutes({
|
|
35
|
+
store,
|
|
36
|
+
origin: options.origin,
|
|
37
|
+
resource,
|
|
38
|
+
paths: options.paths,
|
|
39
|
+
productName: options.productName,
|
|
40
|
+
scopes: options.scopes,
|
|
41
|
+
clock: options.clock,
|
|
42
|
+
security: options.security,
|
|
43
|
+
signIns,
|
|
44
|
+
enrollments: createEnrollmentState(options.clock.now),
|
|
45
|
+
consentFields: options.grantLimits ?? null,
|
|
46
|
+
} satisfies RouteContext);
|
|
47
|
+
|
|
48
|
+
const serviceTokens =
|
|
49
|
+
options.serviceTokens === undefined
|
|
50
|
+
? null
|
|
51
|
+
: buildServiceTokenVerifier(options.serviceTokens.file);
|
|
52
|
+
|
|
53
|
+
const prefix = options.serviceTokens?.prefix ?? null;
|
|
54
|
+
const scopes = options.scopes;
|
|
55
|
+
const grantLimits = options.grantLimits ?? null;
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
...buildAdmin(store, signIns),
|
|
59
|
+
resource,
|
|
60
|
+
issuer: options.origin,
|
|
61
|
+
paths: options.paths,
|
|
62
|
+
routes,
|
|
63
|
+
|
|
64
|
+
verify: (bearer) => {
|
|
65
|
+
if (serviceTokens !== null && prefix !== null && bearer.startsWith(prefix)) {
|
|
66
|
+
return Promise.resolve(serviceTokens.verify(bearer));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return verifyOAuthAccess(
|
|
70
|
+
{
|
|
71
|
+
store,
|
|
72
|
+
resource,
|
|
73
|
+
scopes,
|
|
74
|
+
grantLimits,
|
|
75
|
+
},
|
|
76
|
+
bearer,
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
// oxlint-disable-next-line zgeoff/verb-contract -- the contract names this call findClientScopes
|
|
81
|
+
findClientScopes: (clientID) => {
|
|
82
|
+
const service = serviceTokens?.findScopes(clientID) ?? null;
|
|
83
|
+
|
|
84
|
+
return service === null
|
|
85
|
+
? readClientScopes(store, scopes, clientID)
|
|
86
|
+
: Promise.resolve(service);
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { toTagged } from '@zgeoff/std';
|
|
2
|
+
import type { RouteContext } from '../sign-in/route-context.ts';
|
|
3
|
+
import type { PasskeyID, Requester } from '../types.ts';
|
|
4
|
+
import { buildPageResponse } from '../utils/build-page-response.ts';
|
|
5
|
+
import { readForm } from '../utils/read-form.ts';
|
|
6
|
+
import { createPasskey } from './create-passkey.ts';
|
|
7
|
+
import { PASSKEY_SCRIPT } from './passkey-script.ts';
|
|
8
|
+
import { readEnrollmentToken } from './read-enrollment-token.ts';
|
|
9
|
+
import { readPasskeyRows } from './read-passkey-rows.ts';
|
|
10
|
+
import { renderEnrollPage } from './render-enroll-page.ts';
|
|
11
|
+
import { verifyPasskeyRegistration } from './verify-passkey-registration.ts';
|
|
12
|
+
|
|
13
|
+
const INVALID_TOKEN_MESSAGE =
|
|
14
|
+
'That enrollment token is unknown, used, or expired. Make a new one with the passkeys command on the host.';
|
|
15
|
+
|
|
16
|
+
export async function answerEnrollRequest(
|
|
17
|
+
ctx: RouteContext,
|
|
18
|
+
request: Request,
|
|
19
|
+
requester: Requester,
|
|
20
|
+
): Promise<Response> {
|
|
21
|
+
const view = { productName: ctx.productName, enrollPath: ctx.paths.browser.enroll };
|
|
22
|
+
|
|
23
|
+
if (request.method !== 'POST') {
|
|
24
|
+
return buildPageResponse(200, {
|
|
25
|
+
page: renderEnrollPage({ ...view, ceremony: null, error: null }),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const form = await readForm(request);
|
|
30
|
+
|
|
31
|
+
const token = (form.get('token') ?? '').trim();
|
|
32
|
+
const context = { path: new URL(request.url).pathname, requester };
|
|
33
|
+
const tokenHash = token === '' ? null : await readEnrollmentToken(ctx.store, token);
|
|
34
|
+
|
|
35
|
+
if (tokenHash === null) {
|
|
36
|
+
ctx.security.record({
|
|
37
|
+
kind: 'owner_auth',
|
|
38
|
+
outcome: 'failed',
|
|
39
|
+
reason: 'invalid_token',
|
|
40
|
+
...context,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return buildPageResponse(400, {
|
|
44
|
+
page: renderEnrollPage({ ...view, ceremony: null, error: INVALID_TOKEN_MESSAGE }),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!form.has('credential')) {
|
|
49
|
+
return answerCeremony(ctx, { status: 200, token, tokenHash, error: null });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const taken = ctx.enrollments.claimChallenge(tokenHash);
|
|
53
|
+
|
|
54
|
+
const registered =
|
|
55
|
+
taken.kind === 'taken'
|
|
56
|
+
? await verifyPasskeyRegistration({
|
|
57
|
+
credential: form.get('credential') ?? '',
|
|
58
|
+
challenge: taken.challenge,
|
|
59
|
+
origin: ctx.origin,
|
|
60
|
+
rpID: new URL(ctx.origin).hostname,
|
|
61
|
+
})
|
|
62
|
+
: null;
|
|
63
|
+
|
|
64
|
+
if (registered === null) {
|
|
65
|
+
const isExpired = taken.kind === 'expired';
|
|
66
|
+
|
|
67
|
+
ctx.security.record({
|
|
68
|
+
kind: 'owner_auth',
|
|
69
|
+
outcome: 'failed',
|
|
70
|
+
reason: isExpired ? 'expired' : 'assertion_failed',
|
|
71
|
+
...context,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const error = isExpired
|
|
75
|
+
? 'The enrollment took too long. Try again.'
|
|
76
|
+
: `${ctx.productName} could not enroll that passkey. Try again.`;
|
|
77
|
+
|
|
78
|
+
return answerCeremony(ctx, { status: 400, token, tokenHash, error });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let isCreated: boolean;
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
isCreated = await createPasskey(ctx.store, {
|
|
85
|
+
tokenHash,
|
|
86
|
+
id: toTagged<PasskeyID>(registered.id),
|
|
87
|
+
publicKey: Buffer.from(registered.publicKey).toString('base64url'),
|
|
88
|
+
counter: registered.counter,
|
|
89
|
+
transports: registered.transports,
|
|
90
|
+
});
|
|
91
|
+
} catch {
|
|
92
|
+
ctx.security.record({
|
|
93
|
+
kind: 'owner_auth',
|
|
94
|
+
outcome: 'failed',
|
|
95
|
+
reason: 'assertion_failed',
|
|
96
|
+
...context,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
return answerCeremony(ctx, {
|
|
100
|
+
status: 400,
|
|
101
|
+
token,
|
|
102
|
+
tokenHash,
|
|
103
|
+
error: 'That passkey is already enrolled. Use another device, or sign in with it.',
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!isCreated) {
|
|
108
|
+
ctx.security.record({
|
|
109
|
+
kind: 'owner_auth',
|
|
110
|
+
outcome: 'failed',
|
|
111
|
+
reason: 'invalid_token',
|
|
112
|
+
...context,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return buildPageResponse(400, {
|
|
116
|
+
page: renderEnrollPage({ ...view, ceremony: null, error: INVALID_TOKEN_MESSAGE }),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
ctx.security.record({ kind: 'owner_auth', outcome: 'succeeded', ...context });
|
|
121
|
+
|
|
122
|
+
return buildPageResponse(200, {
|
|
123
|
+
message: 'Passkey enrolled. Start the connection again from your client and sign in with it.',
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
interface CeremonyAnswer {
|
|
128
|
+
readonly status: number;
|
|
129
|
+
readonly token: string;
|
|
130
|
+
readonly tokenHash: string;
|
|
131
|
+
readonly error: string | null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// How long the browser's passkey prompt waits, in milliseconds.
|
|
135
|
+
const PROMPT_TIMEOUT_MS = 120_000;
|
|
136
|
+
|
|
137
|
+
async function answerCeremony(ctx: RouteContext, answer: CeremonyAnswer): Promise<Response> {
|
|
138
|
+
const enrolled = await readPasskeyRows(ctx.store.db, ctx.store.options.tables.passkey, null);
|
|
139
|
+
|
|
140
|
+
// The one owner's WebAuthn user handle, the same for every passkey, so an
|
|
141
|
+
// authenticator files each one under the one account.
|
|
142
|
+
const ownerHandle = Buffer.from(`${ctx.productName}-owner`).toString('base64url');
|
|
143
|
+
|
|
144
|
+
const options = {
|
|
145
|
+
challenge: ctx.enrollments.mintChallenge(answer.tokenHash),
|
|
146
|
+
rp: { id: new URL(ctx.origin).hostname, name: ctx.productName },
|
|
147
|
+
user: { id: ownerHandle, name: 'owner', displayName: `${ctx.productName} owner` },
|
|
148
|
+
pubKeyCredParams: [
|
|
149
|
+
{ type: 'public-key', alg: -8 },
|
|
150
|
+
{ type: 'public-key', alg: -7 },
|
|
151
|
+
{ type: 'public-key', alg: -257 },
|
|
152
|
+
],
|
|
153
|
+
timeout: PROMPT_TIMEOUT_MS,
|
|
154
|
+
|
|
155
|
+
// An authenticator that already holds an enrolled passkey refuses to make
|
|
156
|
+
// a second.
|
|
157
|
+
excludeCredentials: enrolled.map((row) => ({ type: 'public-key', id: row.id })),
|
|
158
|
+
authenticatorSelection: {
|
|
159
|
+
residentKey: 'required',
|
|
160
|
+
requireResidentKey: true,
|
|
161
|
+
userVerification: 'required',
|
|
162
|
+
},
|
|
163
|
+
attestation: 'none',
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
return buildPageResponse(
|
|
167
|
+
answer.status,
|
|
168
|
+
{
|
|
169
|
+
page: renderEnrollPage({
|
|
170
|
+
productName: ctx.productName,
|
|
171
|
+
enrollPath: ctx.paths.browser.enroll,
|
|
172
|
+
ceremony: { token: answer.token, options },
|
|
173
|
+
error: answer.error,
|
|
174
|
+
}),
|
|
175
|
+
},
|
|
176
|
+
[],
|
|
177
|
+
[PASSKEY_SCRIPT.policySource],
|
|
178
|
+
);
|
|
179
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import type { TakenChallenge } from '../sign-in/create-sign-in-state.ts';
|
|
3
|
+
|
|
4
|
+
// At most this many enrollment challenges wait at once; a new one past the
|
|
5
|
+
// limit drops the oldest.
|
|
6
|
+
const MAX_CHALLENGES = 8;
|
|
7
|
+
|
|
8
|
+
// How long an enrollment page's challenge stays valid.
|
|
9
|
+
const CHALLENGE_MS = 5 * 60_000;
|
|
10
|
+
|
|
11
|
+
export interface EnrollmentState {
|
|
12
|
+
readonly mintChallenge: (tokenHash: string) => string;
|
|
13
|
+
|
|
14
|
+
// Takes the token's challenge, so it verifies at most one registration.
|
|
15
|
+
readonly claimChallenge: (tokenHash: string) => TakenChallenge;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function createEnrollmentState(now: () => number): EnrollmentState {
|
|
19
|
+
const challenges = new Map<string, { readonly value: string; readonly expiresAt: number }>();
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
mintChallenge: (tokenHash) => {
|
|
23
|
+
challenges.delete(tokenHash);
|
|
24
|
+
|
|
25
|
+
const oldest = challenges.keys().next();
|
|
26
|
+
|
|
27
|
+
if (challenges.size >= MAX_CHALLENGES && oldest.done !== true) {
|
|
28
|
+
challenges.delete(oldest.value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const value = randomBytes(32).toString('base64url');
|
|
32
|
+
|
|
33
|
+
challenges.set(tokenHash, { value, expiresAt: now() + CHALLENGE_MS });
|
|
34
|
+
|
|
35
|
+
return value;
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
claimChallenge: (tokenHash) => {
|
|
39
|
+
const challenge = challenges.get(tokenHash);
|
|
40
|
+
|
|
41
|
+
if (challenge === undefined) {
|
|
42
|
+
return { kind: 'missing' };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
challenges.delete(tokenHash);
|
|
46
|
+
|
|
47
|
+
if (challenge.expiresAt <= now()) {
|
|
48
|
+
return { kind: 'expired' };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return { kind: 'taken', challenge: challenge.value };
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { sql } from 'kysely';
|
|
2
|
+
import type { Store } from '../store/open-store.ts';
|
|
3
|
+
import type { PasskeyID } from '../types.ts';
|
|
4
|
+
|
|
5
|
+
export interface NewPasskey {
|
|
6
|
+
// The hash of the enrollment token the passkey was enrolled with.
|
|
7
|
+
readonly tokenHash: string;
|
|
8
|
+
|
|
9
|
+
// The credential id and its COSE public key, both base64url.
|
|
10
|
+
readonly id: PasskeyID;
|
|
11
|
+
readonly publicKey: string;
|
|
12
|
+
readonly counter: number;
|
|
13
|
+
readonly transports: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Spending the token in the same transaction as the insert lets one token
|
|
17
|
+
// enroll one passkey.
|
|
18
|
+
export function createPasskey(store: Store, passkey: NewPasskey): Promise<boolean> {
|
|
19
|
+
const now = store.options.clock.now();
|
|
20
|
+
const passkeyTable = store.options.tables.passkey;
|
|
21
|
+
const enrollmentToken = store.options.tables.enrollmentToken;
|
|
22
|
+
|
|
23
|
+
return store.db.transaction().execute(async (trx) => {
|
|
24
|
+
const spent =
|
|
25
|
+
await sql`delete from ${sql.table(enrollmentToken)} where token_hash = ${passkey.tokenHash} and expires_at > ${new Date(now).toISOString()}`.execute(
|
|
26
|
+
trx,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
if ((spent.numAffectedRows ?? 0n) === 0n) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
await sql`insert into ${sql.table(passkeyTable)} (id, public_key, counter, transports, created_at, last_used_at) values (${passkey.id}, ${passkey.publicKey}, ${passkey.counter}, ${JSON.stringify(passkey.transports)}, ${new Date(now).toISOString()}, null)`.execute(
|
|
34
|
+
trx,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return true;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
// runs the `create` or `get` ceremony a page's `mcp-auth-passkey` block holds and posts
|
|
4
|
+
// the credential's JSON with the form; a prompt that ends without one leaves the
|
|
5
|
+
// form unsent and the button ready again.
|
|
6
|
+
const SOURCE = `(() => {
|
|
7
|
+
const data = document.getElementById('mcp-auth-passkey');
|
|
8
|
+
const form = document.getElementById('mcp-auth-passkey-form');
|
|
9
|
+
const button = document.getElementById('mcp-auth-passkey-start');
|
|
10
|
+
const status = document.getElementById('mcp-auth-passkey-status');
|
|
11
|
+
if (data === null || form === null || button === null || status === null) return;
|
|
12
|
+
const spec = JSON.parse(data.textContent);
|
|
13
|
+
const toBytes = (value) => {
|
|
14
|
+
const base64 = value.replace(/-/g, '+').replace(/_/g, '/');
|
|
15
|
+
const padded = base64 + '='.repeat((4 - (base64.length % 4)) % 4);
|
|
16
|
+
return Uint8Array.from(atob(padded), (c) => c.charCodeAt(0));
|
|
17
|
+
};
|
|
18
|
+
const toText = (buffer) => {
|
|
19
|
+
let text = '';
|
|
20
|
+
for (const byte of new Uint8Array(buffer)) text += String.fromCharCode(byte);
|
|
21
|
+
return btoa(text).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '');
|
|
22
|
+
};
|
|
23
|
+
const toDescriptors = (list) => (list || []).map((item) => ({ ...item, id: toBytes(item.id) }));
|
|
24
|
+
button.addEventListener('click', async () => {
|
|
25
|
+
button.disabled = true;
|
|
26
|
+
status.textContent = '';
|
|
27
|
+
try {
|
|
28
|
+
const options = spec.options;
|
|
29
|
+
const credential = spec.mode === 'create'
|
|
30
|
+
? await navigator.credentials.create({ publicKey: { ...options, challenge: toBytes(options.challenge), user: { ...options.user, id: toBytes(options.user.id) }, excludeCredentials: toDescriptors(options.excludeCredentials) } })
|
|
31
|
+
: await navigator.credentials.get({ publicKey: { ...options, challenge: toBytes(options.challenge), allowCredentials: toDescriptors(options.allowCredentials) } });
|
|
32
|
+
const reply = credential.response;
|
|
33
|
+
const response = spec.mode === 'create'
|
|
34
|
+
? { clientDataJSON: toText(reply.clientDataJSON), attestationObject: toText(reply.attestationObject), transports: typeof reply.getTransports === 'function' ? reply.getTransports() : [] }
|
|
35
|
+
: { clientDataJSON: toText(reply.clientDataJSON), authenticatorData: toText(reply.authenticatorData), signature: toText(reply.signature), userHandle: reply.userHandle ? toText(reply.userHandle) : undefined };
|
|
36
|
+
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 });
|
|
37
|
+
form.submit();
|
|
38
|
+
} catch (error) {
|
|
39
|
+
status.textContent = 'The passkey prompt ended without a passkey (' + (error && error.name ? error.name : 'Error') + '). Try again.';
|
|
40
|
+
button.disabled = false;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
})();`;
|
|
44
|
+
|
|
45
|
+
export const PASSKEY_SCRIPT = {
|
|
46
|
+
source: SOURCE,
|
|
47
|
+
policySource: `'sha256-${createHash('sha256').update(SOURCE).digest('base64')}'`,
|
|
48
|
+
} as const;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { sql } from 'kysely';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { Store } from '../store/open-store.ts';
|
|
4
|
+
import { deriveTokenHash } from '../utils/derive-token-hash.ts';
|
|
5
|
+
|
|
6
|
+
const TokenRowsSchema = z.array(z.object({ token_hash: z.string() }));
|
|
7
|
+
|
|
8
|
+
export async function readEnrollmentToken(store: Store, token: string): Promise<string | null> {
|
|
9
|
+
const now = new Date(store.options.clock.now()).toISOString();
|
|
10
|
+
|
|
11
|
+
const table = sql.table(store.options.tables.enrollmentToken);
|
|
12
|
+
|
|
13
|
+
const result =
|
|
14
|
+
await sql`select token_hash from ${table} where token_hash = ${deriveTokenHash(token)} and expires_at > ${now}`.execute(
|
|
15
|
+
store.db,
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const [row] = TokenRowsSchema.parse(result.rows);
|
|
19
|
+
|
|
20
|
+
return row === undefined ? null : row.token_hash;
|
|
21
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { sql } from 'kysely';
|
|
2
|
+
import type { Kysely } from 'kysely';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import type { StoreSchema } from '../store/store-schema.ts';
|
|
5
|
+
|
|
6
|
+
const PasskeyRowsSchema = z.array(
|
|
7
|
+
z.object({
|
|
8
|
+
id: z.string(),
|
|
9
|
+
public_key: z.string(),
|
|
10
|
+
counter: z.number(),
|
|
11
|
+
transports: z.string(),
|
|
12
|
+
created_at: z.string(),
|
|
13
|
+
last_used_at: z.string().nullable(),
|
|
14
|
+
}),
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
// The passkeys of the app's table, oldest first, or the one with the given id.
|
|
18
|
+
// The executor is the store's Kysely, or a transaction of it.
|
|
19
|
+
export async function readPasskeyRows(
|
|
20
|
+
executor: Kysely<StoreSchema>,
|
|
21
|
+
table: string,
|
|
22
|
+
id: string | null,
|
|
23
|
+
): Promise<z.infer<typeof PasskeyRowsSchema>> {
|
|
24
|
+
const result =
|
|
25
|
+
id === null
|
|
26
|
+
? await sql`select * from ${sql.table(table)} order by created_at`.execute(executor)
|
|
27
|
+
: await sql`select * from ${sql.table(table)} where id = ${id}`.execute(executor);
|
|
28
|
+
|
|
29
|
+
return PasskeyRowsSchema.parse(result.rows);
|
|
30
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { toHTMLText } from '../utils/to-html-text.ts';
|
|
2
|
+
import { toScriptJSON } from '../utils/to-script-json.ts';
|
|
3
|
+
import { PASSKEY_SCRIPT } from './passkey-script.ts';
|
|
4
|
+
|
|
5
|
+
interface EnrollPageView {
|
|
6
|
+
readonly productName: string;
|
|
7
|
+
readonly enrollPath: string;
|
|
8
|
+
|
|
9
|
+
// The enrollment token the owner typed, once it checked out, with the
|
|
10
|
+
// WebAuthn creation options for its challenge; null asks for the token.
|
|
11
|
+
readonly ceremony: { readonly token: string; readonly options: unknown } | null;
|
|
12
|
+
readonly error: string | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function renderEnrollPage(view: EnrollPageView): string {
|
|
16
|
+
const product = toHTMLText(view.productName);
|
|
17
|
+
const action = toHTMLText(view.enrollPath);
|
|
18
|
+
const error = view.error === null ? '' : `<p class="error">${toHTMLText(view.error)}</p>`;
|
|
19
|
+
|
|
20
|
+
const step =
|
|
21
|
+
view.ceremony === null
|
|
22
|
+
? `<p>Type the enrollment token that the passkeys command of ${product} printed on the host.</p>
|
|
23
|
+
<form method="post" action="${action}">
|
|
24
|
+
<label>Enrollment token <input name="token" autocomplete="off" autofocus required></label>
|
|
25
|
+
<button type="submit">Continue</button>
|
|
26
|
+
</form>`
|
|
27
|
+
: `<p>Create a passkey for ${product}. Your device asks you to verify yourself.</p>
|
|
28
|
+
<script type="application/json" id="mcp-auth-passkey">${toScriptJSON({ mode: 'create', options: view.ceremony.options })}</script>
|
|
29
|
+
<form method="post" action="${action}" id="mcp-auth-passkey-form">
|
|
30
|
+
<input type="hidden" name="token" value="${toHTMLText(view.ceremony.token)}">
|
|
31
|
+
<input type="hidden" name="credential" value="">
|
|
32
|
+
<button type="button" id="mcp-auth-passkey-start" autofocus>Create a passkey</button>
|
|
33
|
+
</form>
|
|
34
|
+
<p id="mcp-auth-passkey-status" class="error" role="status"></p>
|
|
35
|
+
<script>${PASSKEY_SCRIPT.source}</script>`;
|
|
36
|
+
|
|
37
|
+
return `<!doctype html>
|
|
38
|
+
<html lang="en">
|
|
39
|
+
<head>
|
|
40
|
+
<meta charset="utf-8">
|
|
41
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
42
|
+
<title>Enroll a passkey for ${product}</title>
|
|
43
|
+
<style>
|
|
44
|
+
body { font-family: system-ui, sans-serif; max-width: 32rem; margin: 3rem auto; padding: 0 1rem; line-height: 1.5; }
|
|
45
|
+
input[name="token"] { font: inherit; font-family: ui-monospace, monospace; padding: 0.25rem; width: 100%; }
|
|
46
|
+
.error { color: #b00020; }
|
|
47
|
+
code { word-break: break-all; }
|
|
48
|
+
button { font: inherit; }
|
|
49
|
+
</style>
|
|
50
|
+
</head>
|
|
51
|
+
<body>
|
|
52
|
+
<h1>Enroll a passkey for ${product}</h1>
|
|
53
|
+
${error}
|
|
54
|
+
${step}
|
|
55
|
+
</body>
|
|
56
|
+
</html>
|
|
57
|
+
`;
|
|
58
|
+
}
|