-
-
Notifications
You must be signed in to change notification settings - Fork 297
Zhizinan1997 test #299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zhizinan1997 test #299
Conversation
Summary of ChangesHello @zhizinan1997, 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 significantly improves the robustness of the Gemini OAuth2 authentication process, particularly for users operating in containerized (e.g., Docker) or remote environments. By implementing a manual callback input mechanism alongside the existing automatic flow, it ensures that users can successfully complete authentication even when network configurations prevent direct localhost callbacks, thereby enhancing usability and reliability. Highlights
Using Gemini Code AssistThe 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
Customization To customize 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 Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. 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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this 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 introduces a valuable enhancement by adding support for manual OAuth2 callback input, which is very helpful for users in Docker or remote environments. The implementation is mostly solid, with clear instructions for the user.
I've found a critical issue in the new extractCodeFromInput function that would prevent valid authorization codes from being parsed correctly. I've also included a couple of medium-severity suggestions to improve logging and code clarity. Addressing these points will make the new feature more robust and maintainable.
| } | ||
|
|
||
| // If input looks like a direct code (no spaces or special URL characters) | ||
| if !strings.Contains(input, " ") && !strings.Contains(input, "?") && !strings.Contains(input, "/") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check for a direct authorization code is incorrect. It prevents codes containing a forward slash (/) from being processed. Google's authorization codes can and often do contain slashes (e.g., the example in the PR description 4/0AY0e-g7r...). This will cause the authentication to fail for users who paste such a code directly. The check for / should be removed.
| if !strings.Contains(input, " ") && !strings.Contains(input, "?") && !strings.Contains(input, "/") { | |
| if !strings.Contains(input, " ") && !strings.Contains(input, "?") { |
| go func() { | ||
| if err := server.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) { | ||
| log.Fatalf("ListenAndServe(): %v", err) | ||
| log.Debugf("ListenAndServe(): %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using log.Debugf here is too silent if server.ListenAndServe() fails for reasons other than a graceful shutdown (e.g., port already in use). This would prevent the automatic callback from ever working, forcing the user into the manual flow without a clear indication of what went wrong. It's better to use log.Warnf to make this failure more visible in the logs.
| log.Debugf("ListenAndServe(): %v", err) | |
| log.Warnf("ListenAndServe(): %v", err) |
| // Try to parse as query string (code=... format) | ||
| if strings.HasPrefix(input, "code=") { | ||
| parts := strings.Split(input, "&") | ||
| for _, part := range parts { | ||
| if strings.HasPrefix(part, "code=") { | ||
| return strings.TrimPrefix(part, "code=") | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
For the issue: |
|
Didn't you modify |
I had not modified main.go or anyother file, look like works very well. If possible, I suggest that after obtaining the login link on the web management panel, add an input field for the callback URL. This would be very user-friendly for those who are not good with command-line operations or who have complex network environments. You can refer to the management webpage of the gcli2api project for inspiration. You can see a similar, very convenient implementation at the bottom of the gcli2api project’s web management page — the “Get credentials from the origin/return URL” feature in the screenshot. |
Actually, I ran into this issue myself because of a pretty complicated setup. |


Add Manual Callback Input Support for Docker/Remote Authentication
Description
This PR enhances the Gemini OAuth2 authentication flow to support manual callback URL input, which is particularly useful in Docker containers and remote environments where automatic localhost callbacks may not work due to network isolation.
Problem
When running
./CLIProxyAPI --loginin Docker:http://localhost:8085/oauth2callback?code=...Solution
This PR modifies
internal/auth/gemini/gemini_auth.goto:Parallel Listening: The authentication flow now simultaneously listens for:
Flexible Code Extraction: The
extractCodeFromInput()function intelligently extracts authorization codes from multiple input formats:http://localhost:8085/oauth2callback?code=xxx&state=yyy4/0AY0e-g7r...code=xxx&state=yyyUser-Friendly Instructions: Clear prompts guide users on:
Changes
Modified Files
internal/auth/gemini/gemini_auth.goKey Changes
bufioandosimports for stdin readinggetTokenFromWeb()to create a goroutine that listens for manual inputextractCodeFromInput()helper function to parse various input formatsUsage
In Docker environment: