Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

auth.ts

560 lines20.8 KB

1import * as Schema from "effect/Schema";
2import * as HttpApiSchema from "effect/http-api/HttpApiSchema";
3​
4import {
5 AuthSessionId,
6 ForwardCompatibleArray,
7 ClientSurface,
8 ClientWebDeployment,
9 TrimmedNonEmptyString,
10} from "./baseSchemas.ts";
11​
12export const ServerAuthPolicy = Schema.Literals([
13 "desktop-managed-local",
14 "loopback-browser",
15 "remote-reachable",
16 "unsafe-no-auth",
17]);
18export type ServerAuthPolicy = typeof ServerAuthPolicy.Type;
19​
20export const ServerAuthBootstrapMethod = Schema.Literals(["desktop-bootstrap", "one-time-token"]);
21export type ServerAuthBootstrapMethod = typeof ServerAuthBootstrapMethod.Type;
22​
23export const ServerAuthSessionMethod = Schema.Literals([
24 "browser-session-cookie",
25 "bearer-access-token",
26 "dpop-access-token",
27]);
28export type ServerAuthSessionMethod = typeof ServerAuthSessionMethod.Type;
29​
30export const AuthOrchestrationReadScope = "orchestration:read" as const;
31export const AuthOrchestrationOperateScope = "orchestration:operate" as const;
32export const AuthSettingsWriteScope = "settings:write" as const;
33export const AuthProvidersManageScope = "providers:manage" as const;
34export const AuthEnvironmentMaintainScope = "environment:maintain" as const;
35export const AuthPreviewOperateScope = "preview:operate" as const;
36export const AuthDiagnosticsReadScope = "diagnostics:read" as const;
37export const AuthTerminalReadScope = "terminal:read" as const;
38export const AuthTerminalOperateScope = "terminal:operate" as const;
39export const AuthSourceControlWriteScope = "source-control:write" as const;
40export const AuthFilesystemReadScope = "filesystem:read" as const;
41export const AuthFilesystemWriteScope = "filesystem:write" as const;
42/** Retained for decoding existing credentials; grants no current RPC access. */
43const AuthReviewWriteScope = "review:write" as const;
44export const AuthAccessReadScope = "access:read" as const;
45export const AuthAccessWriteScope = "access:write" as const;
46export const AuthRelayReadScope = "relay:read" as const;
47export const AuthRelayWriteScope = "relay:write" as const;
48export const AuthEnvironmentScope = Schema.Literals([
49 AuthOrchestrationReadScope,
50 AuthOrchestrationOperateScope,
51 AuthSettingsWriteScope,
52 AuthProvidersManageScope,
53 AuthEnvironmentMaintainScope,
54 AuthPreviewOperateScope,
55 AuthDiagnosticsReadScope,
56 AuthTerminalReadScope,
57 AuthTerminalOperateScope,
58 AuthFilesystemReadScope,
59 AuthFilesystemWriteScope,
60 AuthReviewWriteScope,
61 AuthSourceControlWriteScope,
62 AuthAccessReadScope,
63 AuthAccessWriteScope,
64 AuthRelayReadScope,
65 AuthRelayWriteScope,
66]);
67export type AuthEnvironmentScope = typeof AuthEnvironmentScope.Type;
68export const AuthEnvironmentScopes = Schema.Array(AuthEnvironmentScope);
69export type AuthEnvironmentScopes = typeof AuthEnvironmentScopes.Type;
70​
71export const AuthGrantScope = Schema.Literals(
72 AuthEnvironmentScope.literals.filter((scope) => scope !== AuthReviewWriteScope),
73);
74export type AuthGrantScope = typeof AuthGrantScope.Type;
75export const AuthGrantScopes = Schema.Array(AuthGrantScope);
76export type AuthGrantScopes = typeof AuthGrantScopes.Type;
77​
78const legacyScopes = new Set<AuthEnvironmentScope>([
79 AuthOrchestrationReadScope,
80 AuthOrchestrationOperateScope,
81 AuthTerminalOperateScope,
82 AuthReviewWriteScope,
83 AuthAccessReadScope,
84 AuthAccessWriteScope,
85 AuthRelayReadScope,
86 AuthRelayWriteScope,
87]);
88​
89export function authScopeResponse(scopes: ReadonlyArray<AuthEnvironmentScope>) {
90 return { scopes: scopes.filter((scope) => legacyScopes.has(scope)), permissions: scopes };
92​
93const authScopeResponseFields = {
94 scopes: AuthEnvironmentScopes,
95 permissions: Schema.optionalKey(ForwardCompatibleArray(AuthEnvironmentScope)),
96};
97​
98// Client-only fallback for old servers. Servers never expand grants; empty permissions grant nothing.
99const legacyParents: Partial<Record<AuthEnvironmentScope, AuthEnvironmentScope>> = {
100 [AuthFilesystemReadScope]: AuthOrchestrationReadScope,
101 [AuthDiagnosticsReadScope]: AuthOrchestrationReadScope,
102 [AuthSettingsWriteScope]: AuthOrchestrationOperateScope,
103 [AuthProvidersManageScope]: AuthOrchestrationOperateScope,
104 [AuthEnvironmentMaintainScope]: AuthOrchestrationOperateScope,
105 [AuthPreviewOperateScope]: AuthOrchestrationOperateScope,
106 [AuthSourceControlWriteScope]: AuthOrchestrationOperateScope,
107 [AuthFilesystemWriteScope]: AuthOrchestrationOperateScope,
108 [AuthTerminalReadScope]: AuthTerminalOperateScope,
109};
110​
111/** Keep permission denials decodable by clients with the original scope enum. */
112export function authScopeRequiredResponse(requiredPermission: AuthEnvironmentScope) {
113 return {
114 requiredScope: legacyParents[requiredPermission] ?? requiredPermission,
115 requiredPermission,
116 };
118​
119export interface SessionGrantInput {
120 readonly authenticated: boolean;
121 readonly scopes?: ReadonlyArray<AuthEnvironmentScope> | undefined;
122 readonly permissions?: ReadonlyArray<AuthEnvironmentScope> | undefined;
123 readonly auth?: { readonly serverUpdateScope?: string | undefined } | undefined;
125​
126export function sessionGrantsScope(
127 session: SessionGrantInput,
128 scope: AuthEnvironmentScope,
129): boolean {
130 if (!session.authenticated) return false;
131 if (session.permissions !== undefined) return session.permissions.includes(scope);
132 if (session.scopes?.includes(scope)) return true;
133 if (session.auth?.serverUpdateScope !== undefined) return false;
134 const parent = legacyParents[scope];
135 return parent !== undefined && session.scopes?.includes(parent) === true;
137​
138export function sessionHasLegacyPermissions(session: SessionGrantInput): boolean {
139 const permissions = session.permissions;
140 return (
141 session.authenticated &&
142 permissions !== undefined &&
143 permissions.every((scope) => legacyScopes.has(scope)) &&
144 Object.values(legacyParents).some((parent) => permissions.includes(parent))
145 );
147​
148// Shell and full-access agent scopes already confer access and relay authority.
149export const AuthStandardClientScopes = [
150 AuthOrchestrationReadScope,
151 AuthOrchestrationOperateScope,
152 AuthSettingsWriteScope,
153 AuthProvidersManageScope,
154 AuthEnvironmentMaintainScope,
155 AuthPreviewOperateScope,
156 AuthDiagnosticsReadScope,
157 AuthTerminalReadScope,
158 AuthTerminalOperateScope,
159 AuthSourceControlWriteScope,
160 AuthFilesystemReadScope,
161 AuthFilesystemWriteScope,
162 AuthRelayReadScope,
163 AuthAccessReadScope,
164 AuthAccessWriteScope,
165 AuthRelayWriteScope,
166] as const;
167​
168export const AuthTokenExchangeGrantType =
169 "urn:ietf:params:oauth:grant-type:token-exchange" as const;
170export const AuthAccessTokenType = "urn:ietf:params:oauth:token-type:access_token" as const;
171export const AuthEnvironmentBootstrapTokenType =
172 "urn:t3:params:oauth:token-type:environment-bootstrap" as const;
173​
174export const ServerAuthDescriptor = Schema.Struct({
175 policy: ServerAuthPolicy,
176 bootstrapMethods: Schema.Array(ServerAuthBootstrapMethod),
177 sessionMethods: Schema.Array(ServerAuthSessionMethod),
178 sessionCookieName: TrimmedNonEmptyString,
179 /** Older servers omit this and authorize self-updates with orchestration:operate. */
180 serverUpdateScope: Schema.optionalKey(Schema.Literal(AuthEnvironmentMaintainScope)),
181});
182export type ServerAuthDescriptor = typeof ServerAuthDescriptor.Type;
183​
184export const AuthBrowserSessionRequest = Schema.Struct({
185 credential: TrimmedNonEmptyString,
186});
187export type AuthBrowserSessionRequest = typeof AuthBrowserSessionRequest.Type;
188​
189export const AuthBrowserSessionResult = Schema.Struct({
190 authenticated: Schema.Literal(true),
191 ...authScopeResponseFields,
192 sessionMethod: ServerAuthSessionMethod,
193 expiresAt: Schema.DateTimeUtc,
194});
195export type AuthBrowserSessionResult = typeof AuthBrowserSessionResult.Type;
196​
197export const AuthClientMetadataDeviceType = Schema.Literals([
198 "desktop",
199 "mobile",
200 "tablet",
201 "bot",
202 "unknown",
203]);
204export type AuthClientMetadataDeviceType = typeof AuthClientMetadataDeviceType.Type;
205​
206export const AuthClientPresentationMetadata = Schema.Struct({
207 label: Schema.optionalKey(TrimmedNonEmptyString),
208 deviceType: Schema.optionalKey(AuthClientMetadataDeviceType),
209 os: Schema.optionalKey(TrimmedNonEmptyString),
210 osMajorVersion: Schema.optionalKey(Schema.Int),
211 deviceModel: Schema.optionalKey(TrimmedNonEmptyString),
212 surface: Schema.optionalKey(ClientSurface),
213 webDeployment: Schema.optionalKey(ClientWebDeployment),
214 browser: Schema.optionalKey(TrimmedNonEmptyString),
215 appVersion: Schema.optionalKey(TrimmedNonEmptyString),
216});
217export type AuthClientPresentationMetadata = typeof AuthClientPresentationMetadata.Type;
218​
219export const AuthTokenExchangeRequest = Schema.Struct({
220 grant_type: Schema.Literal(AuthTokenExchangeGrantType),
221 subject_token: TrimmedNonEmptyString,
222 subject_token_type: Schema.Literal(AuthEnvironmentBootstrapTokenType),
223 requested_token_type: Schema.Literal(AuthAccessTokenType),
224 scope: Schema.optionalKey(TrimmedNonEmptyString),
225 client_label: Schema.optionalKey(TrimmedNonEmptyString),
226 client_device_type: Schema.optionalKey(AuthClientMetadataDeviceType),
227 client_os: Schema.optionalKey(TrimmedNonEmptyString),
228}).pipe(HttpApiSchema.asFormUrlEncoded());
229export type AuthTokenExchangeRequest = typeof AuthTokenExchangeRequest.Type;
230​
231export const AuthAccessTokenResult = Schema.Struct({
232 access_token: TrimmedNonEmptyString,
233 issued_token_type: Schema.Literal(AuthAccessTokenType),
234 token_type: Schema.Literals(["Bearer", "DPoP"]),
235 expires_in: Schema.Number,
236 scope: TrimmedNonEmptyString,
237});
238export type AuthAccessTokenResult = typeof AuthAccessTokenResult.Type;
239​
240export const AuthWebSocketTicketResult = Schema.Struct({
241 ticket: TrimmedNonEmptyString,
242 expiresAt: Schema.DateTimeUtc,
243});
244export type AuthWebSocketTicketResult = typeof AuthWebSocketTicketResult.Type;
245​
246/**
247 * Media routes share a ticket across requests; RPC uses a separate ticket.
248 * Use a path segment so the DPoP mint proof covers it; `htu` excludes query parameters,
249 * which could be stripped to change the ticket's use.
250 * Older clients mint at the bare path and receive tickets valid for either use.
251 */
252export const AuthWebSocketTicketUse = Schema.Literals(["rpc", "media"]);
253export type AuthWebSocketTicketUse = typeof AuthWebSocketTicketUse.Type;
254​
255export const AuthWebSocketTicketParams = Schema.Struct({ use: AuthWebSocketTicketUse });
256​
257export const AuthPairingCredentialResult = Schema.Struct({
258 id: TrimmedNonEmptyString,
259 credential: TrimmedNonEmptyString,
260 label: Schema.optionalKey(TrimmedNonEmptyString),
261 expiresAt: Schema.DateTimeUtc,
262});
263export type AuthPairingCredentialResult = typeof AuthPairingCredentialResult.Type;
264​
265export const AuthPairingLink = Schema.Struct({
266 id: TrimmedNonEmptyString,
267 ...authScopeResponseFields,
268 subject: TrimmedNonEmptyString,
269 label: Schema.optionalKey(TrimmedNonEmptyString),
270 createdAt: Schema.DateTimeUtc,
271 expiresAt: Schema.DateTimeUtc,
272});
273export type AuthPairingLink = typeof AuthPairingLink.Type;
274​
275export const AuthClientMetadata = Schema.Struct({
276 label: Schema.optionalKey(TrimmedNonEmptyString),
277 ipAddress: Schema.optionalKey(TrimmedNonEmptyString),
278 userAgent: Schema.optionalKey(TrimmedNonEmptyString),
279 deviceType: AuthClientMetadataDeviceType,
280 os: Schema.optionalKey(TrimmedNonEmptyString),
281 browser: Schema.optionalKey(TrimmedNonEmptyString),
282});
283export type AuthClientMetadata = typeof AuthClientMetadata.Type;
284​
285export const AuthClientSession = Schema.Struct({
286 sessionId: AuthSessionId,
287 subject: TrimmedNonEmptyString,
288 ...authScopeResponseFields,
289 method: ServerAuthSessionMethod,
290 client: AuthClientMetadata,
291 issuedAt: Schema.DateTimeUtc,
292 expiresAt: Schema.DateTimeUtc,
293 lastConnectedAt: Schema.NullOr(Schema.DateTimeUtc),
294 connected: Schema.Boolean,
295 current: Schema.Boolean,
296});
297export type AuthClientSession = typeof AuthClientSession.Type;
298​
299export const AuthAccessSnapshot = Schema.Struct({
300 pairingLinks: Schema.Array(AuthPairingLink),
301 clientSessions: Schema.Array(AuthClientSession),
302});
303export type AuthAccessSnapshot = typeof AuthAccessSnapshot.Type;
304​
305export const AuthAccessStreamSnapshotEvent = Schema.Struct({
306 version: Schema.Literal(1),
307 revision: Schema.Number,
308 type: Schema.Literal("snapshot"),
309 payload: AuthAccessSnapshot,
310});
311export type AuthAccessStreamSnapshotEvent = typeof AuthAccessStreamSnapshotEvent.Type;
312​
313export const AuthAccessStreamPairingLinkUpsertedEvent = Schema.Struct({
314 version: Schema.Literal(1),
315 revision: Schema.Number,
316 type: Schema.Literal("pairingLinkUpserted"),
317 payload: AuthPairingLink,
318});
319export type AuthAccessStreamPairingLinkUpsertedEvent =
320 typeof AuthAccessStreamPairingLinkUpsertedEvent.Type;
321​
322export const AuthAccessStreamPairingLinkRemovedEvent = Schema.Struct({
323 version: Schema.Literal(1),
324 revision: Schema.Number,
325 type: Schema.Literal("pairingLinkRemoved"),
326 payload: Schema.Struct({
327 id: TrimmedNonEmptyString,
328 }),
329});
330export type AuthAccessStreamPairingLinkRemovedEvent =
331 typeof AuthAccessStreamPairingLinkRemovedEvent.Type;
332​
333export class AuthAccessStreamError extends Schema.TaggedError<AuthAccessStreamError>()(
334 "AuthAccessStreamError",
335 {
336 message: Schema.String,
337 },
338) {}
339​
340export class EnvironmentAuthorizationError extends Schema.TaggedError<EnvironmentAuthorizationError>()(
341 "EnvironmentAuthorizationError",
342 {
343 message: Schema.String,
344 requiredScope: AuthEnvironmentScope,
345 requiredPermission: Schema.optionalKey(Schema.String),
346 },
347) {}
348​
349export const AuthAccessStreamClientUpsertedEvent = Schema.Struct({
350 version: Schema.Literal(1),
351 revision: Schema.Number,
352 type: Schema.Literal("clientUpserted"),
353 payload: AuthClientSession,
354});
355export type AuthAccessStreamClientUpsertedEvent = typeof AuthAccessStreamClientUpsertedEvent.Type;
356​
357export const AuthAccessStreamClientRemovedEvent = Schema.Struct({
358 version: Schema.Literal(1),
359 revision: Schema.Number,
360 type: Schema.Literal("clientRemoved"),
361 payload: Schema.Struct({
362 sessionId: AuthSessionId,
363 }),
364});
365export type AuthAccessStreamClientRemovedEvent = typeof AuthAccessStreamClientRemovedEvent.Type;
366​
367export const AuthAccessStreamEvent = Schema.Union([
368 AuthAccessStreamSnapshotEvent,
369 AuthAccessStreamPairingLinkUpsertedEvent,
370 AuthAccessStreamPairingLinkRemovedEvent,
371 AuthAccessStreamClientUpsertedEvent,
372 AuthAccessStreamClientRemovedEvent,
373]);
374export type AuthAccessStreamEvent = typeof AuthAccessStreamEvent.Type;
375​
376export const AuthRevokePairingLinkInput = Schema.Struct({
377 id: TrimmedNonEmptyString,
378});
379export type AuthRevokePairingLinkInput = typeof AuthRevokePairingLinkInput.Type;
380​
381export const AuthRevokeClientSessionInput = Schema.Struct({
382 sessionId: AuthSessionId,
383});
384export type AuthRevokeClientSessionInput = typeof AuthRevokeClientSessionInput.Type;
385​
386export const AuthCreatePairingCredentialInput = Schema.Struct({
387 label: Schema.optionalKey(TrimmedNonEmptyString),
388 scopes: Schema.optionalKey(AuthGrantScopes),
389});
390export type AuthCreatePairingCredentialInput = typeof AuthCreatePairingCredentialInput.Type;
391​
392export const AuthSessionState = Schema.Struct({
393 authenticated: Schema.Boolean,
394 auth: ServerAuthDescriptor,
395 scopes: Schema.optionalKey(AuthEnvironmentScopes),
396 permissions: authScopeResponseFields.permissions,
397 sessionMethod: Schema.optionalKey(ServerAuthSessionMethod),
398 expiresAt: Schema.optionalKey(Schema.DateTimeUtc),
399});
400export type AuthSessionState = typeof AuthSessionState.Type;
401​
402export const AuthMcpClientAccess = Schema.Literals([
403 "read-only",
404 "approval-required",
405 "auto-accept-edits",
406 "auto",
407 "full-access",
408]);
409export type AuthMcpClientAccess = typeof AuthMcpClientAccess.Type;
410​
411export const AuthMcpProtectedResourceMetadata = Schema.Struct({
412 resource: Schema.String,
413 authorization_servers: Schema.Array(Schema.String),
414 scopes_supported: Schema.Array(AuthEnvironmentScope),
415 bearer_methods_supported: Schema.Array(Schema.Literal("header")),
416 resource_name: Schema.String,
417});
418export type AuthMcpProtectedResourceMetadata = typeof AuthMcpProtectedResourceMetadata.Type;
419​
420export const AuthMcpAuthorizationServerMetadata = Schema.Struct({
421 issuer: Schema.String,
422 authorization_endpoint: Schema.String,
423 token_endpoint: Schema.String,
424 registration_endpoint: Schema.String,
425 response_types_supported: Schema.Array(Schema.Literal("code")),
426 grant_types_supported: Schema.Array(Schema.Literal("authorization_code")),
427 code_challenge_methods_supported: Schema.Array(Schema.Literal("S256")),
428 token_endpoint_auth_methods_supported: Schema.Array(Schema.Literal("none")),
429 scopes_supported: Schema.Array(AuthEnvironmentScope),
430 authorization_response_iss_parameter_supported: Schema.Boolean,
431});
432export type AuthMcpAuthorizationServerMetadata = typeof AuthMcpAuthorizationServerMetadata.Type;
433​
434/**
435 * The `software_id` another T3 Code environment registers with when it links
436 * to this one. Its session is then a peer link: the work it starts here stays
437 * within that link. Claiming it only ever adds limits.
438 */
439export const MCP_PEER_LINK_SOFTWARE_ID = "t3code-peer-link";
440​
441export const AuthMcpClientRegistration = Schema.Struct({
442 client_name: Schema.optionalKey(Schema.String),
443 software_id: Schema.optionalKey(Schema.String),
444 redirect_uris: Schema.optionalKey(Schema.Array(Schema.String)),
445 token_endpoint_auth_method: Schema.optionalKey(Schema.String),
446});
447export type AuthMcpClientRegistration = typeof AuthMcpClientRegistration.Type;
448​
449export const AuthMcpRegisteredClient = Schema.Struct({
450 client_id: Schema.String,
451 client_name: Schema.String,
452 redirect_uris: Schema.Array(Schema.String),
453 grant_types: Schema.Array(Schema.Literal("authorization_code")),
454 response_types: Schema.Array(Schema.Literal("code")),
455 token_endpoint_auth_method: Schema.Literal("none"),
456}).pipe(HttpApiSchema.status(201));
457export type AuthMcpRegisteredClient = typeof AuthMcpRegisteredClient.Type;
458​
459export class AuthMcpRegistrationError extends Schema.Error<AuthMcpRegistrationError>(
460 "AuthMcpRegistrationError",
461)(
462 {
463 error: Schema.Literals(["invalid_client_metadata", "invalid_redirect_uri"]),
464 error_description: Schema.String,
465 },
466 { httpApiStatus: 400 },
467) {
468 override get message(): string {
469 return this.error_description;
470 }
472​
473/** Fields are optional here because the server validates them. */
474export const AuthMcpAuthorizationRequest = Schema.Struct({
475 response_type: Schema.optionalKey(Schema.String),
476 client_id: Schema.optionalKey(Schema.String),
477 redirect_uri: Schema.optionalKey(Schema.String),
478 code_challenge: Schema.optionalKey(Schema.String),
479 code_challenge_method: Schema.optionalKey(Schema.String),
480 state: Schema.optionalKey(Schema.String),
481 resource: Schema.optionalKey(Schema.String),
482});
483export type AuthMcpAuthorizationRequest = typeof AuthMcpAuthorizationRequest.Type;
484​
485/** Server-validated request details, trusted by the client only for display. */
486export const AuthMcpApprovalDetails = Schema.Struct({
487 /** Self-declared by the client, so shown as such. */
488 clientName: Schema.String,
489 redirectHost: Schema.String,
490 environmentHost: Schema.String,
491 csrfToken: Schema.optionalKey(Schema.String),
492 /** Only scopes held by this session qualify; others need a pairing code. Absent with `csrfToken`. */
493 oneClickAccess: Schema.optionalKey(Schema.Array(AuthMcpClientAccess)),
494});
495export type AuthMcpApprovalDetails = typeof AuthMcpApprovalDetails.Type;
496​
497export const AuthMcpApprovalRedirect = Schema.Struct({
498 redirectTo: Schema.String,
499});
500export type AuthMcpApprovalRedirect = typeof AuthMcpApprovalRedirect.Type;
501​
502export const AuthMcpApprovalDecision = Schema.Union([
503 Schema.TaggedStruct("deny", {}),
504 Schema.TaggedStruct("pairing-code", {
505 access: AuthMcpClientAccess,
506 code: TrimmedNonEmptyString,
507 }),
508 Schema.TaggedStruct("browser-session", {
509 access: AuthMcpClientAccess,
510 csrfToken: Schema.String,
511 }),
512]);
513export type AuthMcpApprovalDecision = typeof AuthMcpApprovalDecision.Type;
514​
515export const AuthMcpApprovalDecisionRequest = Schema.Struct({
516 authorization: AuthMcpAuthorizationRequest,
517 decision: AuthMcpApprovalDecision,
518});
519export type AuthMcpApprovalDecisionRequest = typeof AuthMcpApprovalDecisionRequest.Type;
520​
521export class AuthMcpApprovalError extends Schema.TaggedError<AuthMcpApprovalError>()(
522 "AuthMcpApprovalError",
523 { message: Schema.String },
524 { httpApiStatus: 400 },
525) {}
526​
527export const AuthMcpTokenRequest = Schema.Struct({
528 grant_type: Schema.optionalKey(Schema.String),
529 code: Schema.optionalKey(Schema.String),
530 redirect_uri: Schema.optionalKey(Schema.String),
531 client_id: Schema.optionalKey(Schema.String),
532 code_verifier: Schema.optionalKey(Schema.String),
533 resource: Schema.optionalKey(Schema.String),
534}).pipe(HttpApiSchema.asFormUrlEncoded());
535export type AuthMcpTokenRequest = typeof AuthMcpTokenRequest.Type;
536​
537export const AuthMcpTokenResult = Schema.Struct({
538 access_token: Schema.String,
539 token_type: Schema.Literal("Bearer"),
540 expires_in: Schema.Number,
541 scope: Schema.String,
542});
543export type AuthMcpTokenResult = typeof AuthMcpTokenResult.Type;
544​
545export class AuthMcpTokenError extends Schema.Error<AuthMcpTokenError>("AuthMcpTokenError")(
546 {
547 error: Schema.Literals([
548 "invalid_request",
549 "invalid_client",
550 "invalid_grant",
551 "unsupported_grant_type",
552 ]),
553 error_description: Schema.String,
554 },
555 { httpApiStatus: 400 },
556) {
557 override get message(): string {
558 return this.error_description;
559 }