summaryrefslogtreecommitdiff
path: root/packages/core/src/code_assist/oauth2.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/core/src/code_assist/oauth2.ts')
-rw-r--r--packages/core/src/code_assist/oauth2.ts16
1 files changed, 13 insertions, 3 deletions
diff --git a/packages/core/src/code_assist/oauth2.ts b/packages/core/src/code_assist/oauth2.ts
index 6527f957..3fbbd896 100644
--- a/packages/core/src/code_assist/oauth2.ts
+++ b/packages/core/src/code_assist/oauth2.ts
@@ -160,10 +160,20 @@ export function getAvailablePort(): Promise<number> {
async function loadCachedCredentials(client: OAuth2Client): Promise<boolean> {
try {
- const creds = await fs.readFile(getCachedCredentialPath(), 'utf-8');
+ const keyFile =
+ process.env.GOOGLE_APPLICATION_CREDENTIALS || getCachedCredentialPath();
+
+ const creds = await fs.readFile(keyFile, 'utf-8');
client.setCredentials(JSON.parse(creds));
- // This will either return the existing token or refresh it.
- await client.getAccessToken();
+
+ // This will verify locally that the credentials look good.
+ const { token } = await client.getAccessToken();
+ if (!token) {
+ return false;
+ }
+
+ // This will check with the server to see if it hasn't been revoked.
+ await client.getTokenInfo(token);
return true;
} catch (_) {