diff options
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) { |
