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

auth.ts

573 lines21.4 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​
411/** The scopes an agent session gets for an access level, and a pairing code must carry. */
412export const mcpClientScopes = (access: AuthMcpClientAccess): ReadonlyArray<AuthGrantScope> =>
413 access === "read-only"
414 ? [AuthOrchestrationReadScope]
415 : access === "full-access"
416 ? [
417 AuthOrchestrationReadScope,
418 AuthOrchestrationOperateScope,
419 AuthSettingsWriteScope,
420 AuthSourceControlWriteScope,
421 ]
422 : [AuthOrchestrationReadScope, AuthOrchestrationOperateScope];
423​
424export const AuthMcpProtectedResourceMetadata = Schema.Struct({
425 resource: Schema.String,
426 authorization_servers: Schema.Array(Schema.String),
427 scopes_supported: Schema.Array(AuthEnvironmentScope),
428 bearer_methods_supported: Schema.Array(Schema.Literal("header")),
429 resource_name: Schema.String,
430});
431export type AuthMcpProtectedResourceMetadata = typeof AuthMcpProtectedResourceMetadata.Type;
432​
433export const AuthMcpAuthorizationServerMetadata = Schema.Struct({
434 issuer: Schema.String,
435 authorization_endpoint: Schema.String,
436 token_endpoint: Schema.String,
437 registration_endpoint: Schema.String,
438 response_types_supported: Schema.Array(Schema.Literal("code")),
439 grant_types_supported: Schema.Array(Schema.Literal("authorization_code")),
440 code_challenge_methods_supported: Schema.Array(Schema.Literal("S256")),
441 token_endpoint_auth_methods_supported: Schema.Array(Schema.Literal("none")),
442 scopes_supported: Schema.Array(AuthEnvironmentScope),
443 authorization_response_iss_parameter_supported: Schema.Boolean,
444});
445export type AuthMcpAuthorizationServerMetadata = typeof AuthMcpAuthorizationServerMetadata.Type;
446​
447/**
448 * The `software_id` another T3 Code environment registers with when it links
449 * to this one. Its session is then a peer link: the work it starts here stays
450 * within that link. Claiming it only ever adds limits.
451 */
452export const MCP_PEER_LINK_SOFTWARE_ID = "t3code-peer-link";
453​
454export const AuthMcpClientRegistration = Schema.Struct({
455 client_name: Schema.optionalKey(Schema.String),
456 software_id: Schema.optionalKey(Schema.String),
457 redirect_uris: Schema.optionalKey(Schema.Array(Schema.String)),
458 token_endpoint_auth_method: Schema.optionalKey(Schema.String),
459});
460export type AuthMcpClientRegistration = typeof AuthMcpClientRegistration.Type;
461​
462export const AuthMcpRegisteredClient = Schema.Struct({
463 client_id: Schema.String,
464 client_name: Schema.String,
465 redirect_uris: Schema.Array(Schema.String),
466 grant_types: Schema.Array(Schema.Literal("authorization_code")),
467 response_types: Schema.Array(Schema.Literal("code")),
468 token_endpoint_auth_method: Schema.Literal("none"),
469}).pipe(HttpApiSchema.status(201));
470export type AuthMcpRegisteredClient = typeof AuthMcpRegisteredClient.Type;
471​
472export class AuthMcpRegistrationError extends Schema.Error<AuthMcpRegistrationError>(
473 "AuthMcpRegistrationError",
474)(
475 {
476 error: Schema.Literals(["invalid_client_metadata", "invalid_redirect_uri"]),
477 error_description: Schema.String,
478 },
479 { httpApiStatus: 400 },
480) {
481 override get message(): string {
482 return this.error_description;
483 }
485​
486/** Fields are optional here because the server validates them. */
487export const AuthMcpAuthorizationRequest = Schema.Struct({
488 response_type: Schema.optionalKey(Schema.String),
489 client_id: Schema.optionalKey(Schema.String),
490 redirect_uri: Schema.optionalKey(Schema.String),
491 code_challenge: Schema.optionalKey(Schema.String),
492 code_challenge_method: Schema.optionalKey(Schema.String),
493 state: Schema.optionalKey(Schema.String),
494 resource: Schema.optionalKey(Schema.String),
495});
496export type AuthMcpAuthorizationRequest = typeof AuthMcpAuthorizationRequest.Type;
497​
498/** Server-validated request details, trusted by the client only for display. */
499export const AuthMcpApprovalDetails = Schema.Struct({
500 /** Self-declared by the client, so shown as such. */
501 clientName: Schema.String,
502 redirectHost: Schema.String,
503 environmentHost: Schema.String,
504 csrfToken: Schema.optionalKey(Schema.String),
505 /** Only scopes held by this session qualify; others need a pairing code. Absent with `csrfToken`. */
506 oneClickAccess: Schema.optionalKey(Schema.Array(AuthMcpClientAccess)),
507});
508export type AuthMcpApprovalDetails = typeof AuthMcpApprovalDetails.Type;
509​
510export const AuthMcpApprovalRedirect = Schema.Struct({
511 redirectTo: Schema.String,
512});
513export type AuthMcpApprovalRedirect = typeof AuthMcpApprovalRedirect.Type;
514​
515export const AuthMcpApprovalDecision = Schema.Union([
516 Schema.TaggedStruct("deny", {}),
517 Schema.TaggedStruct("pairing-code", {
518 access: AuthMcpClientAccess,
519 code: TrimmedNonEmptyString,
520 }),
521 Schema.TaggedStruct("browser-session", {
522 access: AuthMcpClientAccess,
523 csrfToken: Schema.String,
524 }),
525]);
526export type AuthMcpApprovalDecision = typeof AuthMcpApprovalDecision.Type;
527​
528export const AuthMcpApprovalDecisionRequest = Schema.Struct({
529 authorization: AuthMcpAuthorizationRequest,
530 decision: AuthMcpApprovalDecision,
531});
532export type AuthMcpApprovalDecisionRequest = typeof AuthMcpApprovalDecisionRequest.Type;
533​
534export class AuthMcpApprovalError extends Schema.TaggedError<AuthMcpApprovalError>()(
535 "AuthMcpApprovalError",
536 { message: Schema.String },
537 { httpApiStatus: 400 },
538) {}
539​
540export const AuthMcpTokenRequest = Schema.Struct({
541 grant_type: Schema.optionalKey(Schema.String),
542 code: Schema.optionalKey(Schema.String),
543 redirect_uri: Schema.optionalKey(Schema.String),
544 client_id: Schema.optionalKey(Schema.String),
545 code_verifier: Schema.optionalKey(Schema.String),
546 resource: Schema.optionalKey(Schema.String),
547}).pipe(HttpApiSchema.asFormUrlEncoded());
548export type AuthMcpTokenRequest = typeof AuthMcpTokenRequest.Type;
549​
550export const AuthMcpTokenResult = Schema.Struct({
551 access_token: Schema.String,
552 token_type: Schema.Literal("Bearer"),
553 expires_in: Schema.Number,
554 scope: Schema.String,
555});
556export type AuthMcpTokenResult = typeof AuthMcpTokenResult.Type;
557​
558export class AuthMcpTokenError extends Schema.Error<AuthMcpTokenError>("AuthMcpTokenError")(
559 {
560 error: Schema.Literals([
561 "invalid_request",
562 "invalid_client",
563 "invalid_grant",
564 "unsupported_grant_type",
565 ]),
566 error_description: Schema.String,
567 },
568 { httpApiStatus: 400 },
569) {
570 override get message(): string {
571 return this.error_description;
572 }