mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
fix(kiro): auto-resolve profileArn to prevent 403 on IDC login
AWS OIDC IDC/Builder-ID tokens omit profileArn, so CodeWhisperer calls return 403 "User is not authorized". Resolve it natively via the ListAvailableProfiles API instead of reading Kiro IDE profile.json. - providers.js: add fetchKiroProfileArn() and resolve on poll (new logins) - tokenRefresh.js: backfill profileArn on refresh so existing IDC connections self-heal without re-login Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -367,6 +367,17 @@ export async function refreshCodexToken(refreshToken, log) {
|
||||
* Specialized refresh for Kiro (AWS CodeWhisperer) tokens
|
||||
* Supports both AWS SSO OIDC (Builder ID/IDC) and Social Auth (Google/GitHub)
|
||||
*/
|
||||
// Backfill missing Kiro profileArn on refresh so existing IDC connections self-heal
|
||||
async function resolveKiroProfileArnPatch(providerSpecificData, accessToken, refreshedArn) {
|
||||
if (providerSpecificData?.profileArn) return {};
|
||||
let profileArn = refreshedArn?.trim?.() || null;
|
||||
if (!profileArn) {
|
||||
const { fetchKiroProfileArn } = await import("../../src/lib/oauth/providers.js");
|
||||
profileArn = await fetchKiroProfileArn(accessToken);
|
||||
}
|
||||
return profileArn ? { providerSpecificData: { profileArn } } : {};
|
||||
}
|
||||
|
||||
export async function refreshKiroToken(refreshToken, providerSpecificData, log, proxyOptions = null) {
|
||||
if (!refreshToken) return null;
|
||||
return dedupRefresh("kiro", refreshToken, async () => {
|
||||
@@ -417,6 +428,7 @@ export async function refreshKiroToken(refreshToken, providerSpecificData, log,
|
||||
accessToken: tokens.accessToken,
|
||||
refreshToken: tokens.refreshToken || refreshToken,
|
||||
expiresIn: tokens.expiresIn,
|
||||
...(await resolveKiroProfileArnPatch(providerSpecificData, tokens.accessToken)),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -453,6 +465,7 @@ export async function refreshKiroToken(refreshToken, providerSpecificData, log,
|
||||
accessToken: tokens.accessToken,
|
||||
refreshToken: tokens.refreshToken || refreshToken,
|
||||
expiresIn: tokens.expiresIn,
|
||||
...(await resolveKiroProfileArnPatch(providerSpecificData, tokens.accessToken, tokens.profileArn)),
|
||||
};
|
||||
}, log);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user