@zgeoff/mcp-auth 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +76 -2
- package/dist/admin/build-admin.d.ts +4 -0
- package/dist/admin/build-client-admin.d.ts +4 -0
- package/dist/admin/build-grant-admin.d.ts +3 -0
- package/dist/admin/build-passkey-admin.d.ts +3 -0
- package/dist/admin/check-redirect-uris.d.ts +1 -0
- package/dist/admin/create-enrollment-token.d.ts +2 -0
- package/dist/admin/read-client-name.d.ts +1 -0
- package/dist/admin/read-sign-in-grants.d.ts +3 -0
- package/dist/admin/remove-expired.d.ts +2 -0
- package/dist/admin/to-client-view.d.ts +3 -0
- package/dist/default-paths.d.ts +18 -0
- package/dist/elysia/create-mcp-http-app.d.ts +17 -0
- package/dist/elysia/find-bearer-token.d.ts +1 -0
- package/dist/elysia/index.d.ts +2 -0
- package/dist/elysia/is-beside-prefix.d.ts +1 -0
- package/dist/grants/collect-granted-scopes.d.ts +7 -0
- package/dist/grants/read-access-payload.d.ts +9 -0
- package/dist/grants/read-client-scopes.d.ts +2 -0
- package/dist/grants/verify-oauth-access.d.ts +13 -0
- package/dist/index.d.ts +7 -0
- package/dist/mcp-auth-error.d.ts +5 -0
- package/dist/open-mcp-auth-admin.d.ts +2 -0
- package/dist/open-mcp-auth.d.ts +2 -0
- package/dist/passkeys/answer-enroll-request.d.ts +3 -0
- package/dist/passkeys/create-enrollment-state.d.ts +6 -0
- package/dist/passkeys/create-passkey.d.ts +10 -0
- package/dist/passkeys/passkey-script.d.ts +4 -0
- package/dist/passkeys/read-enrollment-token.d.ts +2 -0
- package/dist/passkeys/read-passkey-rows.d.ts +13 -0
- package/dist/passkeys/render-enroll-page.d.ts +11 -0
- package/dist/passkeys/render-login-page.d.ts +11 -0
- package/dist/passkeys/update-passkey-use.d.ts +9 -0
- package/dist/passkeys/verify-passkey-assertion.d.ts +10 -0
- package/dist/passkeys/verify-passkey-registration.d.ts +15 -0
- package/dist/passkeys/verify-session-passkey.d.ts +8 -0
- package/dist/routes/build-routes.d.ts +3 -0
- package/dist/routes/with-form-origin.d.ts +4 -0
- package/dist/service-tokens/build-service-token-verifier.d.ts +13 -0
- package/dist/service-tokens/parse-service-token-file.d.ts +7 -0
- package/dist/sign-in/answer-authorize-request.d.ts +3 -0
- package/dist/sign-in/answer-consent-request.d.ts +3 -0
- package/dist/sign-in/answer-login-request.d.ts +3 -0
- package/dist/sign-in/build-consent-binding.d.ts +1 -0
- package/dist/sign-in/create-sign-in-state.d.ts +43 -0
- package/dist/sign-in/pick-consent-choice.d.ts +8 -0
- package/dist/sign-in/pick-consent-outcome.d.ts +4 -0
- package/dist/sign-in/read-session-id.d.ts +2 -0
- package/dist/sign-in/read-stored-client-name.d.ts +3 -0
- package/dist/sign-in/read-url-field.d.ts +1 -0
- package/dist/sign-in/render-consent-page.d.ts +11 -0
- package/dist/sign-in/route-context.d.ts +17 -0
- package/dist/sign-in/verify-oauth-query.d.ts +1 -0
- package/dist/store/check-cascade-keys.d.ts +2 -0
- package/dist/store/check-foreign-keys.d.ts +2 -0
- package/dist/store/check-table-names.d.ts +2 -0
- package/dist/store/check-user-columns.d.ts +2 -0
- package/dist/store/create-auth-server.d.ts +103 -0
- package/dist/store/create-grant-plugin.d.ts +28 -0
- package/dist/store/create-owned-tables.d.ts +3 -0
- package/dist/store/open-store.d.ts +15 -0
- package/dist/store/read-table-columns.d.ts +2 -0
- package/dist/store/remove-grant-rows.d.ts +3 -0
- package/dist/store/store-schema.d.ts +63 -0
- package/dist/test-utils/authorize-test-client.d.ts +12 -0
- package/dist/test-utils/build-form-request.d.ts +1 -0
- package/dist/test-utils/build-seeder.d.ts +13 -0
- package/dist/test-utils/build-stub-authenticator.d.ts +49 -0
- package/dist/test-utils/build-stub-clock.d.ts +5 -0
- package/dist/test-utils/build-test-requester.d.ts +2 -0
- package/dist/test-utils/create-test-database.d.ts +2 -0
- package/dist/test-utils/hook-sqlite-statements.d.ts +2 -0
- package/dist/test-utils/index.d.ts +12 -0
- package/dist/test-utils/open-test-auth.d.ts +21 -0
- package/dist/test-utils/parse-passkey-page.d.ts +21 -0
- package/dist/test-utils/read-json-record.d.ts +5 -0
- package/dist/test-utils/run-sign-in-to-consent.d.ts +13 -0
- package/dist/test-utils/seed-client.d.ts +7 -0
- package/dist/test-utils/seed-enrollment-token.d.ts +2 -0
- package/dist/test-utils/seed-passkey.d.ts +7 -0
- package/dist/tokens/answer-error-request.d.ts +2 -0
- package/dist/tokens/answer-metadata-request.d.ts +2 -0
- package/dist/tokens/answer-revoke-request.d.ts +2 -0
- package/dist/tokens/answer-token-request.d.ts +3 -0
- package/dist/tokens/build-better-auth-request.d.ts +6 -0
- package/dist/tokens/build-oauth-error.d.ts +1 -0
- package/dist/tokens/read-error-code.d.ts +1 -0
- package/dist/tokens/read-error-description.d.ts +1 -0
- package/dist/tokens/record-token-exchange.d.ts +10 -0
- package/dist/tokens/remove-token-sessions.d.ts +2 -0
- package/dist/types.d.ts +185 -0
- package/dist/utils/build-page-response.d.ts +5 -0
- package/dist/utils/derive-token-hash.d.ts +1 -0
- package/dist/utils/is-allowed-redirect-uri.d.ts +1 -0
- package/dist/utils/is-loopback-host.d.ts +1 -0
- package/dist/utils/normalize-client-name.d.ts +1 -0
- package/dist/utils/parse-approved-by.d.ts +2 -0
- package/dist/utils/parse-json-strings.d.ts +1 -0
- package/dist/utils/read-body-text.d.ts +1 -0
- package/dist/utils/read-form.d.ts +2 -0
- package/dist/utils/to-html-text.d.ts +1 -0
- package/dist/utils/to-script-json.d.ts +1 -0
- package/package.json +73 -4
- package/src/admin/build-admin.ts +22 -0
- package/src/admin/build-client-admin.ts +112 -0
- package/src/admin/build-grant-admin.ts +62 -0
- package/src/admin/build-passkey-admin.ts +53 -0
- package/src/admin/check-redirect-uris.ts +17 -0
- package/src/admin/create-enrollment-token.ts +18 -0
- package/src/admin/read-client-name.ts +13 -0
- package/src/admin/read-sign-in-grants.ts +22 -0
- package/src/admin/remove-expired.ts +47 -0
- package/src/admin/to-client-view.ts +12 -0
- package/src/default-paths.ts +21 -0
- package/src/elysia/create-mcp-http-app.ts +218 -0
- package/src/elysia/find-bearer-token.ts +6 -0
- package/src/elysia/index.ts +2 -0
- package/src/elysia/is-beside-prefix.ts +7 -0
- package/src/grants/collect-granted-scopes.ts +19 -0
- package/src/grants/read-access-payload.ts +37 -0
- package/src/grants/read-client-scopes.ts +36 -0
- package/src/grants/verify-oauth-access.ts +113 -0
- package/src/index.ts +7 -0
- package/src/mcp-auth-error.ts +17 -0
- package/src/open-mcp-auth-admin.ts +14 -0
- package/src/open-mcp-auth.ts +89 -0
- package/src/passkeys/answer-enroll-request.ts +179 -0
- package/src/passkeys/create-enrollment-state.ts +54 -0
- package/src/passkeys/create-passkey.ts +39 -0
- package/src/passkeys/passkey-script.ts +48 -0
- package/src/passkeys/read-enrollment-token.ts +21 -0
- package/src/passkeys/read-passkey-rows.ts +30 -0
- package/src/passkeys/render-enroll-page.ts +58 -0
- package/src/passkeys/render-login-page.ts +59 -0
- package/src/passkeys/update-passkey-use.ts +24 -0
- package/src/passkeys/verify-passkey-assertion.ts +120 -0
- package/src/passkeys/verify-passkey-registration.ts +116 -0
- package/src/passkeys/verify-session-passkey.ts +42 -0
- package/src/routes/build-routes.ts +31 -0
- package/src/routes/with-form-origin.ts +18 -0
- package/src/service-tokens/build-service-token-verifier.ts +56 -0
- package/src/service-tokens/parse-service-token-file.ts +104 -0
- package/src/sign-in/answer-authorize-request.ts +133 -0
- package/src/sign-in/answer-consent-request.ts +220 -0
- package/src/sign-in/answer-login-request.ts +243 -0
- package/src/sign-in/build-consent-binding.ts +11 -0
- package/src/sign-in/create-sign-in-state.ts +229 -0
- package/src/sign-in/pick-consent-choice.ts +27 -0
- package/src/sign-in/pick-consent-outcome.ts +14 -0
- package/src/sign-in/read-session-id.ts +11 -0
- package/src/sign-in/read-stored-client-name.ts +15 -0
- package/src/sign-in/read-url-field.ts +12 -0
- package/src/sign-in/render-consent-page.ts +57 -0
- package/src/sign-in/route-context.ts +25 -0
- package/src/sign-in/verify-oauth-query.ts +39 -0
- package/src/store/check-cascade-keys.ts +36 -0
- package/src/store/check-foreign-keys.ts +20 -0
- package/src/store/check-table-names.ts +13 -0
- package/src/store/check-user-columns.ts +22 -0
- package/src/store/create-auth-server.ts +97 -0
- package/src/store/create-grant-plugin.ts +68 -0
- package/src/store/create-owned-tables.ts +45 -0
- package/src/store/open-store.ts +72 -0
- package/src/store/read-table-columns.ts +12 -0
- package/src/store/remove-grant-rows.ts +27 -0
- package/src/store/store-schema.ts +61 -0
- package/src/test-utils/authorize-test-client.ts +93 -0
- package/src/test-utils/build-form-request.ts +12 -0
- package/src/test-utils/build-seeder.ts +19 -0
- package/src/test-utils/build-stub-authenticator.ts +244 -0
- package/src/test-utils/build-stub-clock.ts +21 -0
- package/src/test-utils/build-test-requester.ts +5 -0
- package/src/test-utils/create-test-database.ts +7 -0
- package/src/test-utils/hook-sqlite-statements.ts +17 -0
- package/src/test-utils/index.ts +12 -0
- package/src/test-utils/open-test-auth.ts +72 -0
- package/src/test-utils/parse-passkey-page.ts +25 -0
- package/src/test-utils/read-json-record.ts +15 -0
- package/src/test-utils/run-sign-in-to-consent.ts +100 -0
- package/src/test-utils/seed-client.ts +16 -0
- package/src/test-utils/seed-enrollment-token.ts +5 -0
- package/src/test-utils/seed-passkey.ts +51 -0
- package/src/tokens/answer-error-request.ts +26 -0
- package/src/tokens/answer-metadata-request.ts +51 -0
- package/src/tokens/answer-revoke-request.ts +47 -0
- package/src/tokens/answer-token-request.ts +133 -0
- package/src/tokens/build-better-auth-request.ts +23 -0
- package/src/tokens/build-oauth-error.ts +7 -0
- package/src/tokens/read-error-code.ts +12 -0
- package/src/tokens/read-error-description.ts +11 -0
- package/src/tokens/record-token-exchange.ts +73 -0
- package/src/tokens/remove-token-sessions.ts +32 -0
- package/src/types.ts +247 -0
- package/src/utils/build-page-response.ts +24 -0
- package/src/utils/derive-token-hash.ts +5 -0
- package/src/utils/is-allowed-redirect-uri.ts +17 -0
- package/src/utils/is-loopback-host.ts +8 -0
- package/src/utils/normalize-client-name.ts +20 -0
- package/src/utils/parse-approved-by.ts +9 -0
- package/src/utils/parse-json-strings.ts +13 -0
- package/src/utils/read-body-text.ts +23 -0
- package/src/utils/read-form.ts +16 -0
- package/src/utils/to-html-text.ts +8 -0
- package/src/utils/to-script-json.ts +6 -0
|
@@ -0,0 +1,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
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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 LoginPageView {
|
|
6
|
+
readonly productName: string;
|
|
7
|
+
readonly loginPath: string;
|
|
8
|
+
|
|
9
|
+
// The signed authorization query the page posts back.
|
|
10
|
+
readonly oauthQuery: string;
|
|
11
|
+
readonly clientName: string;
|
|
12
|
+
readonly redirectURI: string;
|
|
13
|
+
|
|
14
|
+
// The WebAuthn request options for this page's challenge, or null when
|
|
15
|
+
// no passkey is enrolled, so there is nothing to sign in with.
|
|
16
|
+
readonly options: unknown;
|
|
17
|
+
readonly error: string | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function renderLoginPage(view: LoginPageView): string {
|
|
21
|
+
const product = toHTMLText(view.productName);
|
|
22
|
+
const error = view.error === null ? '' : `<p class="error">${toHTMLText(view.error)}</p>`;
|
|
23
|
+
|
|
24
|
+
const signIn =
|
|
25
|
+
view.options === null
|
|
26
|
+
? `<p class="error">No passkey is enrolled, so nobody can sign in. On the host that runs ${product}, make an enrollment token with its passkeys command, then follow what it prints.</p>`
|
|
27
|
+
: `<script type="application/json" id="mcp-auth-passkey">${toScriptJSON({ mode: 'get', options: view.options })}</script>
|
|
28
|
+
<form method="post" action="${toHTMLText(view.loginPath)}" id="mcp-auth-passkey-form">
|
|
29
|
+
<input type="hidden" name="oauth_query" value="${toHTMLText(view.oauthQuery)}">
|
|
30
|
+
<input type="hidden" name="credential" value="">
|
|
31
|
+
<button type="button" id="mcp-auth-passkey-start" autofocus>Sign in with a passkey</button>
|
|
32
|
+
</form>
|
|
33
|
+
<p id="mcp-auth-passkey-status" class="error" role="status"></p>
|
|
34
|
+
<script>${PASSKEY_SCRIPT.source}</script>`;
|
|
35
|
+
|
|
36
|
+
return `<!doctype html>
|
|
37
|
+
<html lang="en">
|
|
38
|
+
<head>
|
|
39
|
+
<meta charset="utf-8">
|
|
40
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
41
|
+
<title>Sign in to ${product}</title>
|
|
42
|
+
<style>
|
|
43
|
+
body { font-family: system-ui, sans-serif; max-width: 32rem; margin: 3rem auto; padding: 0 1rem; line-height: 1.5; }
|
|
44
|
+
.error { color: #b00020; }
|
|
45
|
+
code { word-break: break-all; }
|
|
46
|
+
button { font: inherit; }
|
|
47
|
+
</style>
|
|
48
|
+
</head>
|
|
49
|
+
<body>
|
|
50
|
+
<h1>Sign in to ${product}</h1>
|
|
51
|
+
<p><strong>${toHTMLText(view.clientName)}</strong> wants access to your ${product} data.</p>
|
|
52
|
+
<p>After approval it returns to <code>${toHTMLText(view.redirectURI)}</code>.</p>
|
|
53
|
+
<p>Sign in with your passkey. You choose what to allow on the next page.</p>
|
|
54
|
+
${error}
|
|
55
|
+
${signIn}
|
|
56
|
+
</body>
|
|
57
|
+
</html>
|
|
58
|
+
`;
|
|
59
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { sql } from 'kysely';
|
|
2
|
+
import type { Store } from '../store/open-store.ts';
|
|
3
|
+
import type { PasskeyID } from '../types.ts';
|
|
4
|
+
|
|
5
|
+
interface PasskeyUse {
|
|
6
|
+
readonly id: PasskeyID;
|
|
7
|
+
|
|
8
|
+
// The counter the verification read, which the passkey must still hold, so
|
|
9
|
+
// a passkey removed during the verification, or a concurrent assertion that
|
|
10
|
+
// stored a newer counter, makes this use fail.
|
|
11
|
+
readonly counter: number;
|
|
12
|
+
readonly newCounter: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function updatePasskeyUse(store: Store, use: PasskeyUse): Promise<boolean> {
|
|
16
|
+
const now = new Date(store.options.clock.now()).toISOString();
|
|
17
|
+
|
|
18
|
+
const stored =
|
|
19
|
+
await sql`update ${sql.table(store.options.tables.passkey)} set counter = ${use.newCounter}, last_used_at = ${now} where id = ${use.id} and counter = ${use.counter}`.execute(
|
|
20
|
+
store.db,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return (stored.numAffectedRows ?? 0n) > 0n;
|
|
24
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { verifyAuthenticationResponse } from '@simplewebauthn/server';
|
|
2
|
+
import type {
|
|
3
|
+
AuthenticationResponseJSON,
|
|
4
|
+
VerifiedAuthenticationResponse,
|
|
5
|
+
} from '@simplewebauthn/server';
|
|
6
|
+
import { toTagged } from '@zgeoff/std';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import type { Store } from '../store/open-store.ts';
|
|
9
|
+
import type { PasskeyID } from '../types.ts';
|
|
10
|
+
import { parseJSONStrings } from '../utils/parse-json-strings.ts';
|
|
11
|
+
import { readPasskeyRows } from './read-passkey-rows.ts';
|
|
12
|
+
import { updatePasskeyUse } from './update-passkey-use.ts';
|
|
13
|
+
|
|
14
|
+
interface AssertionCheck {
|
|
15
|
+
// The credential JSON the sign-in page posted.
|
|
16
|
+
readonly credential: string;
|
|
17
|
+
|
|
18
|
+
// The challenge the page was given, which the caller has already taken.
|
|
19
|
+
readonly challenge: string;
|
|
20
|
+
readonly origin: string;
|
|
21
|
+
readonly rpID: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function verifyPasskeyAssertion(
|
|
25
|
+
store: Store,
|
|
26
|
+
check: AssertionCheck,
|
|
27
|
+
): Promise<PasskeyID | null> {
|
|
28
|
+
const response = parseAssertion(check.credential);
|
|
29
|
+
|
|
30
|
+
if (response === null) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const [passkey] = await readPasskeyRows(store.db, store.options.tables.passkey, response.id);
|
|
35
|
+
|
|
36
|
+
if (passkey === undefined) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let verified: VerifiedAuthenticationResponse;
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
verified = await verifyAuthenticationResponse({
|
|
44
|
+
response,
|
|
45
|
+
expectedChallenge: check.challenge,
|
|
46
|
+
expectedOrigin: check.origin,
|
|
47
|
+
expectedRPID: check.rpID,
|
|
48
|
+
expectedType: 'webauthn.get',
|
|
49
|
+
requireUserVerification: true,
|
|
50
|
+
credential: {
|
|
51
|
+
id: passkey.id,
|
|
52
|
+
publicKey: new Uint8Array(Buffer.from(passkey.public_key, 'base64url')),
|
|
53
|
+
counter: passkey.counter,
|
|
54
|
+
transports: (parseJSONStrings(passkey.transports) ?? []).flatMap((transport) =>
|
|
55
|
+
isTransport(transport) ? [transport] : [],
|
|
56
|
+
),
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
} catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!verified.verified || !verified.authenticationInfo.userVerified) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const stored = await updatePasskeyUse(store, {
|
|
68
|
+
id: toTagged<PasskeyID>(passkey.id),
|
|
69
|
+
counter: passkey.counter,
|
|
70
|
+
newCounter: verified.authenticationInfo.newCounter,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return stored ? toTagged<PasskeyID>(passkey.id) : null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const AssertionSchema = z.object({
|
|
77
|
+
id: z.string().min(1),
|
|
78
|
+
rawId: z.string().min(1),
|
|
79
|
+
type: z.literal('public-key'),
|
|
80
|
+
response: z.object({
|
|
81
|
+
clientDataJSON: z.string(),
|
|
82
|
+
authenticatorData: z.string(),
|
|
83
|
+
signature: z.string(),
|
|
84
|
+
userHandle: z.string().optional(),
|
|
85
|
+
}),
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// The posted JSON when it has the shape of an authentication response, else
|
|
89
|
+
// null; the verifier checks every value.
|
|
90
|
+
function parseAssertion(credential: string): AuthenticationResponseJSON | null {
|
|
91
|
+
let parsed: unknown;
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
parsed = JSON.parse(credential);
|
|
95
|
+
} catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const result = AssertionSchema.safeParse(parsed);
|
|
100
|
+
|
|
101
|
+
if (!result.success) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const { userHandle, ...response } = result.data.response;
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
id: result.data.id,
|
|
109
|
+
rawId: result.data.rawId,
|
|
110
|
+
type: result.data.type,
|
|
111
|
+
response: userHandle === undefined ? response : { ...response, userHandle },
|
|
112
|
+
clientExtensionResults: {},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const TRANSPORTS = ['ble', 'cable', 'hybrid', 'internal', 'nfc', 'smart-card', 'usb'] as const;
|
|
117
|
+
|
|
118
|
+
function isTransport(value: string): value is (typeof TRANSPORTS)[number] {
|
|
119
|
+
return TRANSPORTS.some((transport) => transport === value);
|
|
120
|
+
}
|