summaryrefslogtreecommitdiff
path: root/packages/core/src/code_assist/oauth2.ts
diff options
context:
space:
mode:
authorMarat Boshernitsan <[email protected]>2025-07-18 17:22:50 -0700
committerGitHub <[email protected]>2025-07-19 00:22:50 +0000
commit5b7b6fe608257381f522df5432d76e9fdf2bc144 (patch)
treeaa9924ed4398cc453d5e0c45b22512977bdb6dc3 /packages/core/src/code_assist/oauth2.ts
parent003609239fe81c8a2920ed0c63b7f5142bb4f7e5 (diff)
Automatically detect non-interactive environments and fall back to a manual, code-based authentication flow (#4475)
Diffstat (limited to 'packages/core/src/code_assist/oauth2.ts')
-rw-r--r--packages/core/src/code_assist/oauth2.ts11
1 files changed, 7 insertions, 4 deletions
diff --git a/packages/core/src/code_assist/oauth2.ts b/packages/core/src/code_assist/oauth2.ts
index ac45177c..51227086 100644
--- a/packages/core/src/code_assist/oauth2.ts
+++ b/packages/core/src/code_assist/oauth2.ts
@@ -26,6 +26,7 @@ import {
clearCachedGoogleAccount,
} from '../utils/user_account.js';
import { AuthType } from '../core/contentGenerator.js';
+import { shouldAttemptBrowserLaunch } from '../utils/browser.js';
import readline from 'node:readline';
// OAuth Client ID used to initiate OAuth2Client class.
@@ -121,7 +122,7 @@ export async function getOauthClient(
}
}
- if (config.getNoBrowser()) {
+ if (config.getNoBrowser() || !shouldAttemptBrowserLaunch()) {
let success = false;
const maxRetries = 2;
for (let i = 0; !success && i < maxRetries; i++) {
@@ -156,15 +157,17 @@ export async function getOauthClient(
// causing the entire Node.js process to crash.
childProcess.on('error', (_) => {
console.error(
- 'Failed to open browser automatically. Please open the URL manually:',
+ 'Failed to open browser automatically. Please try running again with NO_BROWSER=true set.',
);
- console.error(webLogin.authUrl);
+ process.exit(1);
});
} catch (err) {
console.error(
'An unexpected error occurred while trying to open the browser:',
err,
+ '\nPlease try running again with NO_BROWSER=true set.',
);
+ process.exit(1);
}
console.log('Waiting for authentication...');
@@ -175,7 +178,7 @@ export async function getOauthClient(
}
async function authWithUserCode(client: OAuth2Client): Promise<boolean> {
- const redirectUri = 'https://sdk.cloud.google.com/authcode_cloudcode.html';
+ const redirectUri = 'https://codeassist.google.com/authcode';
const codeVerifier = await client.generateCodeVerifierAsync();
const state = crypto.randomBytes(32).toString('hex');
const authUrl: string = client.generateAuthUrl({