From 76411cad0dc5e28d41dbb2a5f91ee34f29aff174 Mon Sep 17 00:00:00 2001 From: LaelLuo Date: Tue, 12 Aug 2025 14:33:43 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20fix(kiro):=20=E4=BC=98=E5=8C=96KIRO=5FO?= =?UTF-8?q?AUTH=5FCREDS=5FFILE=5FPATH=E9=85=8D=E7=BD=AE=E7=9A=84=E5=87=AD?= =?UTF-8?q?=E6=8D=AE=E5=8A=A0=E8=BD=BD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 当配置KIRO_OAUTH_CREDS_FILE_PATH时跳过~/.aws/sso/cache/目录扫描 - 修复token刷新时保存路径问题,使用用户指定路径而不是默认路径 - 改进错误处理和调试日志 --- src/claude/claude-kiro.js | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/claude/claude-kiro.js b/src/claude/claude-kiro.js index 885e34b..9c5f32d 100644 --- a/src/claude/claude-kiro.js +++ b/src/claude/claude-kiro.js @@ -347,20 +347,28 @@ async initializeAuth(forceRefresh = false) { } } - // Priority 3: Load from default directory if no specific file path and no token file credentials - const dirPath = this.credPath; - console.debug(`[Kiro Auth] Attempting to load credentials from directory: ${dirPath}`); - const files = await fs.readdir(dirPath); - for (const file of files) { - if (file.endsWith('.json') && file !== KIRO_AUTH_TOKEN_FILE) { - const filePath = path.join(dirPath, file); - const credentials = await loadCredentialsFromFile(filePath); - if (credentials) { - credentials.expiresAt = mergedCredentials.expiresAt; - Object.assign(mergedCredentials, credentials); - console.debug(`[Kiro Auth] Loaded credentials from ${file}`); + // Priority 3: Load from default directory only if no specific file path is configured + if (!this.credsFilePath) { + const dirPath = this.credPath; + console.debug(`[Kiro Auth] Attempting to load credentials from directory: ${dirPath}`); + try { + const files = await fs.readdir(dirPath); + for (const file of files) { + if (file.endsWith('.json') && file !== KIRO_AUTH_TOKEN_FILE) { + const filePath = path.join(dirPath, file); + const credentials = await loadCredentialsFromFile(filePath); + if (credentials) { + credentials.expiresAt = mergedCredentials.expiresAt; + Object.assign(mergedCredentials, credentials); + console.debug(`[Kiro Auth] Loaded credentials from ${file}`); + } + } } + } catch (error) { + console.debug(`[Kiro Auth] Could not read credential directory ${dirPath}: ${error.message}`); } + } else { + console.debug(`[Kiro Auth] Skipping directory scan because specific file path is configured: ${this.credsFilePath}`); } // console.log('[Kiro Auth] Merged credentials:', mergedCredentials); @@ -385,7 +393,7 @@ async initializeAuth(forceRefresh = false) { this.baseUrl = KIRO_CONSTANTS.BASE_URL.replace("{{region}}", this.region); this.amazonQUrl = KIRO_CONSTANTS.AMAZON_Q_URL.replace("{{region}}", this.region); } catch (error) { - console.warn(`[Kiro Auth] Could not read credential directory ${this.credPath}: ${error.message}`); + console.warn(`[Kiro Auth] Error during credential loading: ${error.message}`); } // Refresh token if forced or if access token is missing but refresh token is available @@ -417,8 +425,8 @@ async initializeAuth(forceRefresh = false) { this.expiresAt = expiresAt; console.info('[Kiro Auth] Access token refreshed successfully'); - // Update the token file - const tokenFilePath = path.join(this.credPath, KIRO_AUTH_TOKEN_FILE); + // Update the token file - use specified path if configured, otherwise use default + const tokenFilePath = this.credsFilePath || path.join(this.credPath, KIRO_AUTH_TOKEN_FILE); const updatedTokenData = { accessToken: this.accessToken, refreshToken: this.refreshToken,