@1mcp/agent 0.13.0 → 0.13.1

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.
Files changed (74) hide show
  1. package/build/auth/sdkOAuthClientProvider.d.ts +1 -1
  2. package/build/auth/sdkOAuthClientProvider.d.ts.map +1 -1
  3. package/build/auth/sdkOAuthClientProvider.js +11 -6
  4. package/build/auth/sdkOAuthClientProvider.js.map +1 -1
  5. package/build/auth/sdkOAuthServerProvider.d.ts +4 -3
  6. package/build/auth/sdkOAuthServerProvider.d.ts.map +1 -1
  7. package/build/auth/sdkOAuthServerProvider.js +41 -110
  8. package/build/auth/sdkOAuthServerProvider.js.map +1 -1
  9. package/build/auth/sessionTypes.d.ts +24 -10
  10. package/build/auth/sessionTypes.d.ts.map +1 -1
  11. package/build/auth/storage/authCodeRepository.d.ts +25 -0
  12. package/build/auth/storage/authCodeRepository.d.ts.map +1 -0
  13. package/build/auth/storage/authCodeRepository.js +50 -0
  14. package/build/auth/storage/authCodeRepository.js.map +1 -0
  15. package/build/auth/storage/authRequestRepository.d.ts +25 -0
  16. package/build/auth/storage/authRequestRepository.d.ts.map +1 -0
  17. package/build/auth/storage/authRequestRepository.js +51 -0
  18. package/build/auth/storage/authRequestRepository.js.map +1 -0
  19. package/build/auth/storage/clientDataRepository.d.ts +25 -0
  20. package/build/auth/storage/clientDataRepository.d.ts.map +1 -0
  21. package/build/auth/storage/clientDataRepository.js +45 -0
  22. package/build/auth/storage/clientDataRepository.js.map +1 -0
  23. package/build/auth/storage/clientSessionRepository.d.ts +77 -0
  24. package/build/auth/storage/clientSessionRepository.d.ts.map +1 -0
  25. package/build/auth/storage/clientSessionRepository.js +120 -0
  26. package/build/auth/storage/clientSessionRepository.js.map +1 -0
  27. package/build/auth/storage/fileStorageService.d.ts +68 -0
  28. package/build/auth/storage/fileStorageService.d.ts.map +1 -0
  29. package/build/auth/storage/fileStorageService.js +262 -0
  30. package/build/auth/storage/fileStorageService.js.map +1 -0
  31. package/build/auth/storage/oauthStorageService.d.ts +57 -0
  32. package/build/auth/storage/oauthStorageService.d.ts.map +1 -0
  33. package/build/auth/storage/oauthStorageService.js +131 -0
  34. package/build/auth/storage/oauthStorageService.js.map +1 -0
  35. package/build/auth/storage/sessionRepository.d.ts +29 -0
  36. package/build/auth/storage/sessionRepository.d.ts.map +1 -0
  37. package/build/auth/storage/sessionRepository.js +64 -0
  38. package/build/auth/storage/sessionRepository.js.map +1 -0
  39. package/build/constants.d.ts +26 -11
  40. package/build/constants.d.ts.map +1 -1
  41. package/build/constants.js +32 -11
  42. package/build/constants.js.map +1 -1
  43. package/build/core/server/agentConfig.js +2 -2
  44. package/build/core/server/agentConfig.js.map +1 -1
  45. package/build/transport/http/middlewares/scopeAuthMiddleware.d.ts +4 -7
  46. package/build/transport/http/middlewares/scopeAuthMiddleware.d.ts.map +1 -1
  47. package/build/transport/http/middlewares/scopeAuthMiddleware.js +5 -12
  48. package/build/transport/http/middlewares/scopeAuthMiddleware.js.map +1 -1
  49. package/build/transport/http/routes/oauthRoutes.d.ts +6 -2
  50. package/build/transport/http/routes/oauthRoutes.d.ts.map +1 -1
  51. package/build/transport/http/routes/oauthRoutes.js +331 -335
  52. package/build/transport/http/routes/oauthRoutes.js.map +1 -1
  53. package/build/transport/http/routes/sseRoutes.d.ts +2 -1
  54. package/build/transport/http/routes/sseRoutes.d.ts.map +1 -1
  55. package/build/transport/http/routes/sseRoutes.js +3 -2
  56. package/build/transport/http/routes/sseRoutes.js.map +1 -1
  57. package/build/transport/http/routes/streamableHttpRoutes.d.ts +2 -1
  58. package/build/transport/http/routes/streamableHttpRoutes.d.ts.map +1 -1
  59. package/build/transport/http/routes/streamableHttpRoutes.js +3 -2
  60. package/build/transport/http/routes/streamableHttpRoutes.js.map +1 -1
  61. package/build/transport/http/server.js +4 -4
  62. package/build/transport/http/server.js.map +1 -1
  63. package/build/utils/clientFiltering.d.ts.map +1 -1
  64. package/build/utils/clientFiltering.js +40 -5
  65. package/build/utils/clientFiltering.js.map +1 -1
  66. package/package.json +1 -1
  67. package/build/auth/clientSessionManager.d.ts +0 -94
  68. package/build/auth/clientSessionManager.d.ts.map +0 -1
  69. package/build/auth/clientSessionManager.js +0 -220
  70. package/build/auth/clientSessionManager.js.map +0 -1
  71. package/build/auth/serverSessionManager.d.ts +0 -185
  72. package/build/auth/serverSessionManager.d.ts.map +0 -1
  73. package/build/auth/serverSessionManager.js +0 -461
  74. package/build/auth/serverSessionManager.js.map +0 -1
