From a64b0d557fc4f1c86531be546c1463b6b27f05f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E5=BA=86=E9=9B=B7?= Date: Fri, 14 Nov 2025 10:39:35 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E4=BF=AE=E5=A4=8DloadCodeAssist?= =?UTF-8?q?=E4=B8=AD=E7=A7=BB=E9=99=A4tokeninfo=E5=92=8Cuserinfo=E8=B0=83?= =?UTF-8?q?=E7=94=A8"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit baffd02b02d0805243b2ece7362cb509f10808c2. --- src/services/geminiAccountService.js | 50 ++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/src/services/geminiAccountService.js b/src/services/geminiAccountService.js index e50d1744..5cb2cff2 100644 --- a/src/services/geminiAccountService.js +++ b/src/services/geminiAccountService.js @@ -1110,10 +1110,54 @@ async function loadCodeAssist(client, projectId = null, proxyConfig = null) { const { token } = await client.getAccessToken() const proxyAgent = ProxyHelper.createProxyAgent(proxyConfig) + const tokenInfoConfig = { + url: 'https://oauth2.googleapis.com/tokeninfo', + method: 'POST', + headers: { + Authorization: `Bearer ${token}`, + 'Content-Type': 'application/x-www-form-urlencoded' + }, + data: new URLSearchParams({ access_token: token }).toString(), + timeout: 15000 + } + + if (proxyAgent) { + tokenInfoConfig.httpAgent = proxyAgent + tokenInfoConfig.httpsAgent = proxyAgent + tokenInfoConfig.proxy = false + } + + try { + await axios(tokenInfoConfig) + logger.info('📋 tokeninfo 接口验证成功') + } catch (error) { + logger.info('tokeninfo 接口获取失败', error) + } + + const userInfoConfig = { + url: 'https://www.googleapis.com/oauth2/v2/userinfo', + method: 'GET', + headers: { + Authorization: `Bearer ${token}`, + Accept: '*/*' + }, + timeout: 15000 + } + + if (proxyAgent) { + userInfoConfig.httpAgent = proxyAgent + userInfoConfig.httpsAgent = proxyAgent + userInfoConfig.proxy = false + } + + try { + await axios(userInfoConfig) + logger.info('📋 userinfo 接口获取成功') + } catch (error) { + logger.info('userinfo 接口获取失败', error) + } + // 创建ClientMetadata - // Note: 移除了 tokeninfo 和 userinfo 验证调用 - // 这些调用在原生 gemini-cli 的 CodeAssistServer.loadCodeAssist 中不存在 - // 且会导致使用特殊 token 时出现 401 错误 const clientMetadata = { ideType: 'IDE_UNSPECIFIED', platform: 'PLATFORM_UNSPECIFIED',