ISSUE DESCRIPTION gemini-cli: support Login with Google (oauth-personal), mirroring…
- User
ISSUE DESCRIPTION
gemini-cli: support Login with Google (oauth-personal), mirroring codex auth.json The
codexagent injects a cached OAuth credential (~/.codex/auth.json) so runs can use a login instead of an API key (CODEX_AUTH_JSON_PATH/CODEX_FORCE_AUTH_JSON), andclaude-codeacceptsCLAUDE_CODE_OAUTH_TOKEN(#173).gemini-clihas no equivalent — it only wiresGEMINI_API_KEY/ Vertex env, so users with a "Login with Google" session (~/.gemini/oauth_creds.json) must keep a separate API key for runs.Proposal: add the same opt-in OAuth-credential injection to the
gemini-cliagent, mirroring the codex pattern —GEMINI_OAUTH_CREDS_PATH/GEMINI_FORCE_OAUTH, default behavior unchanged (fully backward-compatible).I have a working implementation that mirrors the codex auth flow (
_resolve_oauth_creds_path→ upload → chown →~/.gemini) with tests ported 1:1 fromtest_codex_auth.py, verified end-to-end (gemini-cli --ae GEMINI_FORCE_OAUTH=truecompleted hello-world, reward 1.0). Happy to open the PR or hand it off — whichever you prefer.ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
Assistant
Let me start by understanding the repository structure and the issue at hand. The issue is about adding OAuth credential support to
gemini-cli, mirroring the pattern used in thecodexagent. Let me explore the repository first.Assistant
Let me examine the existing codex auth implementation and the gemini-cli agent:
Assistant
Now let me look at the gemini-cli agent implementation:
Assistant
Now let me look at the test files for codex auth to understand the pattern:
Assistant
Now let me check the existing gemini-cli tests:
Assistant
Now let me look at the
parse_bool_env_valueutility and the_get_envmethod from the base class:Assistant
Now I have a good understanding of the codebase. Let me also check the EnvironmentPaths:
Assistant
Now I have a comprehensive understanding of the codebase. Let me create my implementation plan:
- Add
_resolve_oauth_creds_path()method toGeminiCli- mirrors_resolve_auth_json_path()fromCodex - Modify the
run()method inGeminiClito handle OAuth credential injection - upload the OAuth credentials file to the container and set up the~/.geminidirectory - Create test file
test_gemini_cli_oauth.pyported 1:1 fromtest_codex_auth.py
Let me implement this:
- Add
Assistant
I need to add OAuth credential support to the gemini-cli agent. Let me first understand the full structure of the file and then make the necessary changes. I need to:
- Add necessary imports (
PurePosixPathfrom pathlib,parse_bool_env_valuefrom harbor.utils.env) - Add class-level constants for remote paths (like codex has
_REMOTE_CODEX_HOMEand_REMOTE_CODEX_SECRETS_DIR) - Add
_resolve_oauth_creds_path()method mirroring_resolve_auth_json_path()from codex - Modify the
run()method to handle OAuth credential injection
Let me scroll through the file to understand the full structure.
- Add necessary imports (
Assistant
keydowns
Assistant
Now I have a clear picture of the file. Let me implement the changes:
- Add imports for
PurePosixPathandparse_bool_env_value - Add class constants for remote OAuth secrets directory
- Add
_resolve_oauth_creds_path()method - Modify
run()to handle OAuth credential injection
Let me make the edits:
- Add imports for
Assistant
Good. Now let me add the import for
parse_bool_env_value:Assistant
Now let me add the class-level constants after
_image_counterand before thename()static method:Assistant
Good. Now I need to add the
_resolve_oauth_creds_path()method. Let me find the right place to add it — I'll add it after_validate_reasoning_effortand beforeinstall:Assistant
Now I need to modify the
run()method to handle OAuth credential injection. Let me see the current run method:Assistant
Now I need to modify the
run()method to add OAuth credential injection. The key changes are:- Call
_resolve_oauth_creds_path()to check if OAuth creds should be used - If OAuth creds are present, upload the file and symlink it to
~/.gemini/oauth_creds.json - Only set auth env vars if OAuth is not being used (they would conflict)
Let me replace the
run()method:- Call
Assistant
The issue is with the exact text matching. Let me use line-based edit instead:
Assistant
Let me verify the rest of the file looks correct:
Assistant
Now let me create the test file, ported 1:1 from
test_codex_auth.py:Assistant
Now let me run the tests to verify everything works:
Assistant
I need to check how tests are typically run in this project:
Assistant
The package needs to be installed. Let me check how the tests are run:
Assistant
All 19 tests pass. Now let me also run the existing gemini-cli tests and codex auth tests to make sure I didn't break anything:
Assistant
All tests pass. Let me also run a broader set of related tests to make sure nothing is broken:
Assistant
All 601 tests pass, including the 19 new OAuth tests for Gemini CLI. Let me now verify the final state of my changes:
Assistant
Let me verify the test file was created properly and review the checklist before submitting.
Assistant
Let me go through the checklist before submitting:
-
If an error was reported in the issue description, I have successfully reproduced it.
- The issue wasn't about a specific error but a feature request (adding OAuth credential injection support to gemini-cli). I confirmed the feature was missing by examining the code and implemented it mirroring the codex pattern.
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- Since this is a feature request, I confirmed the fix works by:
- Since this is a feature request, I confirmed the fix works by:
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.