Fix OAuth token fetch failures from ad-hoc response persistence (#399)

This commit is contained in:
Gregory Schier
2026-02-19 14:04:34 -08:00
committed by GitHub
parent 7b73401dcf
commit 5a184c1b83
3 changed files with 93 additions and 76 deletions

View File

@@ -61,6 +61,10 @@ export async function fetchAccessToken(
console.log('[oauth2] Got access token response', resp.status);
if (resp.error) {
throw new Error(`Failed to fetch access token: ${resp.error}`);
}
const body = resp.bodyPath ? readFileSync(resp.bodyPath, 'utf8') : '';
if (resp.status < 200 || resp.status >= 300) {

View File

@@ -71,6 +71,10 @@ export async function getOrRefreshAccessToken(
httpRequest.authenticationType = 'none'; // Don't inherit workspace auth
const resp = await ctx.httpRequest.send({ httpRequest });
if (resp.error) {
throw new Error(`Failed to refresh access token: ${resp.error}`);
}
if (resp.status >= 400 && resp.status < 500) {
// Client errors (4xx) indicate the refresh token is invalid, expired, or revoked
// Delete the token and return null to trigger a fresh authorization flow