@1mcp/agent 0.11.0 → 0.13.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.
- package/README.md +45 -50
- package/build/auth/clientSessionManager.d.ts +94 -0
- package/build/auth/clientSessionManager.d.ts.map +1 -0
- package/build/auth/clientSessionManager.js +220 -0
- package/build/auth/clientSessionManager.js.map +1 -0
- package/build/auth/sdkOAuthClientProvider.d.ts +93 -0
- package/build/auth/sdkOAuthClientProvider.d.ts.map +1 -0
- package/build/auth/sdkOAuthClientProvider.js +199 -0
- package/build/auth/sdkOAuthClientProvider.js.map +1 -0
- package/build/auth/sdkOAuthServerProvider.d.ts +63 -0
- package/build/auth/sdkOAuthServerProvider.d.ts.map +1 -0
- package/build/auth/sdkOAuthServerProvider.js +428 -0
- package/build/auth/sdkOAuthServerProvider.js.map +1 -0
- package/build/{server/auth/sessionManager.d.ts → auth/serverSessionManager.d.ts} +26 -37
- package/build/auth/serverSessionManager.d.ts.map +1 -0
- package/build/{server/auth/sessionManager.js → auth/serverSessionManager.js} +104 -19
- package/build/auth/serverSessionManager.js.map +1 -0
- package/build/auth/sessionTypes.d.ts +24 -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/capabilities/capabilityManager.d.ts +2 -2
- package/build/capabilities/capabilityManager.d.ts.map +1 -1
- package/build/capabilities/capabilityManager.js +40 -7
- package/build/capabilities/capabilityManager.js.map +1 -1
- package/build/config/{configManager.d.ts → mcpConfigManager.d.ts} +18 -7
- package/build/config/mcpConfigManager.d.ts.map +1 -0
- package/build/config/{configManager.js → mcpConfigManager.js} +50 -10
- package/build/config/mcpConfigManager.js.map +1 -0
- package/build/constants.d.ts +36 -14
- package/build/constants.d.ts.map +1 -1
- package/build/constants.js +40 -17
- package/build/constants.js.map +1 -1
- package/build/{client.d.ts → core/client/clientFactory.d.ts} +1 -1
- package/build/core/client/clientFactory.d.ts.map +1 -0
- package/build/{client.js → core/client/clientFactory.js} +2 -2
- package/build/core/client/clientFactory.js.map +1 -0
- package/build/{clients → core/client}/clientManager.d.ts +14 -6
- package/build/core/client/clientManager.d.ts.map +1 -0
- package/build/core/client/clientManager.js +209 -0
- package/build/core/client/clientManager.js.map +1 -0
- package/build/{server/config/serverConfig.d.ts → core/server/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 +39 -0
- package/build/core/server/serverManager.d.ts.map +1 -0
- package/build/core/server/serverManager.js +169 -0
- package/build/core/server/serverManager.js.map +1 -0
- package/build/core/types/client.d.ts +51 -0
- package/build/core/types/client.d.ts.map +1 -0
- package/build/core/types/client.js +15 -0
- package/build/core/types/client.js.map +1 -0
- package/build/core/types/index.d.ts +4 -0
- package/build/core/types/index.d.ts.map +1 -0
- package/build/core/types/index.js +5 -0
- package/build/core/types/index.js.map +1 -0
- package/build/core/types/server.d.ts +14 -0
- package/build/core/types/server.d.ts.map +1 -0
- package/build/core/types/server.js +2 -0
- package/build/core/types/server.js.map +1 -0
- package/build/{types.d.ts → core/types/transport.d.ts} +59 -49
- package/build/core/types/transport.d.ts.map +1 -0
- package/build/{types.js → core/types/transport.js} +11 -13
- package/build/core/types/transport.js.map +1 -0
- package/build/handlers/notificationHandlers.d.ts +3 -3
- package/build/handlers/notificationHandlers.d.ts.map +1 -1
- package/build/handlers/notificationHandlers.js +13 -9
- 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 +25 -3
- package/build/handlers/requestHandlers.js.map +1 -1
- package/build/index.js +48 -8
- package/build/index.js.map +1 -1
- package/build/logger/logger.js +1 -1
- package/build/logger/logger.js.map +1 -1
- package/build/{middleware/loggingMiddleware.d.ts → logger/mcpLoggingEnhancer.d.ts} +1 -1
- package/build/logger/mcpLoggingEnhancer.d.ts.map +1 -0
- package/build/{middleware/loggingMiddleware.js → logger/mcpLoggingEnhancer.js} +2 -2
- package/build/logger/mcpLoggingEnhancer.js.map +1 -0
- package/build/server.d.ts +1 -1
- package/build/server.d.ts.map +1 -1
- package/build/server.js +9 -6
- package/build/server.js.map +1 -1
- package/build/services/configReloadService.d.ts +15 -5
- package/build/services/configReloadService.d.ts.map +1 -1
- package/build/services/configReloadService.js +31 -14
- package/build/services/configReloadService.js.map +1 -1
- package/build/transport/http/middlewares/errorHandler.d.ts.map +1 -0
- package/build/{server → transport/http/middlewares}/errorHandler.js +1 -1
- package/build/transport/http/middlewares/errorHandler.js.map +1 -0
- package/build/transport/http/middlewares/scopeAuthMiddleware.d.ts +42 -0
- package/build/transport/http/middlewares/scopeAuthMiddleware.d.ts.map +1 -0
- package/build/transport/http/middlewares/scopeAuthMiddleware.js +136 -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 +4 -0
- package/build/transport/http/routes/oauthRoutes.d.ts.map +1 -0
- package/build/transport/http/routes/oauthRoutes.js +474 -0
- package/build/transport/http/routes/oauthRoutes.js.map +1 -0
- package/build/transport/http/routes/sseRoutes.d.ts +4 -0
- package/build/transport/http/routes/sseRoutes.d.ts.map +1 -0
- package/build/{server → transport/http}/routes/sseRoutes.js +12 -10
- package/build/transport/http/routes/sseRoutes.js.map +1 -0
- package/build/transport/http/routes/streamableHttpRoutes.d.ts +4 -0
- package/build/transport/http/routes/streamableHttpRoutes.d.ts.map +1 -0
- package/build/{server → transport/http}/routes/streamableHttpRoutes.js +46 -13
- package/build/transport/http/routes/streamableHttpRoutes.js.map +1 -0
- package/build/{server/expressServer.d.ts → transport/http/server.d.ts} +5 -4
- package/build/transport/http/server.d.ts.map +1 -0
- package/build/{server/expressServer.js → transport/http/server.js} +60 -23
- package/build/transport/http/server.js.map +1 -0
- 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 +14 -14
- package/build/utils/clientFiltering.js.map +1 -1
- package/build/utils/errorHandling.d.ts +0 -11
- package/build/utils/errorHandling.d.ts.map +1 -1
- package/build/utils/errorHandling.js +1 -18
- package/build/utils/errorHandling.js.map +1 -1
- package/build/utils/errorTypes.js +4 -4
- package/build/utils/errorTypes.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 +87 -8
- 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 +23 -9
- package/build/client.d.ts.map +0 -1
- package/build/client.js.map +0 -1
- package/build/clients/clientManager.d.ts.map +0 -1
- package/build/clients/clientManager.js +0 -147
- package/build/clients/clientManager.js.map +0 -1
- package/build/config/configManager.d.ts.map +0 -1
- package/build/config/configManager.js.map +0 -1
- package/build/config/transportConfig.d.ts +0 -7
- package/build/config/transportConfig.d.ts.map +0 -1
- package/build/config/transportConfig.js +0 -90
- package/build/config/transportConfig.js.map +0 -1
- package/build/middleware/loggingMiddleware.d.ts.map +0 -1
- package/build/middleware/loggingMiddleware.js.map +0 -1
- package/build/server/auth/authManager.d.ts +0 -109
- package/build/server/auth/authManager.d.ts.map +0 -1
- package/build/server/auth/authManager.js +0 -173
- package/build/server/auth/authManager.js.map +0 -1
- package/build/server/auth/authMiddleware.d.ts +0 -16
- package/build/server/auth/authMiddleware.d.ts.map +0 -1
- package/build/server/auth/authMiddleware.js +0 -45
- package/build/server/auth/authMiddleware.js.map +0 -1
- package/build/server/auth/sessionManager.d.ts.map +0 -1
- package/build/server/auth/sessionManager.js.map +0 -1
- package/build/server/config/serverConfig.d.ts.map +0 -1
- package/build/server/config/serverConfig.js +0 -117
- package/build/server/config/serverConfig.js.map +0 -1
- package/build/server/errorHandler.d.ts.map +0 -1
- package/build/server/errorHandler.js.map +0 -1
- package/build/server/expressServer.d.ts.map +0 -1
- package/build/server/expressServer.js.map +0 -1
- package/build/server/routes/oauthRoutes.d.ts +0 -14
- package/build/server/routes/oauthRoutes.d.ts.map +0 -1
- package/build/server/routes/oauthRoutes.js +0 -132
- package/build/server/routes/oauthRoutes.js.map +0 -1
- package/build/server/routes/sseRoutes.d.ts +0 -4
- package/build/server/routes/sseRoutes.d.ts.map +0 -1
- package/build/server/routes/sseRoutes.js.map +0 -1
- package/build/server/routes/streamableHttpRoutes.d.ts +0 -4
- package/build/server/routes/streamableHttpRoutes.d.ts.map +0 -1
- package/build/server/routes/streamableHttpRoutes.js.map +0 -1
- package/build/server/tagsExtractor.d.ts.map +0 -1
- package/build/server/tagsExtractor.js.map +0 -1
- package/build/serverManager.d.ts +0 -27
- package/build/serverManager.d.ts.map +0 -1
- package/build/serverManager.js +0 -87
- package/build/serverManager.js.map +0 -1
- package/build/types.d.ts.map +0 -1
- package/build/types.js.map +0 -1
- /package/build/{server → transport/http/middlewares}/errorHandler.d.ts +0 -0
- /package/build/{server → transport/http/middlewares}/tagsExtractor.d.ts +0 -0
- /package/build/{server → transport/http/middlewares}/tagsExtractor.js +0 -0
package/README.md
CHANGED
|
@@ -16,25 +16,29 @@ A unified Model Context Protocol server implementation that aggregates multiple
|
|
|
16
16
|
- Provides a standardized way for AI models to interact with external tools and resources
|
|
17
17
|
- Supports dynamic configuration reloading without server restart
|
|
18
18
|
- Handles graceful shutdown and resource cleanup
|
|
19
|
+
- Includes comprehensive authentication and security features
|
|
20
|
+
- Supports advanced filtering, pagination, and request optimization
|
|
19
21
|
|
|
20
22
|
## Quick Start
|
|
21
23
|
|
|
22
24
|
To enable Cursor to use existing MCP servers already configured in Claude Desktop, follow these steps:
|
|
23
25
|
|
|
24
26
|
1. Run the 1MCP server with the Claude Desktop config file:
|
|
27
|
+
|
|
25
28
|
```bash
|
|
26
29
|
npx -y @1mcp/agent --config ~/Library/Application\ Support/Claude/claude_desktop_config.json
|
|
27
30
|
```
|
|
28
31
|
|
|
29
32
|
2. Add the 1MCP server to your Cursor config file (`~/.cursor/mcp.json`):
|
|
33
|
+
|
|
30
34
|
```json
|
|
31
35
|
{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
36
|
+
"mcpServers": {
|
|
37
|
+
"1mcp": {
|
|
38
|
+
"type": "http",
|
|
39
|
+
"url": "http://localhost:3050/sse"
|
|
37
40
|
}
|
|
41
|
+
}
|
|
38
42
|
}
|
|
39
43
|
```
|
|
40
44
|
|
|
@@ -59,27 +63,26 @@ npx -y @1mcp/agent --help
|
|
|
59
63
|
```
|
|
60
64
|
|
|
61
65
|
Available options:
|
|
62
|
-
- `--transport, -t`: Choose transport type ("stdio" or "http", default: "http")
|
|
63
|
-
- `--config, -c`: Use a specific config file
|
|
64
|
-
- `--port, -P`: Change HTTP port (default: 3050)
|
|
65
|
-
- `--host, -H`: Change HTTP host (default: localhost)
|
|
66
|
-
- `--tags, -g`: Filter servers by tags (see Tags section below)
|
|
67
|
-
- `--pagination, -p`: Enable pagination for client/server lists (boolean, default: false)
|
|
68
|
-
- `--auth`: Enable authentication (OAuth 2.1) (boolean, default: false)
|
|
69
|
-
- `--session-ttl`: Session expiry time in minutes (number, default: 1440)
|
|
70
|
-
- `--session-storage-path`: Custom session storage directory path (string, default: undefined)
|
|
71
|
-
- `--help, -h`: Show help
|
|
72
|
-
|
|
73
|
-
Example with environment variables:
|
|
74
|
-
```bash
|
|
75
|
-
# Using environment variables
|
|
76
|
-
ONE_MCP_PORT=3051 ONE_MCP_TAGS=network,filesystem npx -y @1mcp/agent
|
|
77
66
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
67
|
+
| Option (CLI) | Environment Variable | Description | Default | Deprecated? |
|
|
68
|
+
| :--------------------------- | :--------------------------------- | :---------------------------------------------------- | :-------: | :---------: |
|
|
69
|
+
| `--transport`, `-t` | `ONE_MCP_TRANSPORT` | Choose transport type ("stdio", "http", or "sse") | "http" | |
|
|
70
|
+
| `--config`, `-c` | `ONE_MCP_CONFIG` | Use a specific config file | | |
|
|
71
|
+
| `--port`, `-P` | `ONE_MCP_PORT` | Change HTTP port | 3050 | |
|
|
72
|
+
| `--host`, `-H` | `ONE_MCP_HOST` | Change HTTP host | localhost | |
|
|
73
|
+
| `--tags`, `-g` | `ONE_MCP_TAGS` | Filter servers by tags | | |
|
|
74
|
+
| `--pagination`, `-p` | `ONE_MCP_PAGINATION` | Enable pagination for client/server lists (boolean) | false | |
|
|
75
|
+
| `--auth` | `ONE_MCP_AUTH` | Enable authentication (OAuth 2.1) | false | Yes |
|
|
76
|
+
| `--enable-auth` | `ONE_MCP_ENABLE_AUTH` | Enable authentication (OAuth 2.1) | false | |
|
|
77
|
+
| `--enable-scope-validation` | `ONE_MCP_ENABLE_SCOPE_VALIDATION` | Enable tag-based scope validation (boolean) | true | |
|
|
78
|
+
| `--enable-enhanced-security` | `ONE_MCP_ENABLE_ENHANCED_SECURITY` | Enable enhanced security middleware (boolean) | false | |
|
|
79
|
+
| `--session-ttl` | `ONE_MCP_SESSION_TTL` | Session expiry time in minutes (number) | 1440 | |
|
|
80
|
+
| `--session-storage-path` | `ONE_MCP_SESSION_STORAGE_PATH` | Custom session storage directory path (string) | | |
|
|
81
|
+
| `--rate-limit-window` | `ONE_MCP_RATE_LIMIT_WINDOW` | OAuth rate limit window in minutes (number) | 15 | |
|
|
82
|
+
| `--rate-limit-max` | `ONE_MCP_RATE_LIMIT_MAX` | Maximum requests per OAuth rate limit window (number) | 100 | |
|
|
83
|
+
| `--help`, `-h` | | Show help | | |
|
|
84
|
+
|
|
85
|
+
> 💡 **Note:** Deprecated options are provided for backward compatibility. Prefer using the non-deprecated options for new configurations.
|
|
83
86
|
|
|
84
87
|
## Docker
|
|
85
88
|
|
|
@@ -100,24 +103,13 @@ docker run -i ghcr.io/1mcp-app/agent --transport stdio
|
|
|
100
103
|
```
|
|
101
104
|
|
|
102
105
|
Available image tags:
|
|
106
|
+
|
|
103
107
|
- `latest`: Latest stable release
|
|
104
108
|
- `vX.Y.Z`: Specific version (e.g. `v1.0.0`)
|
|
105
109
|
- `sha-<commit>`: Specific commit
|
|
106
110
|
|
|
107
|
-
|
|
111
|
+
Example:
|
|
108
112
|
|
|
109
|
-
You can configure 1MCP using environment variables prefixed with `ONE_MCP_`:
|
|
110
|
-
- `ONE_MCP_TRANSPORT`: Transport type ("stdio" or "http", default: "http")
|
|
111
|
-
- `ONE_MCP_PORT`: HTTP port (default: 3050)
|
|
112
|
-
- `ONE_MCP_HOST`: HTTP host (default: "localhost")
|
|
113
|
-
- `ONE_MCP_CONFIG`: Path to config file
|
|
114
|
-
- `ONE_MCP_TAGS`: Comma-separated list of tags to filter servers
|
|
115
|
-
- `ONE_MCP_PAGINATION`: Enable pagination for client/server lists (boolean, default: false)
|
|
116
|
-
- `ONE_MCP_AUTH`: Enable authentication (OAuth 2.1) (boolean, default: false)
|
|
117
|
-
- `ONE_MCP_SESSION_TTL`: Session expiry time in minutes (number, default: 1440)
|
|
118
|
-
- `ONE_MCP_SESSION_STORAGE_PATH`: Custom session storage directory path (string, default: undefined)
|
|
119
|
-
|
|
120
|
-
Example with environment variables:
|
|
121
113
|
```bash
|
|
122
114
|
docker run -p 3051:3051 \
|
|
123
115
|
-e ONE_MCP_PORT=3051 \
|
|
@@ -132,6 +124,7 @@ Tags help you control which MCP servers are available to different clients. Thin
|
|
|
132
124
|
#### How to Use Tags
|
|
133
125
|
|
|
134
126
|
1. **In your server config**: Add tags to each server to describe its capabilities
|
|
127
|
+
|
|
135
128
|
```json
|
|
136
129
|
{
|
|
137
130
|
"mcpServers": {
|
|
@@ -152,6 +145,7 @@ Tags help you control which MCP servers are available to different clients. Thin
|
|
|
152
145
|
```
|
|
153
146
|
|
|
154
147
|
2. **When starting 1MCP in stdio mode**: You can filter servers by tags
|
|
148
|
+
|
|
155
149
|
```bash
|
|
156
150
|
# Only start servers with the "network" tag
|
|
157
151
|
npx -y @1mcp/agent --transport stdio --tags "network"
|
|
@@ -161,18 +155,20 @@ npx -y @1mcp/agent --transport stdio --tags "network,filesystem"
|
|
|
161
155
|
```
|
|
162
156
|
|
|
163
157
|
3. **When using SSE transport**: Clients can request servers with specific tags
|
|
158
|
+
|
|
164
159
|
```json
|
|
165
160
|
{
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
161
|
+
"mcpServers": {
|
|
162
|
+
"1mcp": {
|
|
163
|
+
"type": "http",
|
|
164
|
+
"url": "http://localhost:3050/sse?tags=network" // Only connect to network-capable servers
|
|
171
165
|
}
|
|
166
|
+
}
|
|
172
167
|
}
|
|
173
168
|
```
|
|
174
169
|
|
|
175
170
|
Example tags:
|
|
171
|
+
|
|
176
172
|
- `network`: For servers that make web requests
|
|
177
173
|
- `filesystem`: For servers that handle file operations
|
|
178
174
|
- `memory`: For servers that provide memory/storage
|
|
@@ -195,17 +191,12 @@ The server automatically manages configuration in a global location:
|
|
|
195
191
|
"mcpServers": {
|
|
196
192
|
"mcp-server-fetch": {
|
|
197
193
|
"command": "uvx",
|
|
198
|
-
"args": [
|
|
199
|
-
"mcp-server-fetch"
|
|
200
|
-
],
|
|
194
|
+
"args": ["mcp-server-fetch"],
|
|
201
195
|
"disabled": false
|
|
202
196
|
},
|
|
203
197
|
"server-memory": {
|
|
204
198
|
"command": "npx",
|
|
205
|
-
"args": [
|
|
206
|
-
"-y",
|
|
207
|
-
"@modelcontextprotocol/server-memory"
|
|
208
|
-
],
|
|
199
|
+
"args": ["-y", "@modelcontextprotocol/server-memory"],
|
|
209
200
|
"disabled": false
|
|
210
201
|
}
|
|
211
202
|
}
|
|
@@ -271,21 +262,25 @@ sequenceDiagram
|
|
|
271
262
|
## Development
|
|
272
263
|
|
|
273
264
|
Install dependencies:
|
|
265
|
+
|
|
274
266
|
```bash
|
|
275
267
|
pnpm install
|
|
276
268
|
```
|
|
277
269
|
|
|
278
270
|
Build the server:
|
|
271
|
+
|
|
279
272
|
```bash
|
|
280
273
|
pnpm build
|
|
281
274
|
```
|
|
282
275
|
|
|
283
276
|
For development with auto-rebuild:
|
|
277
|
+
|
|
284
278
|
```bash
|
|
285
279
|
pnpm watch
|
|
286
280
|
```
|
|
287
281
|
|
|
288
282
|
Run the server:
|
|
283
|
+
|
|
289
284
|
```bash
|
|
290
285
|
pnpm dev
|
|
291
286
|
```
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { ClientSessionData } from './sessionTypes.js';
|
|
2
|
+
/**
|
|
3
|
+
* ClientSessionManager handles file-based client session storage with automatic cleanup.
|
|
4
|
+
*
|
|
5
|
+
* This class manages OAuth 2.1 client sessions using the local filesystem.
|
|
6
|
+
* It provides automatic cleanup of expired sessions and supports configurable
|
|
7
|
+
* storage locations separate from server sessions.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - File-based client session storage with JSON format
|
|
11
|
+
* - Automatic cleanup of expired client sessions
|
|
12
|
+
* - Server name sanitization for safe filenames
|
|
13
|
+
* - Configurable storage directory
|
|
14
|
+
* - Unified session data per server
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const clientSessionManager = new ClientSessionManager();
|
|
19
|
+
* const sessionData = { serverName: 'test', ... };
|
|
20
|
+
* clientSessionManager.createClientSession('test', sessionData);
|
|
21
|
+
* const session = clientSessionManager.getClientSession('test');
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class ClientSessionManager {
|
|
25
|
+
private clientSessionStoragePath;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new ClientSessionManager instance.
|
|
28
|
+
*
|
|
29
|
+
* Initializes the client session storage directory.
|
|
30
|
+
*
|
|
31
|
+
* @param clientSessionStoragePath - Optional custom path for client session storage
|
|
32
|
+
*/
|
|
33
|
+
constructor(clientSessionStoragePath?: string);
|
|
34
|
+
/**
|
|
35
|
+
* Gets the client session storage path.
|
|
36
|
+
*
|
|
37
|
+
* @returns The absolute path to the client session storage directory
|
|
38
|
+
*/
|
|
39
|
+
getClientSessionStoragePath(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Ensures the client session storage directory exists.
|
|
42
|
+
*
|
|
43
|
+
* Creates the directory structure if it doesn't exist, including
|
|
44
|
+
* parent directories as needed.
|
|
45
|
+
*
|
|
46
|
+
* @throws Error if directory creation fails
|
|
47
|
+
*/
|
|
48
|
+
private ensureClientSessionDirectory;
|
|
49
|
+
/**
|
|
50
|
+
* Gets the file path for a client session.
|
|
51
|
+
*
|
|
52
|
+
* @param serverName - The server name for the client session
|
|
53
|
+
* @returns Full file path for the client session file
|
|
54
|
+
*/
|
|
55
|
+
private getClientSessionFilePath;
|
|
56
|
+
/**
|
|
57
|
+
* Creates or updates a client session.
|
|
58
|
+
*
|
|
59
|
+
* @param serverName - The server name for the client session
|
|
60
|
+
* @param clientSessionData - The client session data to store
|
|
61
|
+
* @returns The server name
|
|
62
|
+
* @throws Error if client session creation fails
|
|
63
|
+
*/
|
|
64
|
+
createClientSession(serverName: string, clientSessionData: ClientSessionData): string;
|
|
65
|
+
/**
|
|
66
|
+
* Retrieves client session data by server name.
|
|
67
|
+
*
|
|
68
|
+
* @param serverName - The server name to retrieve client session for
|
|
69
|
+
* @returns Client session data if valid and not expired, null otherwise
|
|
70
|
+
*/
|
|
71
|
+
getClientSession(serverName: string): ClientSessionData | null;
|
|
72
|
+
/**
|
|
73
|
+
* Deletes a client session by server name.
|
|
74
|
+
*
|
|
75
|
+
* @param serverName - The server name to delete client session for
|
|
76
|
+
* @returns True if client session was deleted, false if it didn't exist
|
|
77
|
+
*/
|
|
78
|
+
deleteClientSession(serverName: string): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Cleans up expired client sessions.
|
|
81
|
+
*
|
|
82
|
+
* Scans the client session storage directory and removes all expired
|
|
83
|
+
* client session files. Also handles corrupted files by removing them
|
|
84
|
+
* to prevent future errors.
|
|
85
|
+
*/
|
|
86
|
+
cleanupExpiredClientSessions(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Lists all client session files in the storage directory.
|
|
89
|
+
*
|
|
90
|
+
* @returns Array of server names that have client sessions
|
|
91
|
+
*/
|
|
92
|
+
listClientSessions(): string[];
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=clientSessionManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientSessionManager.d.ts","sourceRoot":"","sources":["../../src/auth/clientSessionManager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGtD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,wBAAwB,CAAS;IAEzC;;;;;;OAMG;gBACS,wBAAwB,CAAC,EAAE,MAAM;IAK7C;;;;OAIG;IACI,2BAA2B,IAAI,MAAM;IAI5C;;;;;;;OAOG;IACH,OAAO,CAAC,4BAA4B;IAYpC;;;;;OAKG;IACH,OAAO,CAAC,wBAAwB;IAgBhC;;;;;;;OAOG;IACI,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,iBAAiB,EAAE,iBAAiB,GAAG,MAAM;IAY5F;;;;;OAKG;IACI,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI;IAsBrE;;;;;OAKG;IACI,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAevD;;;;;;OAMG;IACI,4BAA4B,IAAI,IAAI;IAyC3C;;;;OAIG;IACI,kBAAkB,IAAI,MAAM,EAAE;CAetC"}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import logger from '../logger/logger.js';
|
|
4
|
+
import { getGlobalConfigDir } from '../constants.js';
|
|
5
|
+
import { sanitizeServerName } from '../utils/sanitization.js';
|
|
6
|
+
/**
|
|
7
|
+
* ClientSessionManager handles file-based client session storage with automatic cleanup.
|
|
8
|
+
*
|
|
9
|
+
* This class manages OAuth 2.1 client sessions using the local filesystem.
|
|
10
|
+
* It provides automatic cleanup of expired sessions and supports configurable
|
|
11
|
+
* storage locations separate from server sessions.
|
|
12
|
+
*
|
|
13
|
+
* Features:
|
|
14
|
+
* - File-based client session storage with JSON format
|
|
15
|
+
* - Automatic cleanup of expired client sessions
|
|
16
|
+
* - Server name sanitization for safe filenames
|
|
17
|
+
* - Configurable storage directory
|
|
18
|
+
* - Unified session data per server
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const clientSessionManager = new ClientSessionManager();
|
|
23
|
+
* const sessionData = { serverName: 'test', ... };
|
|
24
|
+
* clientSessionManager.createClientSession('test', sessionData);
|
|
25
|
+
* const session = clientSessionManager.getClientSession('test');
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export class ClientSessionManager {
|
|
29
|
+
clientSessionStoragePath;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new ClientSessionManager instance.
|
|
32
|
+
*
|
|
33
|
+
* Initializes the client session storage directory.
|
|
34
|
+
*
|
|
35
|
+
* @param clientSessionStoragePath - Optional custom path for client session storage
|
|
36
|
+
*/
|
|
37
|
+
constructor(clientSessionStoragePath) {
|
|
38
|
+
this.clientSessionStoragePath = clientSessionStoragePath || path.join(getGlobalConfigDir(), 'clientSessions');
|
|
39
|
+
this.ensureClientSessionDirectory();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Gets the client session storage path.
|
|
43
|
+
*
|
|
44
|
+
* @returns The absolute path to the client session storage directory
|
|
45
|
+
*/
|
|
46
|
+
getClientSessionStoragePath() {
|
|
47
|
+
return this.clientSessionStoragePath;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Ensures the client session storage directory exists.
|
|
51
|
+
*
|
|
52
|
+
* Creates the directory structure if it doesn't exist, including
|
|
53
|
+
* parent directories as needed.
|
|
54
|
+
*
|
|
55
|
+
* @throws Error if directory creation fails
|
|
56
|
+
*/
|
|
57
|
+
ensureClientSessionDirectory() {
|
|
58
|
+
try {
|
|
59
|
+
if (!fs.existsSync(this.clientSessionStoragePath)) {
|
|
60
|
+
fs.mkdirSync(this.clientSessionStoragePath, { recursive: true });
|
|
61
|
+
logger.info(`Created client session storage directory: ${this.clientSessionStoragePath}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
logger.error(`Failed to create client session directory: ${error}`);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Gets the file path for a client session.
|
|
71
|
+
*
|
|
72
|
+
* @param serverName - The server name for the client session
|
|
73
|
+
* @returns Full file path for the client session file
|
|
74
|
+
*/
|
|
75
|
+
getClientSessionFilePath(serverName) {
|
|
76
|
+
const sanitizedServerName = sanitizeServerName(serverName);
|
|
77
|
+
const fileName = `oauth_${sanitizedServerName}.json`;
|
|
78
|
+
const filePath = path.resolve(this.clientSessionStoragePath, fileName);
|
|
79
|
+
// Additional security check: ensure resolved path is within client session storage
|
|
80
|
+
const normalizedStoragePath = path.resolve(this.clientSessionStoragePath);
|
|
81
|
+
const normalizedFilePath = path.resolve(filePath);
|
|
82
|
+
if (!normalizedFilePath.startsWith(normalizedStoragePath + path.sep)) {
|
|
83
|
+
throw new Error('Invalid client session file path: outside storage directory');
|
|
84
|
+
}
|
|
85
|
+
return filePath;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Creates or updates a client session.
|
|
89
|
+
*
|
|
90
|
+
* @param serverName - The server name for the client session
|
|
91
|
+
* @param clientSessionData - The client session data to store
|
|
92
|
+
* @returns The server name
|
|
93
|
+
* @throws Error if client session creation fails
|
|
94
|
+
*/
|
|
95
|
+
createClientSession(serverName, clientSessionData) {
|
|
96
|
+
try {
|
|
97
|
+
const filePath = this.getClientSessionFilePath(serverName);
|
|
98
|
+
fs.writeFileSync(filePath, JSON.stringify(clientSessionData, null, 2));
|
|
99
|
+
logger.info(`Created/updated client session for server: ${serverName}`);
|
|
100
|
+
return serverName;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
logger.error(`Failed to create client session for ${serverName}: ${error}`);
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Retrieves client session data by server name.
|
|
109
|
+
*
|
|
110
|
+
* @param serverName - The server name to retrieve client session for
|
|
111
|
+
* @returns Client session data if valid and not expired, null otherwise
|
|
112
|
+
*/
|
|
113
|
+
getClientSession(serverName) {
|
|
114
|
+
try {
|
|
115
|
+
const filePath = this.getClientSessionFilePath(serverName);
|
|
116
|
+
if (!fs.existsSync(filePath)) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
|
120
|
+
const clientSessionData = JSON.parse(data);
|
|
121
|
+
if (clientSessionData.expires < Date.now()) {
|
|
122
|
+
this.deleteClientSession(serverName);
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
return clientSessionData;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
logger.error(`Failed to read client session for ${serverName}: ${error}`);
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Deletes a client session by server name.
|
|
134
|
+
*
|
|
135
|
+
* @param serverName - The server name to delete client session for
|
|
136
|
+
* @returns True if client session was deleted, false if it didn't exist
|
|
137
|
+
*/
|
|
138
|
+
deleteClientSession(serverName) {
|
|
139
|
+
try {
|
|
140
|
+
const filePath = this.getClientSessionFilePath(serverName);
|
|
141
|
+
if (fs.existsSync(filePath)) {
|
|
142
|
+
fs.unlinkSync(filePath);
|
|
143
|
+
logger.info(`Deleted client session for server: ${serverName}`);
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
logger.error(`Failed to delete client session for ${serverName}: ${error}`);
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Cleans up expired client sessions.
|
|
155
|
+
*
|
|
156
|
+
* Scans the client session storage directory and removes all expired
|
|
157
|
+
* client session files. Also handles corrupted files by removing them
|
|
158
|
+
* to prevent future errors.
|
|
159
|
+
*/
|
|
160
|
+
cleanupExpiredClientSessions() {
|
|
161
|
+
try {
|
|
162
|
+
if (!fs.existsSync(this.clientSessionStoragePath)) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const files = fs.readdirSync(this.clientSessionStoragePath);
|
|
166
|
+
let cleanedCount = 0;
|
|
167
|
+
for (const file of files) {
|
|
168
|
+
if (file.endsWith('.json') && file.startsWith('oauth_')) {
|
|
169
|
+
const filePath = path.join(this.clientSessionStoragePath, file);
|
|
170
|
+
try {
|
|
171
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
|
172
|
+
const clientSessionData = JSON.parse(data);
|
|
173
|
+
if (clientSessionData.expires < Date.now()) {
|
|
174
|
+
fs.unlinkSync(filePath);
|
|
175
|
+
cleanedCount++;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
logger.warn(`Failed to process client session file ${file}: ${error}`);
|
|
180
|
+
// Remove corrupted files
|
|
181
|
+
try {
|
|
182
|
+
fs.unlinkSync(filePath);
|
|
183
|
+
cleanedCount++;
|
|
184
|
+
}
|
|
185
|
+
catch (unlinkError) {
|
|
186
|
+
logger.error(`Failed to remove corrupted client session file ${file}: ${unlinkError}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (cleanedCount > 0) {
|
|
192
|
+
logger.info(`Cleaned up ${cleanedCount} expired client sessions`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
logger.error(`Failed to cleanup expired client sessions: ${error}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Lists all client session files in the storage directory.
|
|
201
|
+
*
|
|
202
|
+
* @returns Array of server names that have client sessions
|
|
203
|
+
*/
|
|
204
|
+
listClientSessions() {
|
|
205
|
+
try {
|
|
206
|
+
if (!fs.existsSync(this.clientSessionStoragePath)) {
|
|
207
|
+
return [];
|
|
208
|
+
}
|
|
209
|
+
const files = fs.readdirSync(this.clientSessionStoragePath);
|
|
210
|
+
return files
|
|
211
|
+
.filter((file) => file.endsWith('.json') && file.startsWith('oauth_'))
|
|
212
|
+
.map((file) => file.substring(6, file.length - 5)); // Remove 'oauth_' prefix and '.json' suffix
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
logger.error(`Failed to list client sessions: ${error}`);
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=clientSessionManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientSessionManager.js","sourceRoot":"","sources":["../../src/auth/clientSessionManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,oBAAoB;IACvB,wBAAwB,CAAS;IAEzC;;;;;;OAMG;IACH,YAAY,wBAAiC;QAC3C,IAAI,CAAC,wBAAwB,GAAG,wBAAwB,IAAI,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,gBAAgB,CAAC,CAAC;QAC9G,IAAI,CAAC,4BAA4B,EAAE,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACI,2BAA2B;QAChC,OAAO,IAAI,CAAC,wBAAwB,CAAC;IACvC,CAAC;IAED;;;;;;;OAOG;IACK,4BAA4B;QAClC,IAAI,CAAC;YACH,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,wBAAwB,CAAC,EAAE,CAAC;gBAClD,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,wBAAwB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;gBACjE,MAAM,CAAC,IAAI,CAAC,6CAA6C,IAAI,CAAC,wBAAwB,EAAE,CAAC,CAAC;YAC5F,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,8CAA8C,KAAK,EAAE,CAAC,CAAC;YACpE,MAAM,KAAK,CAAC;QACd,CAAC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BACrB,MAAM,CAAC,IAAI,CAAC,cAAc,YAAY,0BAA0B,CAAC,CAAC;YACpE,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,8CAA8C,KAAK,EAAE,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,kBAAkB;QACvB,IAAI,CAAC;YACH,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,wBAAwB,CAAC,EAAE,CAAC;gBAClD,OAAO,EAAE,CAAC;YACZ,CAAC;YAED,MAAM,KAAK,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;YAC5D,OAAO,KAAK;iBACT,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;iBACrE,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,4CAA4C;QACpG,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,mCAAmC,KAAK,EAAE,CAAC,CAAC;YACzD,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
2
|
+
import type { OAuthClientMetadata, OAuthClientInformationFull, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
3
|
+
/**
|
|
4
|
+
* OAuth client configuration for connecting to downstream MCP servers
|
|
5
|
+
*/
|
|
6
|
+
export interface OAuthClientConfig {
|
|
7
|
+
clientId?: string;
|
|
8
|
+
clientSecret?: string;
|
|
9
|
+
scopes?: string[];
|
|
10
|
+
redirectUrl: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* SDK-compatible OAuth client provider that replaces the custom implementation.
|
|
14
|
+
*
|
|
15
|
+
* This provider implements the OAuth 2.1 Authorization Code Grant flow using
|
|
16
|
+
* the SDK's OAuthClientProvider interface while maintaining compatibility with
|
|
17
|
+
* the existing session storage system.
|
|
18
|
+
*/
|
|
19
|
+
export declare class SDKOAuthClientProvider implements OAuthClientProvider {
|
|
20
|
+
private _clientMetadata;
|
|
21
|
+
private _clientInfo?;
|
|
22
|
+
private _tokens?;
|
|
23
|
+
private _codeVerifier?;
|
|
24
|
+
private _state?;
|
|
25
|
+
private sessionManager;
|
|
26
|
+
private serverName;
|
|
27
|
+
private config;
|
|
28
|
+
private _authorizationUrl?;
|
|
29
|
+
constructor(serverName: string, config: OAuthClientConfig, sessionStoragePath?: string);
|
|
30
|
+
get redirectUrl(): string;
|
|
31
|
+
get clientMetadata(): OAuthClientMetadata;
|
|
32
|
+
/**
|
|
33
|
+
* Returns current client registration information
|
|
34
|
+
*/
|
|
35
|
+
clientInformation(): OAuthClientInformationFull | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Saves client registration information from dynamic registration
|
|
38
|
+
*/
|
|
39
|
+
saveClientInformation(clientInfo: OAuthClientInformationFull): void;
|
|
40
|
+
/**
|
|
41
|
+
* Returns current OAuth tokens
|
|
42
|
+
*/
|
|
43
|
+
tokens(): OAuthTokens | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Saves OAuth tokens after successful authorization
|
|
46
|
+
*/
|
|
47
|
+
saveTokens(tokens: OAuthTokens): void;
|
|
48
|
+
/**
|
|
49
|
+
* Stores authorization URL instead of prompting user in console
|
|
50
|
+
*/
|
|
51
|
+
redirectToAuthorization(authorizationUrl: URL): void;
|
|
52
|
+
/**
|
|
53
|
+
* Gets the current authorization URL
|
|
54
|
+
*/
|
|
55
|
+
getAuthorizationUrl(): string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Clears the stored authorization URL
|
|
58
|
+
*/
|
|
59
|
+
clearAuthorizationUrl(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Saves PKCE code verifier for the authorization session
|
|
62
|
+
*/
|
|
63
|
+
saveCodeVerifier(codeVerifier: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the PKCE code verifier for token exchange
|
|
66
|
+
*/
|
|
67
|
+
codeVerifier(): string | Promise<string>;
|
|
68
|
+
/**
|
|
69
|
+
* Returns the OAuth state parameter for CSRF protection
|
|
70
|
+
*/
|
|
71
|
+
state(): string | Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Custom resource validation (optional)
|
|
74
|
+
*/
|
|
75
|
+
validateResourceURL(serverUrl: string | URL, resource?: string): Promise<URL | undefined>;
|
|
76
|
+
/**
|
|
77
|
+
* Load persisted OAuth data from unified client session storage
|
|
78
|
+
*/
|
|
79
|
+
private loadPersistedData;
|
|
80
|
+
/**
|
|
81
|
+
* Persist all OAuth data to unified client session storage
|
|
82
|
+
*/
|
|
83
|
+
private persistAllData;
|
|
84
|
+
/**
|
|
85
|
+
* Check if OAuth tokens are expired
|
|
86
|
+
*/
|
|
87
|
+
private isTokenExpired;
|
|
88
|
+
/**
|
|
89
|
+
* Clean up resources
|
|
90
|
+
*/
|
|
91
|
+
shutdown(): void;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=sdkOAuthClientProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdkOAuthClientProvider.d.ts","sourceRoot":"","sources":["../../src/auth/sdkOAuthClientProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,KAAK,EACV,mBAAmB,EACnB,0BAA0B,EAC1B,WAAW,EACZ,MAAM,0CAA0C,CAAC;AAMlD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAA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