@1mcp/agent 0.12.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.
- package/README.md +22 -37
- package/build/auth/sdkOAuthClientProvider.d.ts +93 -0
- package/build/auth/sdkOAuthClientProvider.d.ts.map +1 -0
- package/build/auth/sdkOAuthClientProvider.js +204 -0
- package/build/auth/sdkOAuthClientProvider.js.map +1 -0
- package/build/auth/sdkOAuthServerProvider.d.ts +64 -0
- package/build/auth/sdkOAuthServerProvider.d.ts.map +1 -0
- package/build/auth/sdkOAuthServerProvider.js +359 -0
- package/build/auth/sdkOAuthServerProvider.js.map +1 -0
- package/build/auth/sessionTypes.d.ts +38 -0
- package/build/auth/sessionTypes.d.ts.map +1 -0
- package/build/auth/sessionTypes.js +3 -0
- package/build/auth/sessionTypes.js.map +1 -0
- package/build/auth/storage/authCodeRepository.d.ts +25 -0
- package/build/auth/storage/authCodeRepository.d.ts.map +1 -0
- package/build/auth/storage/authCodeRepository.js +50 -0
- package/build/auth/storage/authCodeRepository.js.map +1 -0
- package/build/auth/storage/authRequestRepository.d.ts +25 -0
- package/build/auth/storage/authRequestRepository.d.ts.map +1 -0
- package/build/auth/storage/authRequestRepository.js +51 -0
- package/build/auth/storage/authRequestRepository.js.map +1 -0
- package/build/auth/storage/clientDataRepository.d.ts +25 -0
- package/build/auth/storage/clientDataRepository.d.ts.map +1 -0
- package/build/auth/storage/clientDataRepository.js +45 -0
- package/build/auth/storage/clientDataRepository.js.map +1 -0
- package/build/auth/storage/clientSessionRepository.d.ts +77 -0
- package/build/auth/storage/clientSessionRepository.d.ts.map +1 -0
- package/build/auth/storage/clientSessionRepository.js +120 -0
- package/build/auth/storage/clientSessionRepository.js.map +1 -0
- package/build/auth/storage/fileStorageService.d.ts +68 -0
- package/build/auth/storage/fileStorageService.d.ts.map +1 -0
- package/build/auth/storage/fileStorageService.js +262 -0
- package/build/auth/storage/fileStorageService.js.map +1 -0
- package/build/auth/storage/oauthStorageService.d.ts +57 -0
- package/build/auth/storage/oauthStorageService.d.ts.map +1 -0
- package/build/auth/storage/oauthStorageService.js +131 -0
- package/build/auth/storage/oauthStorageService.js.map +1 -0
- package/build/auth/storage/sessionRepository.d.ts +29 -0
- package/build/auth/storage/sessionRepository.d.ts.map +1 -0
- package/build/auth/storage/sessionRepository.js +64 -0
- package/build/auth/storage/sessionRepository.js.map +1 -0
- package/build/capabilities/capabilityManager.d.ts +2 -2
- package/build/capabilities/capabilityManager.d.ts.map +1 -1
- package/build/capabilities/capabilityManager.js +1 -1
- package/build/capabilities/capabilityManager.js.map +1 -1
- package/build/config/{configManager.d.ts → mcpConfigManager.d.ts} +11 -6
- package/build/config/mcpConfigManager.d.ts.map +1 -0
- package/build/config/{configManager.js → mcpConfigManager.js} +26 -8
- package/build/config/mcpConfigManager.js.map +1 -0
- package/build/constants.d.ts +51 -14
- package/build/constants.d.ts.map +1 -1
- package/build/constants.js +61 -17
- package/build/constants.js.map +1 -1
- package/build/core/client/clientManager.d.ts +14 -6
- package/build/core/client/clientManager.d.ts.map +1 -1
- package/build/core/client/clientManager.js +90 -28
- package/build/core/client/clientManager.js.map +1 -1
- package/build/core/server/{serverConfig.d.ts → agentConfig.d.ts} +50 -15
- package/build/core/server/agentConfig.d.ts.map +1 -0
- package/build/core/server/agentConfig.js +166 -0
- package/build/core/server/agentConfig.js.map +1 -0
- package/build/core/server/serverManager.d.ts +12 -5
- package/build/core/server/serverManager.d.ts.map +1 -1
- package/build/core/server/serverManager.js +12 -2
- package/build/core/server/serverManager.js.map +1 -1
- package/build/core/types/client.d.ts +22 -9
- package/build/core/types/client.d.ts.map +1 -1
- package/build/core/types/client.js +2 -0
- package/build/core/types/client.js.map +1 -1
- package/build/core/types/server.d.ts +3 -3
- package/build/core/types/server.d.ts.map +1 -1
- package/build/core/types/transport.d.ts +58 -0
- package/build/core/types/transport.d.ts.map +1 -1
- package/build/core/types/transport.js +10 -0
- package/build/core/types/transport.js.map +1 -1
- package/build/handlers/notificationHandlers.d.ts +3 -3
- package/build/handlers/notificationHandlers.d.ts.map +1 -1
- package/build/handlers/notificationHandlers.js +2 -2
- package/build/handlers/notificationHandlers.js.map +1 -1
- package/build/handlers/requestHandlers.d.ts +2 -2
- package/build/handlers/requestHandlers.d.ts.map +1 -1
- package/build/handlers/requestHandlers.js +4 -3
- package/build/handlers/requestHandlers.js.map +1 -1
- package/build/index.js +47 -7
- package/build/index.js.map +1 -1
- package/build/{transport/http/middleware/loggingMiddleware.d.ts → logger/mcpLoggingEnhancer.d.ts} +1 -1
- package/build/logger/mcpLoggingEnhancer.d.ts.map +1 -0
- package/build/{transport/http/middleware/loggingMiddleware.js → logger/mcpLoggingEnhancer.js} +2 -2
- package/build/logger/mcpLoggingEnhancer.js.map +1 -0
- package/build/server.js +4 -4
- package/build/server.js.map +1 -1
- package/build/services/configReloadService.d.ts +2 -2
- package/build/services/configReloadService.d.ts.map +1 -1
- package/build/services/configReloadService.js +4 -4
- package/build/services/configReloadService.js.map +1 -1
- package/build/transport/http/middlewares/errorHandler.d.ts.map +1 -0
- package/build/transport/http/{errorHandler.js → middlewares/errorHandler.js} +1 -1
- package/build/transport/http/middlewares/errorHandler.js.map +1 -0
- package/build/transport/http/middlewares/scopeAuthMiddleware.d.ts +39 -0
- package/build/transport/http/middlewares/scopeAuthMiddleware.d.ts.map +1 -0
- package/build/transport/http/middlewares/scopeAuthMiddleware.js +129 -0
- package/build/transport/http/middlewares/scopeAuthMiddleware.js.map +1 -0
- package/build/transport/http/middlewares/securityMiddleware.d.ts +30 -0
- package/build/transport/http/middlewares/securityMiddleware.d.ts.map +1 -0
- package/build/transport/http/middlewares/securityMiddleware.js +201 -0
- package/build/transport/http/middlewares/securityMiddleware.js.map +1 -0
- package/build/transport/http/middlewares/tagsExtractor.d.ts.map +1 -0
- package/build/transport/http/middlewares/tagsExtractor.js.map +1 -0
- package/build/transport/http/routes/oauthRoutes.d.ts +5 -11
- package/build/transport/http/routes/oauthRoutes.d.ts.map +1 -1
- package/build/transport/http/routes/oauthRoutes.js +460 -122
- package/build/transport/http/routes/oauthRoutes.js.map +1 -1
- package/build/transport/http/routes/sseRoutes.d.ts +3 -2
- package/build/transport/http/routes/sseRoutes.d.ts.map +1 -1
- package/build/transport/http/routes/sseRoutes.js +10 -7
- package/build/transport/http/routes/sseRoutes.js.map +1 -1
- package/build/transport/http/routes/streamableHttpRoutes.d.ts +3 -2
- package/build/transport/http/routes/streamableHttpRoutes.d.ts.map +1 -1
- package/build/transport/http/routes/streamableHttpRoutes.js +17 -10
- package/build/transport/http/routes/streamableHttpRoutes.js.map +1 -1
- package/build/transport/http/server.d.ts +3 -2
- package/build/transport/http/server.d.ts.map +1 -1
- package/build/transport/http/server.js +58 -21
- package/build/transport/http/server.js.map +1 -1
- package/build/transport/transportFactory.d.ts +9 -0
- package/build/transport/transportFactory.d.ts.map +1 -0
- package/build/transport/transportFactory.js +148 -0
- package/build/transport/transportFactory.js.map +1 -0
- package/build/utils/clientFiltering.d.ts +4 -4
- package/build/utils/clientFiltering.d.ts.map +1 -1
- package/build/utils/clientFiltering.js +54 -19
- package/build/utils/clientFiltering.js.map +1 -1
- package/build/utils/errorHandling.d.ts +0 -12
- package/build/utils/errorHandling.d.ts.map +1 -1
- package/build/utils/errorHandling.js +1 -42
- package/build/utils/errorHandling.js.map +1 -1
- package/build/utils/pagination.d.ts +2 -2
- package/build/utils/pagination.d.ts.map +1 -1
- package/build/utils/pagination.js +4 -4
- package/build/utils/pagination.js.map +1 -1
- package/build/utils/parsing.d.ts +13 -0
- package/build/utils/parsing.d.ts.map +1 -0
- package/build/utils/parsing.js +32 -0
- package/build/utils/parsing.js.map +1 -0
- package/build/utils/sanitization.d.ts +60 -0
- package/build/utils/sanitization.d.ts.map +1 -0
- package/build/utils/sanitization.js +149 -0
- package/build/utils/sanitization.js.map +1 -0
- package/build/utils/scopeValidation.d.ts +102 -0
- package/build/utils/scopeValidation.d.ts.map +1 -0
- package/build/utils/scopeValidation.js +244 -0
- package/build/utils/scopeValidation.js.map +1 -0
- package/package.json +20 -11
- package/build/auth/authManager.d.ts +0 -109
- package/build/auth/authManager.d.ts.map +0 -1
- package/build/auth/authManager.js +0 -173
- package/build/auth/authManager.js.map +0 -1
- package/build/auth/authMiddleware.d.ts +0 -16
- package/build/auth/authMiddleware.d.ts.map +0 -1
- package/build/auth/authMiddleware.js +0 -45
- package/build/auth/authMiddleware.js.map +0 -1
- package/build/auth/sessionManager.d.ts +0 -197
- package/build/auth/sessionManager.d.ts.map +0 -1
- package/build/auth/sessionManager.js +0 -408
- package/build/auth/sessionManager.js.map +0 -1
- package/build/config/configManager.d.ts.map +0 -1
- package/build/config/configManager.js.map +0 -1
- package/build/core/server/serverConfig.d.ts.map +0 -1
- package/build/core/server/serverConfig.js +0 -117
- package/build/core/server/serverConfig.js.map +0 -1
- package/build/transport/config.d.ts +0 -7
- package/build/transport/config.d.ts.map +0 -1
- package/build/transport/config.js +0 -90
- package/build/transport/config.js.map +0 -1
- package/build/transport/http/errorHandler.d.ts.map +0 -1
- package/build/transport/http/errorHandler.js.map +0 -1
- package/build/transport/http/middleware/loggingMiddleware.d.ts.map +0 -1
- package/build/transport/http/middleware/loggingMiddleware.js.map +0 -1
- package/build/utils/tagsExtractor.d.ts.map +0 -1
- package/build/utils/tagsExtractor.js.map +0 -1
- /package/build/transport/http/{errorHandler.d.ts → middlewares/errorHandler.d.ts} +0 -0
- /package/build/{utils → transport/http/middlewares}/tagsExtractor.d.ts +0 -0
- /package/build/{utils → transport/http/middlewares}/tagsExtractor.js +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import logger from '../../logger/logger.js';
|
|
2
|
+
import { AUTH_CONFIG } from '../../constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* Repository for OAuth client data operations
|
|
5
|
+
*
|
|
6
|
+
* Manages registered OAuth client information with automatic expiration.
|
|
7
|
+
* Client data is stored for a configurable period (default 30 days).
|
|
8
|
+
*/
|
|
9
|
+
export class ClientDataRepository {
|
|
10
|
+
storage;
|
|
11
|
+
constructor(storage) {
|
|
12
|
+
this.storage = storage;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Saves OAuth client data
|
|
16
|
+
*/
|
|
17
|
+
save(clientId, data, ttlMs) {
|
|
18
|
+
const clientData = {
|
|
19
|
+
...data,
|
|
20
|
+
expires: data.client_secret_expires_at ? data.client_secret_expires_at * 1000 : Date.now() + ttlMs,
|
|
21
|
+
createdAt: data.client_id_issued_at ? data.client_id_issued_at * 1000 : Date.now(),
|
|
22
|
+
};
|
|
23
|
+
this.storage.writeData(AUTH_CONFIG.SERVER.SESSION.FILE_PREFIX, clientId, clientData);
|
|
24
|
+
logger.info(`Saved client data: ${clientId}`);
|
|
25
|
+
return clientId;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves OAuth client data by client ID
|
|
29
|
+
*/
|
|
30
|
+
get(clientId) {
|
|
31
|
+
const clientData = this.storage.readData(AUTH_CONFIG.SERVER.SESSION.FILE_PREFIX, clientId);
|
|
32
|
+
return clientData;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Deletes OAuth client data by client ID
|
|
36
|
+
*/
|
|
37
|
+
delete(clientId) {
|
|
38
|
+
const result = this.storage.deleteData(AUTH_CONFIG.SERVER.SESSION.FILE_PREFIX, clientId);
|
|
39
|
+
if (result) {
|
|
40
|
+
logger.info(`Deleted client data: ${clientId}`);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=clientDataRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientDataRepository.js","sourceRoot":"","sources":["../../../src/auth/storage/clientDataRepository.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAKjD;;;;;GAKG;AACH,MAA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77 @@
|
|
|
1
|
+
import { FileStorageService } from './fileStorageService.js';
|
|
2
|
+
import { ClientSessionData } from '../sessionTypes.js';
|
|
3
|
+
/**
|
|
4
|
+
* ClientSessionRepository handles OAuth 2.1 client session storage using the layered storage architecture.
|
|
5
|
+
*
|
|
6
|
+
* This repository manages client sessions for OAuth connections to downstream MCP servers.
|
|
7
|
+
* It follows the same patterns as other repositories (SessionRepository, AuthCodeRepository, etc.)
|
|
8
|
+
* and uses the FileStorageService for consistent data management.
|
|
9
|
+
*
|
|
10
|
+
* Features:
|
|
11
|
+
* - Repository pattern with FileStorageService backend
|
|
12
|
+
* - Server name sanitization for security
|
|
13
|
+
* - Automatic expiration handling
|
|
14
|
+
* - Consistent with other storage repositories
|
|
15
|
+
* - Type-safe client session data management
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const storage = new FileStorageService('/path/to/sessions');
|
|
20
|
+
* const repository = new ClientSessionRepository(storage);
|
|
21
|
+
*
|
|
22
|
+
* const sessionData = {
|
|
23
|
+
* serverName: 'test-server',
|
|
24
|
+
* clientInfo: JSON.stringify(clientInfo),
|
|
25
|
+
* tokens: JSON.stringify(tokens),
|
|
26
|
+
* expires: Date.now() + 3600000,
|
|
27
|
+
* createdAt: Date.now()
|
|
28
|
+
* };
|
|
29
|
+
*
|
|
30
|
+
* repository.save('test-server', sessionData, 3600000);
|
|
31
|
+
* const session = repository.get('test-server');
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare class ClientSessionRepository {
|
|
35
|
+
private storage;
|
|
36
|
+
constructor(storage: FileStorageService);
|
|
37
|
+
/**
|
|
38
|
+
* Saves or updates a client session.
|
|
39
|
+
*
|
|
40
|
+
* @param serverName - The server name for the client session
|
|
41
|
+
* @param clientSessionData - The client session data to store
|
|
42
|
+
* @param ttlMs - Time to live in milliseconds
|
|
43
|
+
* @returns The sanitized server name used as key
|
|
44
|
+
*/
|
|
45
|
+
save(serverName: string, clientSessionData: ClientSessionData, ttlMs: number): string;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves client session data by server name.
|
|
48
|
+
*
|
|
49
|
+
* @param serverName - The server name to retrieve client session for
|
|
50
|
+
* @returns Client session data if exists and not expired, null otherwise
|
|
51
|
+
*/
|
|
52
|
+
get(serverName: string): ClientSessionData | null;
|
|
53
|
+
/**
|
|
54
|
+
* Deletes a client session by server name.
|
|
55
|
+
*
|
|
56
|
+
* @param serverName - The server name to delete client session for
|
|
57
|
+
* @returns True if client session was deleted, false if it didn't exist
|
|
58
|
+
*/
|
|
59
|
+
delete(serverName: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Lists all client session server names.
|
|
62
|
+
*
|
|
63
|
+
* This method scans the storage for client session files and extracts
|
|
64
|
+
* the server names from the file names.
|
|
65
|
+
*
|
|
66
|
+
* @returns Array of server names that have client sessions
|
|
67
|
+
*/
|
|
68
|
+
list(): string[];
|
|
69
|
+
/**
|
|
70
|
+
* Creates a standardized session ID for the server name.
|
|
71
|
+
*
|
|
72
|
+
* @param sanitizedServerName - The sanitized server name
|
|
73
|
+
* @returns The session ID for storage
|
|
74
|
+
*/
|
|
75
|
+
private getSessionId;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=clientSessionRepository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientSessionRepository.d.ts","sourceRoot":"","sources":["../../../src/auth/storage/clientSessionRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAKvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,uBAAuB;IACtB,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,kBAAkB;IAE/C;;;;;;;OAOG;IACH,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAerF;;;;;OAKG;IACH,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI;IAOjD;;;;;OAKG;IACH,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAOnC;;;;;;;OAOG;IACH,IAAI,IAAI,MAAM,EAAE;IA0BhB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;CAGrB"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { AUTH_CONFIG } from '../../constants.js';
|
|
2
|
+
import { sanitizeServerName } from '../../utils/sanitization.js';
|
|
3
|
+
import logger from '../../logger/logger.js';
|
|
4
|
+
/**
|
|
5
|
+
* ClientSessionRepository handles OAuth 2.1 client session storage using the layered storage architecture.
|
|
6
|
+
*
|
|
7
|
+
* This repository manages client sessions for OAuth connections to downstream MCP servers.
|
|
8
|
+
* It follows the same patterns as other repositories (SessionRepository, AuthCodeRepository, etc.)
|
|
9
|
+
* and uses the FileStorageService for consistent data management.
|
|
10
|
+
*
|
|
11
|
+
* Features:
|
|
12
|
+
* - Repository pattern with FileStorageService backend
|
|
13
|
+
* - Server name sanitization for security
|
|
14
|
+
* - Automatic expiration handling
|
|
15
|
+
* - Consistent with other storage repositories
|
|
16
|
+
* - Type-safe client session data management
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const storage = new FileStorageService('/path/to/sessions');
|
|
21
|
+
* const repository = new ClientSessionRepository(storage);
|
|
22
|
+
*
|
|
23
|
+
* const sessionData = {
|
|
24
|
+
* serverName: 'test-server',
|
|
25
|
+
* clientInfo: JSON.stringify(clientInfo),
|
|
26
|
+
* tokens: JSON.stringify(tokens),
|
|
27
|
+
* expires: Date.now() + 3600000,
|
|
28
|
+
* createdAt: Date.now()
|
|
29
|
+
* };
|
|
30
|
+
*
|
|
31
|
+
* repository.save('test-server', sessionData, 3600000);
|
|
32
|
+
* const session = repository.get('test-server');
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export class ClientSessionRepository {
|
|
36
|
+
storage;
|
|
37
|
+
constructor(storage) {
|
|
38
|
+
this.storage = storage;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Saves or updates a client session.
|
|
42
|
+
*
|
|
43
|
+
* @param serverName - The server name for the client session
|
|
44
|
+
* @param clientSessionData - The client session data to store
|
|
45
|
+
* @param ttlMs - Time to live in milliseconds
|
|
46
|
+
* @returns The sanitized server name used as key
|
|
47
|
+
*/
|
|
48
|
+
save(serverName, clientSessionData, ttlMs) {
|
|
49
|
+
const sanitizedServerName = sanitizeServerName(serverName);
|
|
50
|
+
const sessionId = this.getSessionId(sanitizedServerName);
|
|
51
|
+
const dataWithExpiry = {
|
|
52
|
+
...clientSessionData,
|
|
53
|
+
expires: Date.now() + ttlMs,
|
|
54
|
+
createdAt: clientSessionData.createdAt || Date.now(),
|
|
55
|
+
};
|
|
56
|
+
this.storage.writeData(AUTH_CONFIG.CLIENT.SESSION.FILE_PREFIX, sessionId, dataWithExpiry);
|
|
57
|
+
logger.info(`Saved client session for server: ${serverName}`);
|
|
58
|
+
return sanitizedServerName;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves client session data by server name.
|
|
62
|
+
*
|
|
63
|
+
* @param serverName - The server name to retrieve client session for
|
|
64
|
+
* @returns Client session data if exists and not expired, null otherwise
|
|
65
|
+
*/
|
|
66
|
+
get(serverName) {
|
|
67
|
+
const sanitizedServerName = sanitizeServerName(serverName);
|
|
68
|
+
const sessionId = this.getSessionId(sanitizedServerName);
|
|
69
|
+
return this.storage.readData(AUTH_CONFIG.CLIENT.SESSION.FILE_PREFIX, sessionId);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Deletes a client session by server name.
|
|
73
|
+
*
|
|
74
|
+
* @param serverName - The server name to delete client session for
|
|
75
|
+
* @returns True if client session was deleted, false if it didn't exist
|
|
76
|
+
*/
|
|
77
|
+
delete(serverName) {
|
|
78
|
+
const sanitizedServerName = sanitizeServerName(serverName);
|
|
79
|
+
const sessionId = this.getSessionId(sanitizedServerName);
|
|
80
|
+
return this.storage.deleteData(AUTH_CONFIG.CLIENT.SESSION.FILE_PREFIX, sessionId);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Lists all client session server names.
|
|
84
|
+
*
|
|
85
|
+
* This method scans the storage for client session files and extracts
|
|
86
|
+
* the server names from the file names.
|
|
87
|
+
*
|
|
88
|
+
* @returns Array of server names that have client sessions
|
|
89
|
+
*/
|
|
90
|
+
list() {
|
|
91
|
+
// Concatenate FILE_PREFIX and ID_PREFIX to get the full prefix pattern
|
|
92
|
+
const fullPrefix = AUTH_CONFIG.CLIENT.SESSION.FILE_PREFIX + AUTH_CONFIG.CLIENT.SESSION.ID_PREFIX;
|
|
93
|
+
// Get all files that match the full prefix pattern
|
|
94
|
+
const files = this.storage.listFiles(fullPrefix);
|
|
95
|
+
// Extract server names from file names
|
|
96
|
+
return files
|
|
97
|
+
.map((file) => {
|
|
98
|
+
// Remove full prefix and .json suffix to get the server name
|
|
99
|
+
let serverName = file;
|
|
100
|
+
if (serverName.startsWith(fullPrefix)) {
|
|
101
|
+
serverName = serverName.substring(fullPrefix.length);
|
|
102
|
+
}
|
|
103
|
+
if (serverName.endsWith('.json')) {
|
|
104
|
+
serverName = serverName.substring(0, serverName.length - 5);
|
|
105
|
+
}
|
|
106
|
+
return serverName;
|
|
107
|
+
})
|
|
108
|
+
.filter((serverName) => serverName.length > 0);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Creates a standardized session ID for the server name.
|
|
112
|
+
*
|
|
113
|
+
* @param sanitizedServerName - The sanitized server name
|
|
114
|
+
* @returns The session ID for storage
|
|
115
|
+
*/
|
|
116
|
+
getSessionId(sanitizedServerName) {
|
|
117
|
+
return `${AUTH_CONFIG.CLIENT.SESSION.ID_PREFIX}${sanitizedServerName}`;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=clientSessionRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientSessionRepository.js","sourceRoot":"","sources":["../../../src/auth/storage/clientSessionRepository.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,MAAM,MAAM,wBAAwB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,OAAO,uBAAuB;IACd;IAApB,YAAoB,OAA2B;QAA3B,YAAO,GAAP,OAAO,CAAoB;IAAG,CAAC;IAEnD;;;;;;;OAOG;IACH,IAAI,CAAC,UAAkB,EAAE,iBAAoC,EAAE,KAAa;QAC1E,MAAM,mBAAmB,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAC3D,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC;QAEzD,MAAM,cAAc,GAAG;YACrB,GAAG,iBAAiB;YACpB,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;YAC3B,SAAS,EAAE,iBAAiB,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE;SACrD,CAAC;QAEF,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC;QAC1F,MAAM,CAAC,IAAI,CAAC,oCAAoC,UAAU,EAAE,CAAC,CAAC;QAC9D,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,UAAkB;QACpB,MAAM,mBAAmB,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAC3D,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,mB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UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACnD,CAAC;IAED;;;;;OAKG;IACK,YAAY,CAAC,mBAA2B;QAC9C,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,GAAG,mBAAmB,EAAE,CAAC;IACzE,CAAC;CACF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ExpirableData } from '../sessionTypes.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generic file storage service with unified cleanup for all expirable data types.
|
|
4
|
+
*
|
|
5
|
+
* This service provides a common foundation for storing sessions, auth codes,
|
|
6
|
+
* auth requests, and client data with automatic cleanup of expired items.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Generic CRUD operations for any expirable data type
|
|
10
|
+
* - Unified periodic cleanup every 5 minutes
|
|
11
|
+
* - Path traversal protection
|
|
12
|
+
* - Automatic directory creation
|
|
13
|
+
* - Corruption handling (removes corrupted files)
|
|
14
|
+
*/
|
|
15
|
+
export declare class FileStorageService {
|
|
16
|
+
private storageDir;
|
|
17
|
+
private cleanupInterval;
|
|
18
|
+
constructor(storageDir?: string);
|
|
19
|
+
/**
|
|
20
|
+
* Ensures the storage directory exists
|
|
21
|
+
*/
|
|
22
|
+
private ensureDirectory;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the file path for a given prefix and ID
|
|
25
|
+
*/
|
|
26
|
+
getFilePath(filePrefix: string, id: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Validates ID format for security
|
|
29
|
+
*/
|
|
30
|
+
private isValidId;
|
|
31
|
+
/**
|
|
32
|
+
* Writes data to a file with the specified prefix and ID
|
|
33
|
+
*/
|
|
34
|
+
writeData<T extends ExpirableData>(filePrefix: string, id: string, data: T): void;
|
|
35
|
+
/**
|
|
36
|
+
* Reads data from a file with the specified prefix and ID
|
|
37
|
+
* Returns null if file doesn't exist or data is expired
|
|
38
|
+
*/
|
|
39
|
+
readData<T extends ExpirableData>(filePrefix: string, id: string): T | null;
|
|
40
|
+
/**
|
|
41
|
+
* Deletes data file with the specified prefix and ID
|
|
42
|
+
*/
|
|
43
|
+
deleteData(filePrefix: string, id: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Starts periodic cleanup of expired data files
|
|
46
|
+
*/
|
|
47
|
+
private startPeriodicCleanup;
|
|
48
|
+
/**
|
|
49
|
+
* Unified cleanup for all expired data types
|
|
50
|
+
*/
|
|
51
|
+
cleanupExpiredData(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Lists all files in the storage directory that match a given prefix.
|
|
54
|
+
*
|
|
55
|
+
* @param filePrefix - The file prefix to filter by (optional)
|
|
56
|
+
* @returns Array of file names (without directory path)
|
|
57
|
+
*/
|
|
58
|
+
listFiles(filePrefix?: string): string[];
|
|
59
|
+
/**
|
|
60
|
+
* Gets the storage directory path
|
|
61
|
+
*/
|
|
62
|
+
getStorageDir(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Graceful shutdown - stops cleanup interval
|
|
65
|
+
*/
|
|
66
|
+
shutdown(): void;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=fileStorageService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileStorageService.d.ts","sourceRoot":"","sources":["../../../src/auth/storage/fileStorageService.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;;;;;;;;;;GAYG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,eAAe,CAA+C;gBAE1D,UAAU,CAAC,EAAE,MAAM;IAM/B;;OAEG;IACH,OAAO,CAAC,eAAe;IAYvB;;OAEG;IACI,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM;IAmB1D;;OAEG;IACH,OAAO,CAAC,SAAS;IAiDjB;;OAEG;IACH,SAAS,CAAC,CAAC,SAAS,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI;IAWjF;;;OAGG;IACH,QAAQ,CAAC,CAAC,SAAS,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI;IA4B3E;;OAEG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO;IAoBnD;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAU5B;;OAEG;IACI,kBAAkB,IAAI,MAAM;IAyCnC;;;;;OAKG;IACH,SAAS,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE;IAwBxC;;OAEG;IACH,aAAa,IAAI,MAAM;IAIvB;;OAEG;IACH,QAAQ,IAAI,IAAI;CAOjB"}
|
|
@@ -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,YAAY,UAAmB;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,IAAI,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAChG,IAAI,CAAC,eAAe,EAAE,CAAC;QACvB,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACK,eAAe;QACrB,IAAI,CAAC;YACH,IAAI,CAAC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AC,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":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