diff options
| author | Gaurav <[email protected]> | 2025-08-18 14:11:19 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-18 21:11:19 +0000 |
| commit | 5fe4e02310bdeae9ede4e6fe58dc77549b94d7cb (patch) | |
| tree | 5bd601eeb804bf2680ce73b2036eb641c64f67bd /packages/core/src/code_assist/oauth2.ts | |
| parent | 3960ccf78197c140ee483fccd654680894cdea47 (diff) | |
fix: GCA creds loading order (#6498)
Diffstat (limited to 'packages/core/src/code_assist/oauth2.ts')
| -rw-r--r-- | packages/core/src/code_assist/oauth2.ts | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/packages/core/src/code_assist/oauth2.ts b/packages/core/src/code_assist/oauth2.ts index a4dcf8a7..f479dd1b 100644 --- a/packages/core/src/code_assist/oauth2.ts +++ b/packages/core/src/code_assist/oauth2.ts @@ -351,27 +351,32 @@ export function getAvailablePort(): Promise<number> { } async function loadCachedCredentials(client: OAuth2Client): Promise<boolean> { - try { - const keyFile = - process.env['GOOGLE_APPLICATION_CREDENTIALS'] || - getCachedCredentialPath(); + const pathsToTry = [ + getCachedCredentialPath(), + process.env['GOOGLE_APPLICATION_CREDENTIALS'], + ].filter((p): p is string => !!p); - const creds = await fs.readFile(keyFile, 'utf-8'); - client.setCredentials(JSON.parse(creds)); + for (const keyFile of pathsToTry) { + try { + const creds = await fs.readFile(keyFile, 'utf-8'); + client.setCredentials(JSON.parse(creds)); - // This will verify locally that the credentials look good. - const { token } = await client.getAccessToken(); - if (!token) { - return false; - } + // This will verify locally that the credentials look good. + const { token } = await client.getAccessToken(); + if (!token) { + continue; + } - // This will check with the server to see if it hasn't been revoked. - await client.getTokenInfo(token); + // This will check with the server to see if it hasn't been revoked. + await client.getTokenInfo(token); - return true; - } catch (_) { - return false; + return true; + } catch (_) { + // Ignore and try next path. + } } + + return false; } async function cacheCredentials(credentials: Credentials) { |
