fastmcp 3.23.0 → 3.24.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.
@@ -0,0 +1,445 @@
1
+ import { O as OAuthProxy, a as OAuthProviderConfig, b as OAuthTransaction, C as ConsentData, T as TokenStorage, c as TokenVerifier, d as TokenVerificationResult, P as PKCEPair } from '../OAuthProxy-BOCkkAhO.js';
2
+ export { A as AuthorizationParams, f as ClientCode, D as DCRClientMetadata, g as DCRRequest, h as DCRResponse, i as OAuthError, j as OAuthProxyConfig, e as OAuthProxyError, k as ProxyDCRClient, R as RefreshRequest, l as TokenMapping, m as TokenRequest, n as TokenResponse, U as UpstreamTokenSet } from '../OAuthProxy-BOCkkAhO.js';
3
+
4
+ /**
5
+ * Microsoft Azure/Entra ID OAuth Provider
6
+ * Pre-configured OAuth Proxy for Microsoft Identity Platform
7
+ */
8
+
9
+ interface AzureProviderConfig extends OAuthProviderConfig {
10
+ /** Azure AD tenant ID or 'common', 'organizations', 'consumers' */
11
+ tenantId?: string;
12
+ }
13
+ /**
14
+ * Microsoft Azure AD / Entra ID OAuth 2.0 Provider
15
+ * Supports Microsoft accounts and organizational accounts
16
+ */
17
+ declare class AzureProvider extends OAuthProxy {
18
+ constructor(config: AzureProviderConfig);
19
+ }
20
+
21
+ /**
22
+ * GitHub OAuth Provider
23
+ * Pre-configured OAuth Proxy for GitHub OAuth Apps
24
+ */
25
+
26
+ /**
27
+ * GitHub OAuth 2.0 Provider
28
+ * Supports GitHub OAuth Apps
29
+ */
30
+ declare class GitHubProvider extends OAuthProxy {
31
+ constructor(config: OAuthProviderConfig);
32
+ }
33
+
34
+ /**
35
+ * Google OAuth Provider
36
+ * Pre-configured OAuth Proxy for Google Identity Platform
37
+ */
38
+
39
+ /**
40
+ * Google OAuth 2.0 Provider
41
+ * Supports Google Sign-In and Google APIs
42
+ */
43
+ declare class GoogleProvider extends OAuthProxy {
44
+ constructor(config: OAuthProviderConfig);
45
+ }
46
+
47
+ /**
48
+ * Consent Management
49
+ * Handles user consent flow for OAuth authorization
50
+ */
51
+
52
+ /**
53
+ * Manages consent screens and cookie signing
54
+ */
55
+ declare class ConsentManager {
56
+ private signingKey;
57
+ constructor(signingKey: string);
58
+ /**
59
+ * Create HTTP response with consent screen
60
+ */
61
+ createConsentResponse(transaction: OAuthTransaction, provider: string): Response;
62
+ /**
63
+ * Generate HTML for consent screen
64
+ */
65
+ generateConsentScreen(data: ConsentData): string;
66
+ /**
67
+ * Sign consent data for cookie
68
+ */
69
+ signConsentCookie(data: ConsentData): string;
70
+ /**
71
+ * Validate and parse consent cookie
72
+ */
73
+ validateConsentCookie(cookie: string): ConsentData | null;
74
+ /**
75
+ * Escape HTML to prevent XSS
76
+ */
77
+ private escapeHtml;
78
+ /**
79
+ * Format scope for display
80
+ */
81
+ private formatScope;
82
+ /**
83
+ * Generate default signing key if none provided
84
+ */
85
+ private generateDefaultKey;
86
+ /**
87
+ * Sign a payload using HMAC-SHA256
88
+ */
89
+ private sign;
90
+ }
91
+
92
+ /**
93
+ * Disk-based Token Storage Implementation
94
+ * Provides persistent file-based storage for OAuth tokens and transaction state
95
+ */
96
+
97
+ interface DiskStoreOptions {
98
+ /**
99
+ * How often to run cleanup (in milliseconds)
100
+ * @default 60000 (1 minute)
101
+ */
102
+ cleanupIntervalMs?: number;
103
+ /**
104
+ * Directory path for storing data
105
+ */
106
+ directory: string;
107
+ /**
108
+ * File extension for stored files
109
+ * @default ".json"
110
+ */
111
+ fileExtension?: string;
112
+ }
113
+ /**
114
+ * Disk-based token storage with TTL support
115
+ * Persists tokens to filesystem for survival across server restarts
116
+ */
117
+ declare class DiskStore implements TokenStorage {
118
+ private cleanupInterval;
119
+ private directory;
120
+ private fileExtension;
121
+ constructor(options: DiskStoreOptions);
122
+ /**
123
+ * Clean up expired entries
124
+ */
125
+ cleanup(): Promise<void>;
126
+ /**
127
+ * Delete a value
128
+ */
129
+ delete(key: string): Promise<void>;
130
+ /**
131
+ * Destroy the storage and clear cleanup interval
132
+ */
133
+ destroy(): void;
134
+ /**
135
+ * Retrieve a value
136
+ */
137
+ get(key: string): Promise<null | unknown>;
138
+ /**
139
+ * Save a value with optional TTL
140
+ */
141
+ save(key: string, value: unknown, ttl?: number): Promise<void>;
142
+ /**
143
+ * Get the number of stored items
144
+ */
145
+ size(): Promise<number>;
146
+ /**
147
+ * Ensure storage directory exists
148
+ */
149
+ private ensureDirectory;
150
+ /**
151
+ * Get file path for a key
152
+ */
153
+ private getFilePath;
154
+ }
155
+
156
+ /**
157
+ * JWT Issuer for OAuth Proxy
158
+ * Issues and validates short-lived JWTs that reference upstream provider tokens
159
+ */
160
+ /**
161
+ * JWT Claims for FastMCP tokens
162
+ */
163
+ interface JWTClaims {
164
+ /** Additional custom claims from upstream tokens */
165
+ [key: string]: unknown;
166
+ /** Audience */
167
+ aud: string;
168
+ /** Client ID */
169
+ client_id: string;
170
+ /** Expiration time (seconds since epoch) */
171
+ exp: number;
172
+ /** Issued at time (seconds since epoch) */
173
+ iat: number;
174
+ /** Issuer */
175
+ iss: string;
176
+ /** JWT ID (unique identifier) */
177
+ jti: string;
178
+ /** Scopes */
179
+ scope: string[];
180
+ }
181
+ /**
182
+ * JWT Issuer configuration
183
+ */
184
+ interface JWTIssuerConfig {
185
+ /** Token expiration in seconds (default: 3600 = 1 hour) */
186
+ accessTokenTtl?: number;
187
+ /** Audience for issued tokens */
188
+ audience: string;
189
+ /** Issuer identifier */
190
+ issuer: string;
191
+ /** Refresh token expiration in seconds (default: 2592000 = 30 days) */
192
+ refreshTokenTtl?: number;
193
+ /** Secret key for signing tokens */
194
+ signingKey: string;
195
+ }
196
+ /**
197
+ * Token validation result
198
+ */
199
+ interface TokenValidationResult {
200
+ /** Decoded claims if valid */
201
+ claims?: JWTClaims;
202
+ /** Error message if invalid */
203
+ error?: string;
204
+ /** Whether token is valid */
205
+ valid: boolean;
206
+ }
207
+ /**
208
+ * JWT Issuer
209
+ * Issues and validates HS256-signed JWTs for the OAuth proxy
210
+ */
211
+ declare class JWTIssuer {
212
+ private accessTokenTtl;
213
+ private audience;
214
+ private issuer;
215
+ private refreshTokenTtl;
216
+ private signingKey;
217
+ constructor(config: JWTIssuerConfig);
218
+ /**
219
+ * Derive a signing key from a secret
220
+ * Uses PBKDF2 for key derivation
221
+ */
222
+ static deriveKey(secret: string, iterations?: number): Promise<string>;
223
+ /**
224
+ * Issue an access token
225
+ */
226
+ issueAccessToken(clientId: string, scope: string[], additionalClaims?: Record<string, unknown>): string;
227
+ /**
228
+ * Issue a refresh token
229
+ */
230
+ issueRefreshToken(clientId: string, scope: string[], additionalClaims?: Record<string, unknown>): string;
231
+ /**
232
+ * Validate a JWT token
233
+ */
234
+ verify(token: string): Promise<TokenValidationResult>;
235
+ /**
236
+ * Generate unique JWT ID
237
+ */
238
+ private generateJti;
239
+ /**
240
+ * Sign data with HMAC-SHA256
241
+ */
242
+ private sign;
243
+ /**
244
+ * Sign a JWT token
245
+ */
246
+ private signToken;
247
+ }
248
+
249
+ /**
250
+ * JWKS (JSON Web Key Set) Verifier
251
+ * Provides JWT verification using public keys from JWKS endpoints
252
+ *
253
+ * Requires the 'jose' package as an optional peer dependency.
254
+ * Install with: npm install jose
255
+ */
256
+
257
+ /**
258
+ * Token verification result
259
+ */
260
+ interface JWKSVerificationResult {
261
+ claims?: JWTClaims;
262
+ error?: string;
263
+ valid: boolean;
264
+ }
265
+ /**
266
+ * JWKS configuration options
267
+ */
268
+ interface JWKSVerifierConfig {
269
+ /**
270
+ * Expected token audience
271
+ */
272
+ audience?: string;
273
+ /**
274
+ * Cache duration for JWKS keys in milliseconds
275
+ * @default 3600000 (1 hour)
276
+ */
277
+ cacheDuration?: number;
278
+ /**
279
+ * Cooldown duration between JWKS refetches in milliseconds
280
+ * @default 30000 (30 seconds)
281
+ */
282
+ cooldownDuration?: number;
283
+ /**
284
+ * Expected token issuer
285
+ */
286
+ issuer?: string;
287
+ /**
288
+ * JWKS endpoint URL (e.g., https://provider.com/.well-known/jwks.json)
289
+ */
290
+ jwksUri: string;
291
+ }
292
+ /**
293
+ * JWKS Verifier
294
+ * Verifies JWTs using public keys from a JWKS endpoint
295
+ *
296
+ * This class requires the 'jose' package to be installed:
297
+ * ```bash
298
+ * npm install jose
299
+ * ```
300
+ *
301
+ * @example
302
+ * ```typescript
303
+ * const verifier = new JWKSVerifier({
304
+ * jwksUri: 'https://accounts.google.com/.well-known/jwks.json',
305
+ * audience: 'your-client-id',
306
+ * issuer: 'https://accounts.google.com'
307
+ * });
308
+ *
309
+ * const result = await verifier.verify(token);
310
+ * if (result.valid) {
311
+ * console.log('Token claims:', result.claims);
312
+ * }
313
+ * ```
314
+ */
315
+ declare class JWKSVerifier implements TokenVerifier {
316
+ private config;
317
+ private jose;
318
+ private joseLoaded;
319
+ private jwksCache;
320
+ constructor(config: JWKSVerifierConfig);
321
+ /**
322
+ * Get the JWKS URI being used
323
+ */
324
+ getJwksUri(): string;
325
+ /**
326
+ * Refresh the JWKS cache
327
+ * Useful if you need to force a key refresh
328
+ */
329
+ refreshKeys(): Promise<void>;
330
+ /**
331
+ * Verify a JWT token using JWKS
332
+ *
333
+ * @param token - The JWT token to verify
334
+ * @returns Verification result with claims if valid
335
+ *
336
+ * @example
337
+ * ```typescript
338
+ * const result = await verifier.verify(token);
339
+ * if (result.valid) {
340
+ * console.log('User:', result.claims?.client_id);
341
+ * } else {
342
+ * console.error('Invalid token:', result.error);
343
+ * }
344
+ * ```
345
+ */
346
+ verify(token: string): Promise<TokenVerificationResult>;
347
+ /**
348
+ * Lazy load the jose library
349
+ * Only loads when verification is first attempted
350
+ */
351
+ private loadJose;
352
+ /**
353
+ * Parse scope from token payload
354
+ * Handles both string (space-separated) and array formats
355
+ */
356
+ private parseScope;
357
+ }
358
+
359
+ /**
360
+ * PKCE (Proof Key for Code Exchange) Utilities
361
+ * Implements RFC 7636 for OAuth 2.0 public clients
362
+ */
363
+
364
+ /**
365
+ * PKCE utility class for generating and validating code challenges
366
+ */
367
+ declare class PKCEUtils {
368
+ /**
369
+ * Generate a code challenge from a verifier
370
+ * @param verifier The code verifier
371
+ * @param method Challenge method: 'S256' or 'plain' (default: 'S256')
372
+ * @returns Base64URL-encoded challenge string
373
+ */
374
+ static generateChallenge(verifier: string, method?: "plain" | "S256"): string;
375
+ /**
376
+ * Generate a complete PKCE pair (verifier + challenge)
377
+ * @param method Challenge method: 'S256' or 'plain' (default: 'S256')
378
+ * @returns Object containing verifier and challenge
379
+ */
380
+ static generatePair(method?: "plain" | "S256"): PKCEPair;
381
+ /**
382
+ * Generate a cryptographically secure code verifier
383
+ * @param length Length of verifier (43-128 characters, default: 128)
384
+ * @returns Base64URL-encoded verifier string
385
+ */
386
+ static generateVerifier(length?: number): string;
387
+ /**
388
+ * Validate a code verifier against a challenge
389
+ * @param verifier The code verifier to validate
390
+ * @param challenge The expected challenge
391
+ * @param method The challenge method used
392
+ * @returns True if verifier matches challenge
393
+ */
394
+ static validateChallenge(verifier: string, challenge: string, method: string): boolean;
395
+ /**
396
+ * Encode a buffer as base64url (RFC 4648)
397
+ * @param buffer Buffer to encode
398
+ * @returns Base64URL-encoded string
399
+ */
400
+ private static base64URLEncode;
401
+ }
402
+
403
+ /**
404
+ * Token Storage Implementations
405
+ * Secure storage for OAuth tokens and transaction state
406
+ */
407
+
408
+ /**
409
+ * Encrypted token storage wrapper
410
+ * Encrypts values using AES-256-GCM before storing
411
+ */
412
+ declare class EncryptedTokenStorage implements TokenStorage {
413
+ private algorithm;
414
+ private backend;
415
+ private encryptionKey;
416
+ constructor(backend: TokenStorage, encryptionKey: string);
417
+ cleanup(): Promise<void>;
418
+ delete(key: string): Promise<void>;
419
+ get(key: string): Promise<null | unknown>;
420
+ save(key: string, value: unknown, ttl?: number): Promise<void>;
421
+ private decrypt;
422
+ private encrypt;
423
+ }
424
+ /**
425
+ * In-memory token storage with TTL support
426
+ */
427
+ declare class MemoryTokenStorage implements TokenStorage {
428
+ private cleanupInterval;
429
+ private store;
430
+ constructor(cleanupIntervalMs?: number);
431
+ cleanup(): Promise<void>;
432
+ delete(key: string): Promise<void>;
433
+ /**
434
+ * Destroy the storage and clear cleanup interval
435
+ */
436
+ destroy(): void;
437
+ get(key: string): Promise<null | unknown>;
438
+ save(key: string, value: unknown, ttl?: number): Promise<void>;
439
+ /**
440
+ * Get the number of stored items
441
+ */
442
+ size(): number;
443
+ }
444
+
445
+ export { AzureProvider, type AzureProviderConfig, ConsentData, ConsentManager, DiskStore, EncryptedTokenStorage, GitHubProvider, GoogleProvider, type JWKSVerificationResult, JWKSVerifier, type JWKSVerifierConfig, type JWTClaims, JWTIssuer, MemoryTokenStorage, OAuthProviderConfig, OAuthProxy, OAuthTransaction, PKCEPair, PKCEUtils, TokenStorage, TokenVerificationResult, TokenVerifier };