From 8a128d8dc6c1c5d7aea7004e0efa9fd175be36e5 Mon Sep 17 00:00:00 2001 From: Seth Troisi Date: Thu, 10 Jul 2025 18:59:02 -0700 Subject: Add NO_BROWSER environment variable to trigger offline oauth flow (#3713) --- packages/cli/src/config/config.ts | 1 + packages/cli/src/gemini.tsx | 10 ++++++++++ packages/cli/src/ui/App.tsx | 30 +++++++++++++++++++++++------- 3 files changed, 34 insertions(+), 7 deletions(-) (limited to 'packages/cli/src') diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index 20a8afcf..b80b6dd0 100644 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -317,6 +317,7 @@ export async function loadCliConfig( name: e.config.name, version: e.config.version, })), + noBrowser: !!process.env.NO_BROWSER, }); } diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx index 84a3da62..8b58c46a 100644 --- a/packages/cli/src/gemini.tsx +++ b/packages/cli/src/gemini.tsx @@ -35,6 +35,7 @@ import { sessionId, logUserPrompt, AuthType, + getOauthClient, } from '@google/gemini-cli-core'; import { validateAuthMethod } from './config/auth.js'; import { setMaxSizedBoxDebugging } from './ui/components/shared/MaxSizedBox.js'; @@ -165,6 +166,15 @@ export async function main() { } } } + + if ( + settings.merged.selectedAuthType === AuthType.LOGIN_WITH_GOOGLE && + config.getNoBrowser() + ) { + // Do oauth before app renders to make copying the link possible. + await getOauthClient(settings.merged.selectedAuthType, config); + } + let input = config.getQuestion(); const startupWarnings = [ ...(await getStartupWarnings()), diff --git a/packages/cli/src/ui/App.tsx b/packages/cli/src/ui/App.tsx index e3a5eb55..2a6bf088 100644 --- a/packages/cli/src/ui/App.tsx +++ b/packages/cli/src/ui/App.tsx @@ -728,13 +728,29 @@ const App = ({ config, settings, startupWarnings = [] }: AppProps) => { /> ) : isAuthenticating ? ( - { - setAuthError('Authentication timed out. Please try again.'); - cancelAuthentication(); - openAuthDialog(); - }} - /> + <> + { + setAuthError('Authentication timed out. Please try again.'); + cancelAuthentication(); + openAuthDialog(); + }} + /> + {showErrorDetails && ( + + + + + + + )} + ) : isAuthDialogOpen ? (