Fix Kiro token refresh logic
This commit is contained in:
parent
eff52f75ae
commit
6b22b1f490
2 changed files with 14 additions and 24 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import { BaseExecutor } from "./base.js";
|
import { BaseExecutor } from "./base.js";
|
||||||
import { PROVIDERS } from "../config/constants.js";
|
import { PROVIDERS } from "../config/constants.js";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
|
import { refreshKiroToken } from "../services/tokenRefresh.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* KiroExecutor - Executor for Kiro AI (AWS CodeWhisperer)
|
* KiroExecutor - Executor for Kiro AI (AWS CodeWhisperer)
|
||||||
|
|
@ -319,31 +320,13 @@ export class KiroExecutor extends BaseExecutor {
|
||||||
if (!credentials.refreshToken) return null;
|
if (!credentials.refreshToken) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(this.config.tokenUrl, {
|
// Use centralized refreshKiroToken function (handles both AWS SSO OIDC and Social Auth)
|
||||||
method: "POST",
|
const result = await refreshKiroToken(
|
||||||
headers: {
|
credentials.refreshToken,
|
||||||
"Content-Type": "application/json",
|
credentials.providerSpecificData,
|
||||||
"User-Agent": "kiro-cli/1.0.0"
|
log
|
||||||
},
|
);
|
||||||
body: JSON.stringify({
|
|
||||||
refreshToken: credentials.refreshToken
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
log?.error?.("TOKEN", `Kiro refresh failed: ${response.status}`);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
|
|
||||||
const result = {
|
|
||||||
accessToken: data.accessToken,
|
|
||||||
refreshToken: data.refreshToken || credentials.refreshToken,
|
|
||||||
expiresIn: data.expiresIn || 3600
|
|
||||||
};
|
|
||||||
|
|
||||||
log?.info?.("TOKEN", "Kiro token refreshed");
|
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log?.error?.("TOKEN", `Kiro refresh error: ${error.message}`);
|
log?.error?.("TOKEN", `Kiro refresh error: ${error.message}`);
|
||||||
|
|
|
||||||
|
|
@ -228,6 +228,13 @@ export async function appendRequestLog({ model, provider, connectionId, tokens,
|
||||||
const line = `${timestamp} | ${m} | ${p} | ${account} | ${sent} | ${received} | ${status}\n`;
|
const line = `${timestamp} | ${m} | ${p} | ${account} | ${sent} | ${received} | ${status}\n`;
|
||||||
|
|
||||||
fs.appendFileSync(LOG_FILE, line);
|
fs.appendFileSync(LOG_FILE, line);
|
||||||
|
|
||||||
|
// Trim to keep only last 200 lines
|
||||||
|
const content = fs.readFileSync(LOG_FILE, "utf-8");
|
||||||
|
const lines = content.trim().split("\n");
|
||||||
|
if (lines.length > 200) {
|
||||||
|
fs.writeFileSync(LOG_FILE, lines.slice(-200).join("\n") + "\n");
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to append to log.txt:", error.message);
|
console.error("Failed to append to log.txt:", error.message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue