Skip to content

fix(cli): add GATEWAY auth type to validateAuthMethod#27553

Open
tmuskal wants to merge 1 commit into
google-gemini:mainfrom
tmuskal:fix/gateway-auth-validation
Open

fix(cli): add GATEWAY auth type to validateAuthMethod#27553
tmuskal wants to merge 1 commit into
google-gemini:mainfrom
tmuskal:fix/gateway-auth-validation

Conversation

@tmuskal
Copy link
Copy Markdown

@tmuskal tmuskal commented May 29, 2026

Summary

AuthType.GATEWAY was added in b705505 (PR #27021) to support custom base URL routing via GOOGLE_GEMINI_BASE_URL, but validateAuthMethod() in packages/cli/src/config/auth.ts was not updated to handle this new auth type.

When GOOGLE_GEMINI_BASE_URL is set (with GOOGLE_GENAI_USE_VERTEXAI=false), getAuthTypeFromEnv() correctly returns AuthType.GATEWAY, but validateAuthMethod() falls through all existing handlers (LOGIN_WITH_GOOGLE, COMPUTE_ADC, USE_GEMINI, USE_VERTEX_AI) and returns "Invalid auth method selected." (exit code 41).

Root cause

validateAuthMethod() handles four auth types but was missing GATEWAY:

// Before (missing GATEWAY)
if (authMethod === AuthType.LOGIN_WITH_GOOGLE || authMethod === AuthType.COMPUTE_ADC) return null;
if (authMethod === AuthType.USE_GEMINI) { /* validate GEMINI_API_KEY */ }
if (authMethod === AuthType.USE_VERTEX_AI) { /* validate project/location */ }
return 'Invalid auth method selected.'; // ← GATEWAY falls through here

Fix

Added AuthType.GATEWAY handler that returns null (valid, no validation needed). Gateway auth delegates authentication to the gateway itself — API keys are optional, handled downstream in createContentGeneratorConfig which falls back to GEMINI_API_KEY or empty string.

Changes

  • packages/cli/src/config/auth.ts — add GATEWAY case to validateAuthMethod()
  • packages/cli/src/config/auth.test.ts — add test case for GATEWAY auth type

Test plan

  • npx vitest run packages/cli/src/config/auth.test.ts — 9/9 tests pass (including new GATEWAY test)
  • npx vitest run packages/core/src/core/contentGenerator.test.ts — 47/47 tests pass (no regressions)
  • Verified git diff contains only the two intended file changes

Fixes #27550

AuthType.GATEWAY was added in b705505 (PR google-gemini#27021) for custom base URL
routing, but validateAuthMethod() was not updated to accept it. This
caused "Invalid auth method selected" (exit 41) when GOOGLE_GEMINI_BASE_URL
was set with a non-standard API key.

Fixes google-gemini#27550
@tmuskal tmuskal requested a review from a team as a code owner May 29, 2026 07:58
@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 29, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where the CLI failed to recognize the GATEWAY authentication method, causing it to incorrectly report an invalid auth method error. By updating the validation logic to include this type, the system now properly delegates authentication to the gateway as intended.

Highlights

  • Authentication Validation: Updated the validateAuthMethod function to correctly recognize and validate the GATEWAY authentication type.
  • Test Coverage: Added a new test case in auth.test.ts to ensure that GATEWAY authentication is handled correctly and returns no validation errors.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for the GATEWAY authentication type in the CLI configuration. Specifically, it updates validateAuthMethod in packages/cli/src/config/auth.ts to return null (indicating a valid authentication method) when the auth method is AuthType.GATEWAY, and adds a corresponding unit test in packages/cli/src/config/auth.test.ts to verify this behavior. I have no feedback to provide.

@gemini-cli gemini-cli Bot added priority/p1 Important and should be addressed in the near term. area/security Issues related to security labels May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/security Issues related to security priority/p1 Important and should be addressed in the near term.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: GOOGLE_API_KEY + GOOGLE_GEMINI_BASE_URL rejected with "Invalid auth method selected" in 0.44.x (worked in 0.43.0)

1 participant