diff options
| author | Tommaso Sciortino <[email protected]> | 2025-06-18 09:49:13 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-18 09:49:13 -0700 |
| commit | 3453b977b8d200ebb5195cc2db38d89dbc2a7323 (patch) | |
| tree | 6607d774db9d7aed03f30e57e35d2d57fc597596 /packages/core/src/code_assist/codeAssist.ts | |
| parent | 5b2cea8eda60e9cc07a82a0bb69d5f00a13bd96b (diff) | |
Support logging in with Application Default Credentials (#1157)
Co-authored-by: N. Taylor Mullen <[email protected]>
Diffstat (limited to 'packages/core/src/code_assist/codeAssist.ts')
| -rw-r--r-- | packages/core/src/code_assist/codeAssist.ts | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/packages/core/src/code_assist/codeAssist.ts b/packages/core/src/code_assist/codeAssist.ts index 5df1502b..92b53104 100644 --- a/packages/core/src/code_assist/codeAssist.ts +++ b/packages/core/src/code_assist/codeAssist.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { GoogleAuth, AuthClient } from 'google-auth-library'; import { ContentGenerator } from '../core/contentGenerator.js'; import { getOauthClient } from './oauth2.js'; import { setupUser } from './setup.js'; @@ -12,10 +13,17 @@ import { CodeAssistServer, HttpOptions } from './server.js'; export async function createCodeAssistContentGenerator( httpOptions: HttpOptions, ): Promise<ContentGenerator> { - const oauth2Client = await getOauthClient(); - const projectId = await setupUser( - oauth2Client, - process.env.GOOGLE_CLOUD_PROJECT, - ); - return new CodeAssistServer(oauth2Client, projectId, httpOptions); + const authClient = await getAuthClient(); + const projectId = await setupUser(authClient); + return new CodeAssistServer(authClient, projectId, httpOptions); +} + +async function getAuthClient(): Promise<AuthClient> { + try { + // Try for Application Default Credentials. + return await new GoogleAuth().getClient(); + } catch (_) { + // No Application Default Credentials so try Oauth. + return await getOauthClient(); + } } |