@@ -0,0 +1,262 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import logger from '../../logger/logger.js';
4
+ import { AUTH_CONFIG, getGlobalConfigDir } from '../../constants.js';
5
+ /**
6
+ * Generic file storage service with unified cleanup for all expirable data types.
7
+ *
8
+ * This service provides a common foundation for storing sessions, auth codes,
9
+ * auth requests, and client data with automatic cleanup of expired items.
10
+ *
11
+ * Features:
12
+ * - Generic CRUD operations for any expirable data type
13
+ * - Unified periodic cleanup every 5 minutes
14
+ * - Path traversal protection
15
+ * - Automatic directory creation
16
+ * - Corruption handling (removes corrupted files)
17
+ */
18
+ export class FileStorageService {
19
+ storageDir;
20
+ cleanupInterval = null;
21
+ constructor(storageDir) {
22
+ this.storageDir = storageDir || path.join(getGlobalConfigDir(), AUTH_CONFIG.SERVER.STORAGE.DIR);
23
+ this.ensureDirectory();
24
+ this.startPeriodicCleanup();
25
+ }
26
+ /**
27
+ * Ensures the storage directory exists
28
+ */
29
+ ensureDirectory() {
30
+ try {
31
+ if (!fs.existsSync(this.storageDir)) {
32
+ fs.mkdirSync(this.storageDir, { recursive: true });
33
+ logger.info(`Created storage directory: ${this.storageDir}`);
34
+ }
35
+ }
36
+ catch (error) {
37
+ logger.error(`Failed to create storage directory: ${error}`);
38
+ throw error;
39
+ }
40
+ }
41
+ /**
42
+ * Gets the file path for a given prefix and ID
43
+ */
44
+ getFilePath(filePrefix, id) {
45
+ if (!this.isValidId(id)) {
46
+ throw new Error(`Invalid ID format: ${id}`);
47
+ }
48
+ const fileName = `${filePrefix}${id}${AUTH_CONFIG.SERVER.STORAGE.FILE_EXTENSION}`;
49
+ const filePath = path.resolve(this.storageDir, fileName);
50
+ // Security check: ensure resolved path is within storage directory
51
+ const normalizedStorageDir = path.resolve(this.storageDir);
52
+ const normalizedFilePath = path.resolve(filePath);
53
+ if (!normalizedFilePath.startsWith(normalizedStorageDir + path.sep)) {
54
+ throw new Error('Invalid file path: outside storage directory');
55
+ }
56
+ return filePath;
57
+ }
58
+ /**
59
+ * Validates ID format for security
60
+ */
61
+ isValidId(id) {
62
+ // Check minimum length (prefix + content)
63
+ if (!id || id.length < 8) {
64
+ return false;
65
+ }
66
+ // Check for valid server-side prefix
67
+ const hasServerPrefix = id.startsWith(AUTH_CONFIG.SERVER.SESSION.ID_PREFIX) ||
68
+ id.startsWith(AUTH_CONFIG.SERVER.AUTH_CODE.ID_PREFIX) ||
69
+ id.startsWith(AUTH_CONFIG.SERVER.AUTH_REQUEST.ID_PREFIX);
70
+ if (hasServerPrefix) {
71
+ // Validate the UUID portion (after prefix)
72
+ let uuidPart;
73
+ if (id.startsWith(AUTH_CONFIG.SERVER.SESSION.ID_PREFIX)) {
74
+ uuidPart = id.substring(AUTH_CONFIG.SERVER.SESSION.ID_PREFIX.length);
75
+ }
76
+ else if (id.startsWith(AUTH_CONFIG.SERVER.AUTH_CODE.ID_PREFIX)) {
77
+ uuidPart = id.substring(AUTH_CONFIG.SERVER.AUTH_CODE.ID_PREFIX.length);
78
+ }
79
+ else {
80
+ uuidPart = id.substring(AUTH_CONFIG.SERVER.AUTH_REQUEST.ID_PREFIX.length);
81
+ }
82
+ // UUID v4 format: 8-4-4-4-12 hexadecimal digits with hyphens
83
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
84
+ return uuidRegex.test(uuidPart);
85
+ }
86
+ // Check for valid client-side OAuth prefix
87
+ const hasClientPrefix = id.startsWith(AUTH_CONFIG.CLIENT.PREFIXES.CLIENT) ||
88
+ id.startsWith(AUTH_CONFIG.CLIENT.PREFIXES.TOKENS) ||
89
+ id.startsWith(AUTH_CONFIG.CLIENT.PREFIXES.VERIFIER) ||
90
+ id.startsWith(AUTH_CONFIG.CLIENT.PREFIXES.STATE);
91
+ if (hasClientPrefix) {
92
+ const contentPart = id.substring(4); // All client prefixes are 4 characters
93
+ return contentPart.length > 0 && /^[a-zA-Z0-9_-]+$/.test(contentPart);
94
+ }
95
+ // Check for client session prefix
96
+ if (id.startsWith(AUTH_CONFIG.CLIENT.SESSION.ID_PREFIX)) {
97
+ const contentPart = id.substring(AUTH_CONFIG.CLIENT.SESSION.ID_PREFIX.length);
98
+ return contentPart.length > 0 && /^[a-zA-Z0-9_-]+$/.test(contentPart);
99
+ }
100
+ return false;
101
+ }
102
+ /**
103
+ * Writes data to a file with the specified prefix and ID
104
+ */
105
+ writeData(filePrefix, id, data) {
106
+ try {
107
+ const filePath = this.getFilePath(filePrefix, id);
108
+ fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
109
+ logger.debug(`Wrote data to ${filePath}`);
110
+ }
111
+ catch (error) {
112
+ logger.error(`Failed to write data for ${id}: ${error}`);
113
+ throw error;
114
+ }
115
+ }
116
+ /**
117
+ * Reads data from a file with the specified prefix and ID
118
+ * Returns null if file doesn't exist or data is expired
119
+ */
120
+ readData(filePrefix, id) {
121
+ if (!this.isValidId(id)) {
122
+ logger.warn(`Rejected readData with invalid ID: ${id}`);
123
+ return null;
124
+ }
125
+ try {
126
+ const filePath = this.getFilePath(filePrefix, id);
127
+ if (!fs.existsSync(filePath)) {
128
+ return null;
129
+ }
130
+ const data = fs.readFileSync(filePath, 'utf8');
131
+ const parsedData = JSON.parse(data);
132
+ // Check if data is expired
133
+ if (parsedData.expires < Date.now()) {
134
+ this.deleteData(filePrefix, id);
135
+ return null;
136
+ }
137
+ return parsedData;
138
+ }
139
+ catch (error) {
140
+ logger.error(`Failed to read data for ${id}: ${error}`);
141
+ return null;
142
+ }
143
+ }
144
+ /**
145
+ * Deletes data file with the specified prefix and ID
146
+ */
147
+ deleteData(filePrefix, id) {
148
+ if (!this.isValidId(id)) {
149
+ logger.warn(`Rejected deleteData with invalid ID: ${id}`);
150
+ return false;
151
+ }
152
+ try {
153
+ const filePath = this.getFilePath(filePrefix, id);
154
+ if (fs.existsSync(filePath)) {
155
+ fs.unlinkSync(filePath);
156
+ logger.debug(`Deleted data file: ${filePath}`);
157
+ return true;
158
+ }
159
+ return false;
160
+ }
161
+ catch (error) {
162
+ logger.error(`Failed to delete data for ${id}: ${error}`);
163
+ return false;
164
+ }
165
+ }
166
+ /**
167
+ * Starts periodic cleanup of expired data files
168
+ */
169
+ startPeriodicCleanup() {
170
+ // Clean up expired data every 5 minutes
171
+ this.cleanupInterval = setInterval(() => {
172
+ this.cleanupExpiredData();
173
+ }, 5 * 60 * 1000);
174
+ }
175
+ /**
176
+ * Unified cleanup for all expired data types
177
+ */
178
+ cleanupExpiredData() {
179
+ try {
180
+ const files = fs.readdirSync(this.storageDir);
181
+ let cleanedCount = 0;
182
+ for (const file of files) {
183
+ if (file.endsWith(AUTH_CONFIG.SERVER.STORAGE.FILE_EXTENSION)) {
184
+ const filePath = path.join(this.storageDir, file);
185
+ try {
186
+ const data = fs.readFileSync(filePath, 'utf8');
187
+ const parsedData = JSON.parse(data);
188
+ // Check if expired (all our data types have expires field)
189
+ if (parsedData.expires && parsedData.expires < Date.now()) {
190
+ fs.unlinkSync(filePath);
191
+ cleanedCount++;
192
+ logger.debug(`Cleaned up expired file: ${file}`);
193
+ }
194
+ }
195
+ catch (error) {
196
+ // Remove corrupted files
197
+ logger.warn(`Removing corrupted file ${file}: ${error}`);
198
+ try {
199
+ fs.unlinkSync(filePath);
200
+ cleanedCount++;
201
+ }
202
+ catch (unlinkError) {
203
+ logger.error(`Failed to remove corrupted file ${file}: ${unlinkError}`);
204
+ }
205
+ }
206
+ }
207
+ }
208
+ if (cleanedCount > 0) {
209
+ logger.info(`Cleaned up ${cleanedCount} expired/corrupted files`);
210
+ }
211
+ return cleanedCount;
212
+ }
213
+ catch (error) {
214
+ logger.error(`Failed to cleanup expired data: ${error}`);
215
+ return 0;
216
+ }
217
+ }
218
+ /**
219
+ * Lists all files in the storage directory that match a given prefix.
220
+ *
221
+ * @param filePrefix - The file prefix to filter by (optional)
222
+ * @returns Array of file names (without directory path)
223
+ */
224
+ listFiles(filePrefix) {
225
+ try {
226
+ if (!fs.existsSync(this.storageDir)) {
227
+ return [];
228
+ }
229
+ const files = fs.readdirSync(this.storageDir);
230
+ return files.filter((file) => {
231
+ if (!file.endsWith('.json')) {
232
+ return false;
233
+ }
234
+ if (filePrefix) {
235
+ return file.startsWith(filePrefix);
236
+ }
237
+ return true;
238
+ });
239
+ }
240
+ catch (error) {
241
+ logger.error(`Failed to list files: ${error}`);
242
+ return [];
243
+ }
244
+ }
245
+ /**
246
+ * Gets the storage directory path
247
+ */
248
+ getStorageDir() {
249
+ return this.storageDir;
250
+ }
251
+ /**
252
+ * Graceful shutdown - stops cleanup interval
253
+ */
254
+ shutdown() {
255
+ if (this.cleanupInterval) {
256
+ clearInterval(this.cleanupInterval);
257
+ this.cleanupInterval = null;
258
+ logger.info('FileStorageService cleanup interval stopped');
259
+ }
260
+ }
261
+ }
262
+ //# sourceMappingURL=fileStorageService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileStorageService.js","sourceRoot":"","sources":["../../../src/auth/storage/fileStorageService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,MAAM,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGrE;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,kBAAkB;IACrB,UAAU,CAAS;IACnB,eAAe,GAA0C,IAAI,CAAC;IAEtE,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,CAAC,CAAC;YACzD,OAAO,CAAC,CAAC;QACX,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,UAAmB;QAC3B,IAAI,CAAC;YACH,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;gBACpC,OAAO,EAAE,CAAC;YACZ,CAAC;YAED,MAAM,KAAK,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC9C,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;gBAC3B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;oBAC5B,OAAO,KAAK,CAAC;gBACf,CAAC;gBAED,IAAI,UAAU,EAAE,CAAC;oBACf,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;gBACrC,CAAC;gBAED,OAAO,IAAI,CAAC;YACd,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,yBAAyB,KAAK,EAAE,CAAC,CAAC;YAC/C,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAED;;OAEG;IACH,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,aAAa,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YACpC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;YAC5B,MAAM,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,57 @@
1
+ import { SessionRepository } from './sessionRepository.js';
2
+ import { AuthCodeRepository } from './authCodeRepository.js';
3
+ import { AuthRequestRepository } from './authRequestRepository.js';
4
+ import { ClientDataRepository } from './clientDataRepository.js';
5
+ /**
6
+ * High-level OAuth storage service providing business operations
7
+ *
8
+ * This service orchestrates the lower-level repositories to provide
9
+ * high-level business operations for OAuth flows. It encapsulates
10
+ * the complexity of coordinating multiple data types and provides
11
+ * clean APIs for route handlers.
12
+ */
13
+ export declare class OAuthStorageService {
14
+ private storage;
15
+ private sessions;
16
+ private authCodes;
17
+ private authRequests;
18
+ private clientData;
19
+ constructor(storageDir?: string);
20
+ /**
21
+ * Processes user consent approval
22
+ *
23
+ * Creates an authorization code with the selected scopes and builds
24
+ * the redirect URL for the client. Cleans up the temporary auth request.
25
+ */
26
+ processConsentApproval(authRequestId: string, selectedScopes: string[]): Promise<{
27
+ authCode: string;
28
+ redirectUrl: URL;
29
+ }>;
30
+ /**
31
+ * Processes user consent denial
32
+ *
33
+ * Builds an error redirect URL and cleans up the temporary auth request.
34
+ */
35
+ processConsentDenial(authRequestId: string): Promise<URL>;
36
+ /**
37
+ * Creates a temporary authorization request for the consent flow
38
+ */
39
+ createAuthorizationRequest(clientId: string, redirectUri: string, codeChallenge?: string, state?: string, resource?: string, scopes?: string[]): string;
40
+ /**
41
+ * Retrieves an authorization request
42
+ */
43
+ getAuthorizationRequest(authRequestId: string): import("../sessionTypes.js").AuthRequestData | null;
44
+ get sessionRepository(): SessionRepository;
45
+ get authCodeRepository(): AuthCodeRepository;
46
+ get authRequestRepository(): AuthRequestRepository;
47
+ get clientDataRepository(): ClientDataRepository;
48
+ /**
49
+ * Gets the storage directory path
50
+ */
51
+ getStorageDir(): string;
52
+ /**
53
+ * Graceful shutdown
54
+ */
55
+ shutdown(): void;
56
+ }
57
+ //# sourceMappingURL=oauthStorageService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauthStorageService.d.ts","sourceRoot":"","sources":["../../../src/auth/storage/oauthStorageService.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAGjE;;;;;;;GAOG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,QAAQ,CAAoB;IACpC,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,YAAY,CAAwB;IAC5C,OAAO,CAAC,UAAU,CAAuB;gBAE7B,UAAU,CAAC,EAAE,MAAM;IAQ/B;;;;;OAKG;IACG,sBAAsB,CAC1B,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,EAAE,GACvB,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,GAAG,CAAA;KAAE,CAAC;IA2ClD;;;;OAIG;IACG,oBAAoB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IA6B/D;;OAEG;IACH,0BAA0B,CACxB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,aAAa,CAAC,EAAE,MAAM,EACtB,KAAK,CAAC,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,EAAE,GAChB,MAAM;IAIT;;OAEG;IACH,uBAAuB,CAAC,aAAa,EAAE,MAAM;IAK7C,IAAI,iBAAiB,IAAI,iBAAiB,CAEzC;IAED,IAAI,kBAAkB,IAAI,kBAAkB,CAE3C;IAED,IAAI,qBAAqB,IAAI,qBAAqB,CAEjD;IAED,IAAI,oBAAoB,IAAI,oBAAoB,CAE/C;IAED;;OAEG;IACH,aAAa,IAAI,MAAM;IAIvB;;OAEG;IACH,QAAQ,IAAI,IAAI;CAGjB"}
@@ -0,0 +1,131 @@
1
+ import logger from '../../logger/logger.js';
2
+ import { AUTH_CONFIG } from '../../constants.js';
3
+ import { FileStorageService } from './fileStorageService.js';
4
+ import { SessionRepository } from './sessionRepository.js';
5
+ import { AuthCodeRepository } from './authCodeRepository.js';
6
+ import { AuthRequestRepository } from './authRequestRepository.js';
7
+ import { ClientDataRepository } from './clientDataRepository.js';
8
+ import { auditScopeOperation } from '../../utils/scopeValidation.js';
9
+ /**
10
+ * High-level OAuth storage service providing business operations
11
+ *
12
+ * This service orchestrates the lower-level repositories to provide
13
+ * high-level business operations for OAuth flows. It encapsulates
14
+ * the complexity of coordinating multiple data types and provides
15
+ * clean APIs for route handlers.
16
+ */
17
+ export class OAuthStorageService {
18
+ storage;
19
+ sessions;
20
+ authCodes;
21
+ authRequests;
22
+ clientData;
23
+ constructor(storageDir) {
24
+ this.storage = new FileStorageService(storageDir);
25
+ this.sessions = new SessionRepository(this.storage);
26
+ this.authCodes = new AuthCodeRepository(this.storage);
27
+ this.authRequests = new AuthRequestRepository(this.storage);
28
+ this.clientData = new ClientDataRepository(this.storage);
29
+ }
30
+ /**
31
+ * Processes user consent approval
32
+ *
33
+ * Creates an authorization code with the selected scopes and builds
34
+ * the redirect URL for the client. Cleans up the temporary auth request.
35
+ */
36
+ async processConsentApproval(authRequestId, selectedScopes) {
37
+ const authRequest = this.authRequests.get(authRequestId);
38
+ if (!authRequest) {
39
+ throw new Error('Invalid or expired authorization request');
40
+ }
41
+ // Create authorization code with selected scopes
42
+ const authCode = this.authCodes.create(authRequest.clientId, authRequest.redirectUri, authRequest.resource || '', selectedScopes, AUTH_CONFIG.SERVER.AUTH_CODE.TTL_MS, authRequest.codeChallenge);
43
+ // Clean up the temporary auth request
44
+ this.authRequests.delete(authRequestId);
45
+ // Build redirect URL
46
+ const redirectUrl = new URL(authRequest.redirectUri);
47
+ redirectUrl.searchParams.set('code', authCode);
48
+ if (authRequest.state) {
49
+ redirectUrl.searchParams.set('state', authRequest.state);
50
+ }
51
+ // Audit the operation
52
+ auditScopeOperation('authorization_granted', {
53
+ clientId: authRequest.clientId,
54
+ requestedScopes: authRequest.scopes || [],
55
+ grantedScopes: selectedScopes,
56
+ success: true,
57
+ });
58
+ logger.info(`OAuth authorization granted for client ${authRequest.clientId}`, {
59
+ clientId: authRequest.clientId,
60
+ redirectUri: authRequest.redirectUri,
61
+ grantedScopes: selectedScopes,
62
+ });
63
+ return { authCode, redirectUrl };
64
+ }
65
+ /**
66
+ * Processes user consent denial
67
+ *
68
+ * Builds an error redirect URL and cleans up the temporary auth request.
69
+ */
70
+ async processConsentDenial(authRequestId) {
71
+ const authRequest = this.authRequests.get(authRequestId);
72
+ if (!authRequest) {
73
+ throw new Error('Invalid or expired authorization request');
74
+ }
75
+ // Clean up the auth request
76
+ this.authRequests.delete(authRequestId);
77
+ // Build error redirect URL
78
+ const redirectUrl = new URL(authRequest.redirectUri);
79
+ redirectUrl.searchParams.set('error', 'access_denied');
80
+ redirectUrl.searchParams.set('error_description', 'User denied the request');
81
+ if (authRequest.state) {
82
+ redirectUrl.searchParams.set('state', authRequest.state);
83
+ }
84
+ // Audit the operation
85
+ auditScopeOperation('authorization_denied', {
86
+ clientId: authRequest.clientId,
87
+ success: false,
88
+ error: 'User denied authorization',
89
+ });
90
+ logger.info(`OAuth authorization denied by user for client ${authRequest.clientId}`);
91
+ return redirectUrl;
92
+ }
93
+ /**
94
+ * Creates a temporary authorization request for the consent flow
95
+ */
96
+ createAuthorizationRequest(clientId, redirectUri, codeChallenge, state, resource, scopes) {
97
+ return this.authRequests.create(clientId, redirectUri, codeChallenge, state, resource, scopes);
98
+ }
99
+ /**
100
+ * Retrieves an authorization request
101
+ */
102
+ getAuthorizationRequest(authRequestId) {
103
+ return this.authRequests.get(authRequestId);
104
+ }
105
+ // Expose repositories for direct access when needed (with getters for encapsulation)
106
+ get sessionRepository() {
107
+ return this.sessions;
108
+ }
109
+ get authCodeRepository() {
110
+ return this.authCodes;
111
+ }
112
+ get authRequestRepository() {
113
+ return this.authRequests;
114
+ }
115
+ get clientDataRepository() {
116
+ return this.clientData;
117
+ }
118
+ /**
119
+ * Gets the storage directory path
120
+ */
121
+ getStorageDir() {
122
+ return this.storage.getStorageDir();
123
+ }
124
+ /**
125
+ * Graceful shutdown
126
+ */
127
+ shutdown() {
128
+ this.storage.shutdown();
129
+ }
130
+ }
131
+ //# sourceMappingURL=oauthStorageService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauthStorageService.js","sourceRoot":"","sources":["../../../src/auth/storage/oauthStorageService.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE;;;;;;;GAOG;AACH,MAAM,OAAO,mBAAmB;IACtB,OAAO,CAAqB;IAC5B,QAAQ,CAAoB;IAC5B,SAAS,CAAqB;IAC9B,YAAY,CAAwB;IACpC,UAAU,CAAuB;IAEzC,YAAY,UAAmB;QAC7B,IAAI,CAAC,OAAO,GAAG,IAAI,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAClD,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,SAAS,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtD,IAAI,CAAC,YAAY,GAAG,IAAI,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5D,IAAI,CAAC,UAAU,GAAG,IAAI,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC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AAE,aAAa,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACjG,CAAC;IAED;;OAEG;IACH,uBAAuB,CAAC,aAAqB;QAC3C,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAC9C,CAAC;IAED,qFAAqF;IACrF,IAAI,iBAAiB;QACnB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,IAAI,qBAAqB;QACvB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,IAAI,oBAAoB;QACtB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,aAAa;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC1B,CAAC;CACF"}
@@ -0,0 +1,29 @@
1
+ import { SessionData } from '../sessionTypes.js';
2
+ import { FileStorageService } from './fileStorageService.js';
3
+ /**
4
+ * Repository for session operations
5
+ *
6
+ * Manages OAuth 2.1 sessions with automatic expiration and cleanup.
7
+ * Sessions store user authorization state and granted scopes.
8
+ */
9
+ export declare class SessionRepository {
10
+ private storage;
11
+ constructor(storage: FileStorageService);
12
+ /**
13
+ * Creates a new session
14
+ */
15
+ create(clientId: string, resource: string, scopes: string[], ttlMs: number): string;
16
+ /**
17
+ * Creates a session with a specific token ID (for access tokens)
18
+ */
19
+ createWithId(tokenId: string, clientId: string, resource: string, scopes: string[], ttlMs: number): string;
20
+ /**
21
+ * Retrieves a session by ID
22
+ */
23
+ get(sessionId: string): SessionData | null;
24
+ /**
25
+ * Deletes a session by ID
26
+ */
27
+ delete(sessionId: string): boolean;
28
+ }
29
+ //# sourceMappingURL=sessionRepository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessionRepository.d.ts","sourceRoot":"","sources":["../../../src/auth/storage/sessionRepository.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;;;;GAKG;AACH,qBAAa,iBAAiB;IAChB,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,kBAAkB;IAE/C;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAenF;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAe1G;;OAEG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAI1C;;OAEG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;CAOnC"}
@@ -0,0 +1,64 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import logger from '../../logger/logger.js';
3
+ import { AUTH_CONFIG } from '../../constants.js';
4
+ /**
5
+ * Repository for session operations
6
+ *
7
+ * Manages OAuth 2.1 sessions with automatic expiration and cleanup.
8
+ * Sessions store user authorization state and granted scopes.
9
+ */
10
+ export class SessionRepository {
11
+ storage;
12
+ constructor(storage) {
13
+ this.storage = storage;
14
+ }
15
+ /**
16
+ * Creates a new session
17
+ */
18
+ create(clientId, resource, scopes, ttlMs) {
19
+ const sessionId = AUTH_CONFIG.SERVER.SESSION.ID_PREFIX + randomUUID();
20
+ const sessionData = {
21
+ clientId,
22
+ resource,
23
+ scopes,
24
+ expires: Date.now() + ttlMs,
25
+ createdAt: Date.now(),
26
+ };
27
+ this.storage.writeData(AUTH_CONFIG.SERVER.SESSION.FILE_PREFIX, sessionId, sessionData);
28
+ logger.info(`Created session: ${sessionId} for client: ${clientId}`);
29
+ return sessionId;
30
+ }
31
+ /**
32
+ * Creates a session with a specific token ID (for access tokens)
33
+ */
34
+ createWithId(tokenId, clientId, resource, scopes, ttlMs) {
35
+ const sessionId = AUTH_CONFIG.SERVER.SESSION.ID_PREFIX + tokenId;
36
+ const sessionData = {
37
+ clientId,
38
+ resource,
39
+ scopes,
40
+ expires: Date.now() + ttlMs,
41
+ createdAt: Date.now(),
42
+ };
43
+ this.storage.writeData(AUTH_CONFIG.SERVER.SESSION.FILE_PREFIX, sessionId, sessionData);
44
+ logger.info(`Created session with ID: ${sessionId} for client: ${clientId}`);
45
+ return sessionId;
46
+ }
47
+ /**
48
+ * Retrieves a session by ID
49
+ */
50
+ get(sessionId) {
51
+ return this.storage.readData(AUTH_CONFIG.SERVER.SESSION.FILE_PREFIX, sessionId);
52
+ }
53
+ /**
54
+ * Deletes a session by ID
55
+ */
56
+ delete(sessionId) {
57
+ const result = this.storage.deleteData(AUTH_CONFIG.SERVER.SESSION.FILE_PREFIX, sessionId);
58
+ if (result) {
59
+ logger.info(`Deleted session: ${sessionId}`);
60
+ }
61
+ return result;
62
+ }
63
+ }
64
+ //# sourceMappingURL=sessionRepository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessionRepository.js","sourceRoot":"","sources":["../../../src/auth/storage/sessionRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,MAAM,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAIjD;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IACR;IAApB,YAAoB,OAA2B;QAA3B,YAAO,GAAP,OAAO,CAAoB;IAAG,CAAC;IAEnD;;OAEG;IACH,MAAM,CAAC,QAAgB,EAAE,QAAg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AE,SAAS,CAAC,CAAC;IAC/F,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,SAAiB;QACtB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAC1F,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,CAAC,IAAI,CAAC,oBAAoB,SAAS,EAAE,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -9,7 +9,7 @@ export declare const MESSAGES_ENDPOINT = "/messages";
9
9
  export declare const STREAMABLE_HTTP_ENDPOINT = "/mcp";
