mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-11 22:51:26 +00:00
refactor(McpOAuthClientProvider): add TOKEN_EXPIRY_BUFFER
This commit is contained in:
parent
5aeed4f3c0
commit
1f8209ac2a
3 changed files with 4 additions and 5 deletions
|
|
@ -36,6 +36,7 @@ import { GlobalFileNames } from "../../shared/globalFileNames"
|
|||
import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js"
|
||||
|
||||
import { fileExistsAtPath } from "../../utils/fs"
|
||||
import { TOKEN_EXPIRY_BUFFER_MS } from "./constants"
|
||||
import { SecretStorageService } from "./SecretStorageService"
|
||||
import { McpOAuthClientProvider } from "./McpOAuthClientProvider"
|
||||
import { arePathsEqual, getWorkspacePath } from "../../utils/path"
|
||||
|
|
@ -1053,8 +1054,6 @@ export class McpHub {
|
|||
return
|
||||
}
|
||||
|
||||
const TOKEN_EXPIRY_BUFFER_MS = 5 * 60 * 1000
|
||||
|
||||
// Check if another window already saved valid tokens
|
||||
const existing = await this.secretStorage.getOAuthData(serverUrl)
|
||||
if (existing && Date.now() < existing.expires_at - TOKEN_EXPIRY_BUFFER_MS) {
|
||||
|
|
@ -1163,8 +1162,6 @@ export class McpHub {
|
|||
this._oauthWatchers.delete(watcherKey)
|
||||
}
|
||||
|
||||
const TOKEN_EXPIRY_BUFFER_MS = 5 * 60 * 1000
|
||||
|
||||
// Called when SecretStorage fires onDidChange for this server's key.
|
||||
// Runs in all VS Code windows the instant tokens are saved — no polling delay.
|
||||
const onTokensChanged = async () => {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import type {
|
|||
OAuthTokens,
|
||||
} from "@modelcontextprotocol/sdk/shared/auth.js"
|
||||
|
||||
import { TOKEN_EXPIRY_BUFFER_MS } from "./constants"
|
||||
import { SecretStorageService } from "./SecretStorageService"
|
||||
import { startCallbackServer, stopCallbackServer } from "./utils/callbackServer"
|
||||
import { fetchOAuthAuthServerMetadata } from "./utils/oauth"
|
||||
|
|
@ -265,7 +266,7 @@ export class McpOAuthClientProvider implements OAuthClientProvider {
|
|||
if (!data) return undefined
|
||||
|
||||
// If the access token is still valid (with 5m buffer), return it.
|
||||
if (Date.now() < data.expires_at - 5 * 60 * 1000) {
|
||||
if (Date.now() < data.expires_at - TOKEN_EXPIRY_BUFFER_MS) {
|
||||
return data.tokens
|
||||
}
|
||||
|
||||
|
|
|
|||
1
src/services/mcp/constants.ts
Normal file
1
src/services/mcp/constants.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export const TOKEN_EXPIRY_BUFFER_MS = 5 * 60 * 1000 // 5 minutes
|
||||
Loading…
Add table
Reference in a new issue