mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-15 12:30:32 -07:00
fix(core): restore auth consent in headless mode and add unit tests (#19689)
This commit is contained in:
@@ -12,22 +12,21 @@ import { isHeadlessMode } from './headless.js';
|
||||
|
||||
/**
|
||||
* Requests consent from the user for OAuth login.
|
||||
* Handles both TTY and non-TTY environments.
|
||||
* Handles both interactive and non-interactive (headless) modes.
|
||||
*/
|
||||
export async function getConsentForOauth(prompt: string): Promise<boolean> {
|
||||
const finalPrompt = prompt + ' Opening authentication page in your browser. ';
|
||||
|
||||
if (coreEvents.listenerCount(CoreEvent.ConsentRequest) === 0) {
|
||||
if (isHeadlessMode()) {
|
||||
throw new FatalAuthenticationError(
|
||||
'Interactive consent could not be obtained.\n' +
|
||||
'Please run Gemini CLI in an interactive terminal to authenticate, or use NO_BROWSER=true for manual authentication.',
|
||||
);
|
||||
}
|
||||
if (isHeadlessMode()) {
|
||||
return getOauthConsentNonInteractive(finalPrompt);
|
||||
} else if (coreEvents.listenerCount(CoreEvent.ConsentRequest) > 0) {
|
||||
return getOauthConsentInteractive(finalPrompt);
|
||||
}
|
||||
|
||||
return getOauthConsentInteractive(finalPrompt);
|
||||
throw new FatalAuthenticationError(
|
||||
'Authentication consent could not be obtained.\n' +
|
||||
'Please run Gemini CLI in an interactive terminal to authenticate, ' +
|
||||
'or use NO_BROWSER=true for manual authentication.',
|
||||
);
|
||||
}
|
||||
|
||||
async function getOauthConsentNonInteractive(prompt: string) {
|
||||
|
||||
Reference in New Issue
Block a user