10
10
  export declare const MCP_CONFIG_FILE = "mcp.json";
11
11
  export declare const MCP_SERVER_NAME = "1mcp";
12
- export declare const MCP_SERVER_VERSION = "0.13.0";
12
+ export declare const MCP_SERVER_VERSION = "0.13.1";
13
13
  export declare const MCP_URI_SEPARATOR = "_1mcp_";
14
14
  export declare const CONFIG_DIR_NAME = "1mcp";
15
15
  export declare const DEFAULT_CONFIG: {
@@ -30,21 +30,31 @@ export declare const CONNECTION_RETRY: {
30
30
  export declare const AUTH_CONFIG: {
31
31
  SERVER: {
32
32
  DEFAULT_ENABLED: boolean;
33
+ STORAGE: {
34
+ DIR: string;
35
+ FILE_EXTENSION: string;
36
+ };
33
37
  SESSION: {
34
38
  TTL_MINUTES: number;
35
- STORAGE_DIR: string;
39
+ ID_PREFIX: string;
36
40
  FILE_PREFIX: string;
37
- FILE_EXTENSION: string;
38
41
  };
39
- OAUTH: {
40
- CODE_TTL_MS: number;
41
- TOKEN_TTL_MS: number;
42
+ AUTH_CODE: {
43
+ TTL_MS: number;
44
+ ID_PREFIX: string;
45
+ FILE_PREFIX: string;
42
46
  };
43
- PREFIXES: {
44
- SESSION_ID: string;
45
- ACCESS_TOKEN: string;
46
- AUTH_CODE: string;
47
- CLIENT_ID: string;
47
+ AUTH_REQUEST: {
48
+ TTL_MS: number;
49
+ ID_PREFIX: string;
50
+ FILE_PREFIX: string;
51
+ };
52
+ TOKEN: {
53
+ TTL_MS: number;
54
+ ID_PREFIX: string;
55
+ };
56
+ CLIENT: {
57
+ ID_PREFIX: string;
48
58
  };
49
59
  };
50
60
  CLIENT: {
@@ -56,6 +66,11 @@ export declare const AUTH_CONFIG: {
56
66
  DEFAULT_CALLBACK_PATH: string;
57
67
  DEFAULT_SCOPES: never[];
58
68
  };
69
+ SESSION: {
70
+ TTL_MS: number;
71
+ ID_PREFIX: string;
72
+ FILE_PREFIX: string;
73
+ };
59
74
  PREFIXES: {
60
75
  CLIENT: string;
61
76
  TOKENS: string;
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAG5F,eAAO,MAAM,IAAI,OAAO,CAAC;AACzB,eAAO,MAAM,IAAI,cAAc,CAAC;AAGhC,eAAO,MAAM,YAAY,SAAS,CAAC;AACnC,eAAO,MAAM,iBAAiB,cAAc,CAAC;AAC7C,eAAO,MAAM,wBAAwB,SAAS,CAAC;AAG/C,eAAO,MAAM,eAAe,aAAa,CAAC;AAC1C,eAAO,MAAM,eAAe,SAAS,CAAC;AACtC,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAE3C,eAAO,MAAM,iBAAiB,WAAW,CAAC;AAG1C,eAAO,MAAM,eAAe,SAAS,CAAC;AACtC,eAAO,MAAM,cAAc;;CAE1B,CAAC;AAEF;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAY3C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAGD,eAAO,MAAM,gBAAgB;;;CAG5B,CAAC;AAGF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCvB,CAAC;AAGF,e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