MCPcopy Create free account
hub / github.com/anus-dev/ANUS / loadCachedCredentials

Function loadCachedCredentials

packages/core/src/code_assist/oauth2.ts:354–381  ·  view source on GitHub ↗
(client: OAuth2Client)

Source from the content-addressed store, hash-verified

352}
353
354async function loadCachedCredentials(client: OAuth2Client): Promise<boolean> {
355 const pathsToTry = [
356 getCachedCredentialPath(),
357 process.env['GOOGLE_APPLICATION_CREDENTIALS'],
358 ].filter((p): p is string => !!p);
359
360 for (const keyFile of pathsToTry) {
361 try {
362 const creds = await fs.readFile(keyFile, 'utf-8');
363 client.setCredentials(JSON.parse(creds));
364
365 // This will verify locally that the credentials look good.
366 const { token } = await client.getAccessToken();
367 if (!token) {
368 continue;
369 }
370
371 // This will check with the server to see if it hasn't been revoked.
372 await client.getTokenInfo(token);
373
374 return true;
375 } catch (_) {
376 // Ignore and try next path.
377 }
378 }
379
380 return false;
381}
382
383async function cacheCredentials(credentials: Credentials) {
384 const filePath = getCachedCredentialPath();

Callers 1

initOauthClientFunction · 0.85

Calls 2

getCachedCredentialPathFunction · 0.85
readFileMethod · 0.80

Tested by

no test coverage detected