@1mcp/agent 0.12.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 +22 -37
- 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/auth/{sessionManager.d.ts → serverSessionManager.d.ts} +24 -36
- package/build/auth/serverSessionManager.d.ts.map +1 -0
- package/build/auth/{sessionManager.js → serverSessionManager.js} +77 -24
- 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 +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 +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/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 +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 +3 -13
- package/build/transport/http/routes/oauthRoutes.d.ts.map +1 -1
- package/build/transport/http/routes/oauthRoutes.js +459 -117
- package/build/transport/http/routes/oauthRoutes.js.map +1 -1
- package/build/transport/http/routes/sseRoutes.d.ts +2 -2
- package/build/transport/http/routes/sseRoutes.d.ts.map +1 -1
- package/build/transport/http/routes/sseRoutes.js +9 -7
- package/build/transport/http/routes/sseRoutes.js.map +1 -1
- package/build/transport/http/routes/streamableHttpRoutes.d.ts +2 -2
- package/build/transport/http/routes/streamableHttpRoutes.d.ts.map +1 -1
- package/build/transport/http/routes/streamableHttpRoutes.js +16 -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 +14 -14
- 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.map +0 -1
- 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,199 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import logger from '../logger/logger.js';
|
|
3
|
+
import { ClientSessionManager } from './clientSessionManager.js';
|
|
4
|
+
import { AUTH_CONFIG } from '../constants.js';
|
|
5
|
+
/**
|
|
6
|
+
* SDK-compatible OAuth client provider that replaces the custom implementation.
|
|
7
|
+
*
|
|
8
|
+
* This provider implements the OAuth 2.1 Authorization Code Grant flow using
|
|
9
|
+
* the SDK's OAuthClientProvider interface while maintaining compatibility with
|
|
10
|
+
* the existing session storage system.
|
|
11
|
+
*/
|
|
12
|
+
export class SDKOAuthClientProvider {
|
|
13
|
+
_clientMetadata;
|
|
14
|
+
_clientInfo;
|
|
15
|
+
_tokens;
|
|
16
|
+
_codeVerifier;
|
|
17
|
+
_state;
|
|
18
|
+
sessionManager;
|
|
19
|
+
serverName;
|
|
20
|
+
config;
|
|
21
|
+
_authorizationUrl;
|
|
22
|
+
constructor(serverName, config, sessionStoragePath) {
|
|
23
|
+
this.serverName = serverName;
|
|
24
|
+
this.config = config;
|
|
25
|
+
this.sessionManager = new ClientSessionManager(sessionStoragePath);
|
|
26
|
+
// Set up client metadata for registration with better defaults
|
|
27
|
+
this._clientMetadata = {
|
|
28
|
+
client_name: `1MCP Agent - ${serverName}`,
|
|
29
|
+
redirect_uris: [config.redirectUrl || ''],
|
|
30
|
+
grant_types: ['authorization_code', 'refresh_token'],
|
|
31
|
+
response_types: ['code'],
|
|
32
|
+
token_endpoint_auth_method: config.clientSecret ? 'client_secret_post' : 'none',
|
|
33
|
+
scope: config.scopes?.join(' ') || AUTH_CONFIG.CLIENT.OAUTH.DEFAULT_SCOPES.join(' '),
|
|
34
|
+
};
|
|
35
|
+
logger.debug(`OAuth client metadata: ${JSON.stringify(this._clientMetadata)}`);
|
|
36
|
+
// Load existing client info and tokens if available
|
|
37
|
+
this.loadPersistedData();
|
|
38
|
+
}
|
|
39
|
+
get redirectUrl() {
|
|
40
|
+
return this.config.redirectUrl || '';
|
|
41
|
+
}
|
|
42
|
+
get clientMetadata() {
|
|
43
|
+
return this._clientMetadata;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns current client registration information
|
|
47
|
+
*/
|
|
48
|
+
clientInformation() {
|
|
49
|
+
return this._clientInfo;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Saves client registration information from dynamic registration
|
|
53
|
+
*/
|
|
54
|
+
saveClientInformation(clientInfo) {
|
|
55
|
+
this._clientInfo = clientInfo;
|
|
56
|
+
this.persistAllData();
|
|
57
|
+
logger.info(`OAuth client registered for ${this.serverName}: ${clientInfo.client_id}`);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Returns current OAuth tokens
|
|
61
|
+
*/
|
|
62
|
+
tokens() {
|
|
63
|
+
return this._tokens;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Saves OAuth tokens after successful authorization
|
|
67
|
+
*/
|
|
68
|
+
saveTokens(tokens) {
|
|
69
|
+
this._tokens = tokens;
|
|
70
|
+
this.persistAllData();
|
|
71
|
+
logger.info(`OAuth tokens saved for ${this.serverName}`);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Stores authorization URL instead of prompting user in console
|
|
75
|
+
*/
|
|
76
|
+
redirectToAuthorization(authorizationUrl) {
|
|
77
|
+
this._authorizationUrl = authorizationUrl.toString();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Gets the current authorization URL
|
|
81
|
+
*/
|
|
82
|
+
getAuthorizationUrl() {
|
|
83
|
+
return this._authorizationUrl;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Clears the stored authorization URL
|
|
87
|
+
*/
|
|
88
|
+
clearAuthorizationUrl() {
|
|
89
|
+
this._authorizationUrl = undefined;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Saves PKCE code verifier for the authorization session
|
|
93
|
+
*/
|
|
94
|
+
saveCodeVerifier(codeVerifier) {
|
|
95
|
+
this._codeVerifier = codeVerifier;
|
|
96
|
+
this.persistAllData();
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Returns the PKCE code verifier for token exchange
|
|
100
|
+
*/
|
|
101
|
+
codeVerifier() {
|
|
102
|
+
return this._codeVerifier || '';
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Returns the OAuth state parameter for CSRF protection
|
|
106
|
+
*/
|
|
107
|
+
state() {
|
|
108
|
+
if (!this._state) {
|
|
109
|
+
this._state = randomUUID();
|
|
110
|
+
this.persistAllData();
|
|
111
|
+
}
|
|
112
|
+
return this._state;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Custom resource validation (optional)
|
|
116
|
+
*/
|
|
117
|
+
async validateResourceURL(serverUrl, resource) {
|
|
118
|
+
const url = typeof serverUrl === 'string' ? new URL(serverUrl) : serverUrl;
|
|
119
|
+
// Basic validation - can be extended for specific requirements
|
|
120
|
+
if (resource && !resource.startsWith(url.origin)) {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
return url;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Load persisted OAuth data from unified client session storage
|
|
127
|
+
*/
|
|
128
|
+
loadPersistedData() {
|
|
129
|
+
const clientSession = this.sessionManager.getClientSession(this.serverName);
|
|
130
|
+
if (clientSession) {
|
|
131
|
+
// Load client info
|
|
132
|
+
if (clientSession.clientInfo) {
|
|
133
|
+
this._clientInfo = JSON.parse(clientSession.clientInfo);
|
|
134
|
+
}
|
|
135
|
+
// Load tokens
|
|
136
|
+
if (clientSession.tokens) {
|
|
137
|
+
this._tokens = JSON.parse(clientSession.tokens);
|
|
138
|
+
// Check if tokens are expired
|
|
139
|
+
if (this._tokens && this.isTokenExpired(this._tokens)) {
|
|
140
|
+
logger.warn(`OAuth tokens expired for ${this.serverName}, clearing`);
|
|
141
|
+
this._tokens = undefined;
|
|
142
|
+
this.persistAllData();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Load code verifier
|
|
146
|
+
if (clientSession.codeVerifier) {
|
|
147
|
+
this._codeVerifier = clientSession.codeVerifier;
|
|
148
|
+
}
|
|
149
|
+
// Load state
|
|
150
|
+
if (clientSession.state) {
|
|
151
|
+
this._state = clientSession.state;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Persist all OAuth data to unified client session storage
|
|
157
|
+
*/
|
|
158
|
+
persistAllData() {
|
|
159
|
+
// Calculate the longest TTL based on the data we have
|
|
160
|
+
let maxTtl = AUTH_CONFIG.CLIENT.OAUTH.TTL_MS; // Default to 30 days
|
|
161
|
+
// If we have tokens, use their expiry time
|
|
162
|
+
if (this._tokens && this._tokens.expires_in) {
|
|
163
|
+
const tokenTtl = this._tokens.expires_in * 1000;
|
|
164
|
+
maxTtl = Math.max(maxTtl, tokenTtl);
|
|
165
|
+
}
|
|
166
|
+
// Code verifier and state have shorter TTL, but we keep them for completeness
|
|
167
|
+
const clientSessionData = {
|
|
168
|
+
serverName: this.serverName,
|
|
169
|
+
clientInfo: this._clientInfo ? JSON.stringify(this._clientInfo) : undefined,
|
|
170
|
+
tokens: this._tokens ? JSON.stringify(this._tokens) : undefined,
|
|
171
|
+
codeVerifier: this._codeVerifier,
|
|
172
|
+
state: this._state,
|
|
173
|
+
expires: Date.now() + maxTtl,
|
|
174
|
+
createdAt: Date.now(),
|
|
175
|
+
};
|
|
176
|
+
this.sessionManager.createClientSession(this.serverName, clientSessionData);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Check if OAuth tokens are expired
|
|
180
|
+
*/
|
|
181
|
+
isTokenExpired(tokens) {
|
|
182
|
+
if (!tokens.expires_in) {
|
|
183
|
+
return false; // No expiration info, assume valid
|
|
184
|
+
}
|
|
185
|
+
// This is a simple check - in practice, you might want to store the issued_at time
|
|
186
|
+
// For now, we'll rely on the session storage TTL for expiration
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Clean up resources
|
|
191
|
+
*/
|
|
192
|
+
shutdown() {
|
|
193
|
+
// Clean up temporary session data by clearing verifier and state
|
|
194
|
+
this._codeVerifier = undefined;
|
|
195
|
+
this._state = undefined;
|
|
196
|
+
this.persistAllData();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=sdkOAuthClientProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdkOAuthClientProvider.js","sourceRoot":"","sources":["../../src/auth/sdkOAuthClientProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAa9C;;;;;;GAMG;AACH,MAAM,OAAO,sBAAsB;IACzB,eAAe,CAAsB;IACrC,WAAW,CAA8B;IACzC,OAAO,CAAe;IACtB,aAAa,CAAU;IACvB,MAAM,CAAU;IAChB,cAAc,CAAuB;IACrC,UAAU,CAAS;IACnB,MAAM,CAAoB;IAC1B,iBAAiB,CAAU;IAEnC,YAAY,UAAkB,EAAE,MAAyB,EAAE,kBAA2B;QACpF,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,cAAc,GAAG,IAAI,oBAAoB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OAuthServerProvider, AuthorizationParams } from '@modelcontextprotocol/sdk/server/auth/provider.js';
|
|
3
|
+
import type { OAuthRegisteredClientsStore } from '@modelcontextprotocol/sdk/server/auth/clients.js';
|
|
4
|
+
import type { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js';
|
|
5
|
+
import type { OAuthClientInformationFull, OAuthTokens, OAuthTokenRevocationRequest } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
6
|
+
/**
|
|
7
|
+
* Implementation of SDK's OAuthServerProvider interface using existing SessionManager.
|
|
8
|
+
*
|
|
9
|
+
* This provider implements OAuth 2.1 server functionality using the MCP SDK's interfaces
|
|
10
|
+
* while maintaining compatibility with the existing session storage system.
|
|
11
|
+
*/
|
|
12
|
+
export declare class SDKOAuthServerProvider implements OAuthServerProvider {
|
|
13
|
+
private sessionManager;
|
|
14
|
+
private configManager;
|
|
15
|
+
private _clientsStore;
|
|
16
|
+
constructor(sessionStoragePath?: string);
|
|
17
|
+
get clientsStore(): OAuthRegisteredClientsStore;
|
|
18
|
+
/**
|
|
19
|
+
* Handles the authorization request with scope validation and user consent
|
|
20
|
+
*/
|
|
21
|
+
authorize(client: OAuthClientInformationFull, params: AuthorizationParams, res: Response): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Determines if user consent is required for the authorization
|
|
24
|
+
*/
|
|
25
|
+
private requiresUserConsent;
|
|
26
|
+
/**
|
|
27
|
+
* Renders the consent page for scope selection
|
|
28
|
+
*/
|
|
29
|
+
private renderConsentPage;
|
|
30
|
+
/**
|
|
31
|
+
* Approves the authorization and redirects back to client
|
|
32
|
+
*/
|
|
33
|
+
approveAuthorization(client: OAuthClientInformationFull, params: AuthorizationParams, grantedScopes: string[], res: Response): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Generates the HTML for the consent page
|
|
36
|
+
*/
|
|
37
|
+
private generateConsentPageHtml;
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves the PKCE challenge for an authorization code
|
|
40
|
+
*/
|
|
41
|
+
challengeForAuthorizationCode(client: OAuthClientInformationFull, authorizationCode: string): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Exchanges authorization code for access token
|
|
44
|
+
*/
|
|
45
|
+
exchangeAuthorizationCode(client: OAuthClientInformationFull, authorizationCode: string, _codeVerifier?: string, redirectUri?: string, resource?: URL): Promise<OAuthTokens>;
|
|
46
|
+
/**
|
|
47
|
+
* Exchanges refresh token for new access token (not implemented)
|
|
48
|
+
*/
|
|
49
|
+
exchangeRefreshToken(_client: OAuthClientInformationFull, _refreshToken: string, _scopes?: string[], _resource?: URL): Promise<OAuthTokens>;
|
|
50
|
+
/**
|
|
51
|
+
* Verifies access token and returns auth info with granted scopes
|
|
52
|
+
*/
|
|
53
|
+
verifyAccessToken(token: string): Promise<AuthInfo>;
|
|
54
|
+
/**
|
|
55
|
+
* Revokes a token
|
|
56
|
+
*/
|
|
57
|
+
revokeToken(client: OAuthClientInformationFull, request: OAuthTokenRevocationRequest): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Graceful shutdown
|
|
60
|
+
*/
|
|
61
|
+
shutdown(): void;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=sdkOAuthServerProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdkOAuthServerProvider.d.ts","sourceRoot":"","sources":["../../src/auth/sdkOAuthServerProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,mDAAmD,CAAC;AAClH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kDAAkD,CAAC;AACpG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gDAAgD,CAAC;AAC/E,OAAO,KAAK,EACV,0BAA0B,EAC1B,WAAW,EACX,2BAA2B,EAC5B,MAAM,0CAA0C,CAAC;AA2FlD;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