|
7 | 7 | OAuthTokensSchema,
|
8 | 8 | } from '@modelcontextprotocol/sdk/shared/auth.js'
|
9 | 9 | import type { OAuthProviderOptions, StaticOAuthClientMetadata } from './types'
|
10 |
| -import { readJsonFile, writeJsonFile, readTextFile, writeTextFile } from './mcp-auth-config' |
| 10 | +import { readJsonFile, writeJsonFile, readTextFile, writeTextFile, deleteConfigFile } from './mcp-auth-config' |
11 | 11 | import { StaticOAuthClientInformationFull } from './types'
|
12 | 12 | import { getServerUrlHash, log, debugLog, DEBUG, MCP_REMOTE_VERSION } from './utils'
|
13 | 13 |
|
@@ -193,4 +193,41 @@ export class NodeOAuthClientProvider implements OAuthClientProvider {
|
193 | 193 | if (DEBUG) debugLog('Code verifier found:', !!verifier)
|
194 | 194 | return verifier
|
195 | 195 | }
|
| 196 | + |
| 197 | + /** |
| 198 | + * Invalidates the specified credentials |
| 199 | + * @param scope The scope of credentials to invalidate |
| 200 | + */ |
| 201 | + async invalidateCredentials(scope: 'all' | 'client' | 'tokens' | 'verifier'): Promise<void> { |
| 202 | + if (DEBUG) debugLog(`Invalidating credentials: ${scope}`) |
| 203 | + |
| 204 | + switch (scope) { |
| 205 | + case 'all': |
| 206 | + await Promise.all([ |
| 207 | + deleteConfigFile(this.serverUrlHash, 'client_info.json'), |
| 208 | + deleteConfigFile(this.serverUrlHash, 'tokens.json'), |
| 209 | + deleteConfigFile(this.serverUrlHash, 'code_verifier.txt'), |
| 210 | + ]) |
| 211 | + if (DEBUG) debugLog('All credentials invalidated') |
| 212 | + break |
| 213 | + |
| 214 | + case 'client': |
| 215 | + await deleteConfigFile(this.serverUrlHash, 'client_info.json') |
| 216 | + if (DEBUG) debugLog('Client information invalidated') |
| 217 | + break |
| 218 | + |
| 219 | + case 'tokens': |
| 220 | + await deleteConfigFile(this.serverUrlHash, 'tokens.json') |
| 221 | + if (DEBUG) debugLog('OAuth tokens invalidated') |
| 222 | + break |
| 223 | + |
| 224 | + case 'verifier': |
| 225 | + await deleteConfigFile(this.serverUrlHash, 'code_verifier.txt') |
| 226 | + if (DEBUG) debugLog('Code verifier invalidated') |
| 227 | + break |
| 228 | + |
| 229 | + default: |
| 230 | + throw new Error(`Unknown credential scope: ${scope}`) |
| 231 | + } |
| 232 | + } |
196 | 233 | }
|
0 commit comments