v6.6.105
Unified · Split
| @@ -74,6 +74,7 @@ func main() { · 73 unmodified lines | ||
| 74 | 74 | var iflowLogin bool |
| 75 | 75 | var iflowCookie bool |
| 76 | 76 | var noBrowser bool |
| 77 | + var oauthCallbackPort int | |
| 77 | 78 | var antigravityLogin bool |
| 78 | 79 | var kiroLogin bool |
| 79 | 80 | var kiroGoogleLogin bool |
| @@ -96,6 +97,7 @@ func main() { · 16 unmodified lines | ||
| 96 | 97 | flag.BoolVar(&iflowLogin, "iflow-login", false, "Login to iFlow using OAuth") |
| 97 | 98 | flag.BoolVar(&iflowCookie, "iflow-cookie", false, "Login to iFlow using Cookie") |
| 98 | 99 | flag.BoolVar(&noBrowser, "no-browser", false, "Don't open browser automatically for OAuth") |
| 100 | + flag.IntVar(&oauthCallbackPort, "oauth-callback-port", 0, "Override OAuth callback port (defaults to provider-specific port)") | |
| 99 | 101 | flag.BoolVar(&useIncognito, "incognito", false, "Open browser in incognito/private mode for OAuth (useful for multiple accounts)") |
| 100 | 102 | flag.BoolVar(&noIncognito, "no-incognito", false, "Force disable incognito mode (uses existing browser session)") |
| 101 | 103 | flag.BoolVar(&antigravityLogin, "antigravity-login", false, "Login to Antigravity using OAuth") |
| @@ -454,7 +456,8 @@ func main() { · 352 unmodified lines | ||
| 454 | 456 | |
| 455 | 457 | // Create login options to be used in authentication flows. |
| 456 | 458 | options := &cmd.LoginOptions{ |
| 457 | − NoBrowser: noBrowser, | |
| 459 | + NoBrowser: noBrowser, | |
| 460 | + CallbackPort: oauthCallbackPort, | |
| 458 | 461 | } |
| 459 | 462 | |
| 460 | 463 | // Register the shared token store once so all components use the same persistence backend. |
| @@ -29,8 +29,9 @@ import ( · 28 unmodified lines | ||
| 29 | 29 | ) |
| 30 | 30 | |
| 31 | 31 | const ( |
| 32 | − geminiOauthClientID = "681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com" | |
| 33 | − geminiOauthClientSecret = "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" | |
| 32 | + geminiOauthClientID = "681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com" | |
| 33 | + geminiOauthClientSecret = "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" | |
| 34 | + geminiDefaultCallbackPort = 8085 | |
| 34 | 35 | ) |
| 35 | 36 | |
| 36 | 37 | var ( |
| @@ -49,8 +50,9 @@ type GeminiAuth struct { · 12 unmodified lines | ||
| 49 | 50 | |
| 50 | 51 | // WebLoginOptions customizes the interactive OAuth flow. |
| 51 | 52 | type WebLoginOptions struct { |
| 52 | − NoBrowser bool | |
| 53 | − Prompt func(string) (string, error) | |
| 53 | + NoBrowser bool | |
| 54 | + CallbackPort int | |
| 55 | + Prompt func(string) (string, error) | |
| 54 | 56 | } |
| 55 | 57 | |
| 56 | 58 | // NewGeminiAuth creates a new instance of GeminiAuth. |
| @@ -72,6 +74,12 @@ func NewGeminiAuth() *GeminiAuth { · 15 unmodified lines | ||
| 72 | 74 | // - *http.Client: An HTTP client configured with authentication |
| 73 | 75 | // - error: An error if the client configuration fails, nil otherwise |
| 74 | 76 | func (g *GeminiAuth) GetAuthenticatedClient(ctx context.Context, ts *GeminiTokenStorage, cfg *config.Config, opts *WebLoginOptions) (*http.Client, error) { |
| 77 | + callbackPort := geminiDefaultCallbackPort | |
| 78 | + if opts != nil && opts.CallbackPort > 0 { | |
| 79 | + callbackPort = opts.CallbackPort | |
| 80 | + } | |
| 81 | + callbackURL := fmt.Sprintf("http://localhost:%d/oauth2callback", callbackPort) | |
| 82 | + | |
| 75 | 83 | // Configure proxy settings for the HTTP client if a proxy URL is provided. |
| 76 | 84 | proxyURL, err := url.Parse(cfg.ProxyURL) |
| 77 | 85 | if err == nil { |
| @@ -106,7 +114,7 @@ func (g *GeminiAuth) GetAuthenticatedClient(ctx context.Context, ts *GeminiToken · 28 unmodified lines | ||
| 106 | 114 | conf := &oauth2.Config{ |
| 107 | 115 | ClientID: geminiOauthClientID, |
| 108 | 116 | ClientSecret: geminiOauthClientSecret, |
| 109 | − RedirectURL: "http://localhost:8085/oauth2callback", // This will be used by the local server. | |
| 117 | + RedirectURL: callbackURL, // This will be used by the local server. | |
| 110 | 118 | Scopes: geminiOauthScopes, |
| 111 | 119 | Endpoint: google.Endpoint, |
| 112 | 120 | } |
| @@ -218,14 +226,20 @@ func (g *GeminiAuth) createTokenStorage(ctx context.Context, config *oauth2.Conf · 105 unmodified lines | ||
| 218 | 226 | // - *oauth2.Token: The OAuth2 token obtained from the authorization flow |
| 219 | 227 | // - error: An error if the token acquisition fails, nil otherwise |
| 220 | 228 | func (g *GeminiAuth) getTokenFromWeb(ctx context.Context, config *oauth2.Config, opts *WebLoginOptions) (*oauth2.Token, error) { |
| 229 | + callbackPort := geminiDefaultCallbackPort | |
| 230 | + if opts != nil && opts.CallbackPort > 0 { | |
| 231 | + callbackPort = opts.CallbackPort | |
| 232 | + } | |
| 233 | + callbackURL := fmt.Sprintf("http://localhost:%d/oauth2callback", callbackPort) | |
| 234 | + | |
| 221 | 235 | // Use a channel to pass the authorization code from the HTTP handler to the main function. |
| 222 | 236 | codeChan := make(chan string, 1) |
| 223 | 237 | errChan := make(chan error, 1) |
| 224 | 238 | |
| 225 | 239 | // Create a new HTTP server with its own multiplexer. |
| 226 | 240 | mux := http.NewServeMux() |
| 227 | − server := &http.Server{Addr: ":8085", Handler: mux} | |
| 228 | − config.RedirectURL = "http://localhost:8085/oauth2callback" | |
| 241 | + server := &http.Server{Addr: fmt.Sprintf(":%d", callbackPort), Handler: mux} | |
| 242 | + config.RedirectURL = callbackURL | |
| 229 | 243 | |
| 230 | 244 | mux.HandleFunc("/oauth2callback", func(w http.ResponseWriter, r *http.Request) { |
| 231 | 245 | if err := r.URL.Query().Get("error"); err != "" { |
| @@ -277,13 +291,13 @@ func (g *GeminiAuth) getTokenFromWeb(ctx context.Context, config *oauth2.Config, · 45 unmodified lines | ||
| 277 | 291 | // Check if browser is available |
| 278 | 292 | if !browser.IsAvailable() { |
| 279 | 293 | log.Warn("No browser available on this system") |
| 280 | − util.PrintSSHTunnelInstructions(8085) | |
| 294 | + util.PrintSSHTunnelInstructions(callbackPort) | |
| 281 | 295 | fmt.Printf("Please manually open this URL in your browser:\n\n%s\n", authURL) |
| 282 | 296 | } else { |
| 283 | 297 | if err := browser.OpenURL(authURL); err != nil { |
| 284 | 298 | authErr := codex.NewAuthenticationError(codex.ErrBrowserOpenFailed, err) |
| 285 | 299 | log.Warn(codex.GetUserFriendlyMessage(authErr)) |
| 286 | − util.PrintSSHTunnelInstructions(8085) | |
| 300 | + util.PrintSSHTunnelInstructions(callbackPort) | |
| 287 | 301 | fmt.Printf("Please manually open this URL in your browser:\n\n%s\n", authURL) |
| 288 | 302 | |
| 289 | 303 | // Log platform info for debugging |
| @@ -294,7 +308,7 @@ func (g *GeminiAuth) getTokenFromWeb(ctx context.Context, config *oauth2.Config, · 4 unmodified lines | ||
| 294 | 308 | } |
| 295 | 309 | } |
| 296 | 310 | } else { |
| 297 | − util.PrintSSHTunnelInstructions(8085) | |
| 311 | + util.PrintSSHTunnelInstructions(callbackPort) | |
| 298 | 312 | fmt.Printf("Please open this URL in your browser:\n\n%s\n", authURL) |
| 299 | 313 | } |
| 300 | 314 | |
| @@ -32,9 +32,10 @@ func DoClaudeLogin(cfg *config.Config, options *LoginOptions) { · 31 unmodified lines | ||
| 32 | 32 | manager := newAuthManager() |
| 33 | 33 | |
| 34 | 34 | authOpts := &sdkAuth.LoginOptions{ |
| 35 | − NoBrowser: options.NoBrowser, | |
| 36 | − Metadata: map[string]string{}, | |
| 37 | − Prompt: promptFn, | |
| 35 | + NoBrowser: options.NoBrowser, | |
| 36 | + CallbackPort: options.CallbackPort, | |
| 37 | + Metadata: map[string]string{}, | |
| 38 | + Prompt: promptFn, | |
| 38 | 39 | } |
| 39 | 40 | |
| 40 | 41 | _, savedPath, err := manager.Login(context.Background(), "claude", cfg, authOpts) |
| @@ -22,9 +22,10 @@ func DoAntigravityLogin(cfg *config.Config, options *LoginOptions) { · 21 unmodified lines | ||
| 22 | 22 | |
| 23 | 23 | manager := newAuthManager() |
| 24 | 24 | authOpts := &sdkAuth.LoginOptions{ |
| 25 | − NoBrowser: options.NoBrowser, | |
| 26 | − Metadata: map[string]string{}, | |
| 27 | − Prompt: promptFn, | |
| 25 | + NoBrowser: options.NoBrowser, | |
| 26 | + CallbackPort: options.CallbackPort, | |
| 27 | + Metadata: map[string]string{}, | |
| 28 | + Prompt: promptFn, | |
| 28 | 29 | } |
| 29 | 30 | |
| 30 | 31 | record, savedPath, err := manager.Login(context.Background(), "antigravity", cfg, authOpts) |
| @@ -24,9 +24,10 @@ func DoIFlowLogin(cfg *config.Config, options *LoginOptions) { · 23 unmodified lines | ||
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | authOpts := &sdkAuth.LoginOptions{ |
| 27 | − NoBrowser: options.NoBrowser, | |
| 28 | − Metadata: map[string]string{}, | |
| 29 | − Prompt: promptFn, | |
| 27 | + NoBrowser: options.NoBrowser, | |
| 28 | + CallbackPort: options.CallbackPort, | |
| 29 | + Metadata: map[string]string{}, | |
| 30 | + Prompt: promptFn, | |
| 30 | 31 | } |
| 31 | 32 | |
| 32 | 33 | _, savedPath, err := manager.Login(context.Background(), "iflow", cfg, authOpts) |
| @@ -67,10 +67,11 @@ func DoLogin(cfg *config.Config, projectID string, options *LoginOptions) { · 66 unmodified lines | ||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | loginOpts := &sdkAuth.LoginOptions{ |
| 70 | − NoBrowser: options.NoBrowser, | |
| 71 | − ProjectID: trimmedProjectID, | |
| 72 | − Metadata: map[string]string{}, | |
| 73 | − Prompt: callbackPrompt, | |
| 70 | + NoBrowser: options.NoBrowser, | |
| 71 | + ProjectID: trimmedProjectID, | |
| 72 | + CallbackPort: options.CallbackPort, | |
| 73 | + Metadata: map[string]string{}, | |
| 74 | + Prompt: callbackPrompt, | |
| 74 | 75 | } |
| 75 | 76 | |
| 76 | 77 | authenticator := sdkAuth.NewGeminiAuthenticator() |
| @@ -88,8 +89,9 @@ func DoLogin(cfg *config.Config, projectID string, options *LoginOptions) { · 11 unmodified lines | ||
| 88 | 89 | |
| 89 | 90 | geminiAuth := gemini.NewGeminiAuth() |
| 90 | 91 | httpClient, errClient := geminiAuth.GetAuthenticatedClient(ctx, storage, cfg, &gemini.WebLoginOptions{ |
| 91 | − NoBrowser: options.NoBrowser, | |
| 92 | − Prompt: callbackPrompt, | |
| 92 | + NoBrowser: options.NoBrowser, | |
| 93 | + CallbackPort: options.CallbackPort, | |
| 94 | + Prompt: callbackPrompt, | |
| 93 | 95 | }) |
| 94 | 96 | if errClient != nil { |
| 95 | 97 | log.Errorf("Gemini authentication failed: %v", errClient) |
| @@ -19,6 +19,9 @@ type LoginOptions struct { · 18 unmodified lines | ||
| 19 | 19 | // NoBrowser indicates whether to skip opening the browser automatically. |
| 20 | 20 | NoBrowser bool |
| 21 | 21 | |
| 22 | + // CallbackPort overrides the local OAuth callback port when set (>0). | |
| 23 | + CallbackPort int | |
| 24 | + | |
| 22 | 25 | // Prompt allows the caller to provide interactive input when needed. |
| 23 | 26 | Prompt func(prompt string) (string, error) |
| 24 | 27 | } |
| @@ -43,9 +46,10 @@ func DoCodexLogin(cfg *config.Config, options *LoginOptions) { · 18 unmodified lines | ||
| 43 | 46 | manager := newAuthManager() |
| 44 | 47 | |
| 45 | 48 | authOpts := &sdkAuth.LoginOptions{ |
| 46 | − NoBrowser: options.NoBrowser, | |
| 47 | − Metadata: map[string]string{}, | |
| 48 | − Prompt: promptFn, | |
| 49 | + NoBrowser: options.NoBrowser, | |
| 50 | + CallbackPort: options.CallbackPort, | |
| 51 | + Metadata: map[string]string{}, | |
| 52 | + Prompt: promptFn, | |
| 49 | 53 | } |
| 50 | 54 | |
| 51 | 55 | _, savedPath, err := manager.Login(context.Background(), "codex", cfg, authOpts) |
| @@ -36,9 +36,10 @@ func DoQwenLogin(cfg *config.Config, options *LoginOptions) { · 35 unmodified lines | ||
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | authOpts := &sdkAuth.LoginOptions{ |
| 39 | − NoBrowser: options.NoBrowser, | |
| 40 | − Metadata: map[string]string{}, | |
| 41 | − Prompt: promptFn, | |
| 39 | + NoBrowser: options.NoBrowser, | |
| 40 | + CallbackPort: options.CallbackPort, | |
| 41 | + Metadata: map[string]string{}, | |
| 42 | + Prompt: promptFn, | |
| 42 | 43 | } |
| 43 | 44 | |
| 44 | 45 | _, savedPath, err := manager.Login(context.Background(), "qwen", cfg, authOpts) |
| @@ -251,6 +251,7 @@ func ConvertClaudeResponseToOpenAIResponses(ctx context.Context, modelName strin · 250 unmodified lines | ||
| 251 | 251 | itemDone, _ = sjson.Set(itemDone, "item.id", fmt.Sprintf("fc_%s", st.CurrentFCID)) |
| 252 | 252 | itemDone, _ = sjson.Set(itemDone, "item.arguments", args) |
| 253 | 253 | itemDone, _ = sjson.Set(itemDone, "item.call_id", st.CurrentFCID) |
| 254 | + itemDone, _ = sjson.Set(itemDone, "item.name", st.FuncNames[idx]) | |
| 254 | 255 | out = append(out, emitEvent("response.output_item.done", itemDone)) |
| 255 | 256 | st.InFuncBlock = false |
| 256 | 257 | } else if st.ReasoningActive { |
| @@ -60,6 +60,11 @@ func (AntigravityAuthenticator) Login(ctx context.Context, cfg *config.Config, o · 59 unmodified lines | ||
| 60 | 60 | opts = &LoginOptions{} |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | + callbackPort := antigravityCallbackPort | |
| 64 | + if opts.CallbackPort > 0 { | |
| 65 | + callbackPort = opts.CallbackPort | |
| 66 | + } | |
| 67 | + | |
| 63 | 68 | httpClient := util.SetProxy(&cfg.SDKConfig, &http.Client{}) |
| 64 | 69 | |
| 65 | 70 | state, err := misc.GenerateRandomState() |
| @@ -67,7 +72,7 @@ func (AntigravityAuthenticator) Login(ctx context.Context, cfg *config.Config, o · 1 unmodified line | ||
| 67 | 72 | return nil, fmt.Errorf("antigravity: failed to generate state: %w", err) |
| 68 | 73 | } |
| 69 | 74 | |
| 70 | − srv, port, cbChan, errServer := startAntigravityCallbackServer() | |
| 75 | + srv, port, cbChan, errServer := startAntigravityCallbackServer(callbackPort) | |
| 71 | 76 | if errServer != nil { |
| 72 | 77 | return nil, fmt.Errorf("antigravity: failed to start callback server: %w", errServer) |
| 73 | 78 | } |
| @@ -224,13 +229,16 @@ type callbackResult struct { · 150 unmodified lines | ||
| 224 | 229 | State string |
| 225 | 230 | } |
| 226 | 231 | |
| 227 | −func startAntigravityCallbackServer() (*http.Server, int, <-chan callbackResult, error) { | |
| 228 | − addr := fmt.Sprintf(":%d", antigravityCallbackPort) | |
| 232 | +func startAntigravityCallbackServer(port int) (*http.Server, int, <-chan callbackResult, error) { | |
| 233 | + if port <= 0 { | |
| 234 | + port = antigravityCallbackPort | |
| 235 | + } | |
| 236 | + addr := fmt.Sprintf(":%d", port) | |
| 229 | 237 | listener, err := net.Listen("tcp", addr) |
| 230 | 238 | if err != nil { |
| 231 | 239 | return nil, 0, nil, err |
| 232 | 240 | } |
| 233 | − port := listener.Addr().(*net.TCPAddr).Port | |
| 241 | + port = listener.Addr().(*net.TCPAddr).Port | |
| 234 | 242 | resultCh := make(chan callbackResult, 1) |
| 235 | 243 | |
| 236 | 244 | mux := http.NewServeMux() |
| @@ -47,6 +47,11 @@ func (a *ClaudeAuthenticator) Login(ctx context.Context, cfg *config.Config, opt · 46 unmodified lines | ||
| 47 | 47 | opts = &LoginOptions{} |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | + callbackPort := a.CallbackPort | |
| 51 | + if opts.CallbackPort > 0 { | |
| 52 | + callbackPort = opts.CallbackPort | |
| 53 | + } | |
| 54 | + | |
| 50 | 55 | pkceCodes, err := claude.GeneratePKCECodes() |
| 51 | 56 | if err != nil { |
| 52 | 57 | return nil, fmt.Errorf("claude pkce generation failed: %w", err) |
| @@ -57,7 +62,7 @@ func (a *ClaudeAuthenticator) Login(ctx context.Context, cfg *config.Config, opt · 4 unmodified lines | ||
| 57 | 62 | return nil, fmt.Errorf("claude state generation failed: %w", err) |
| 58 | 63 | } |
| 59 | 64 | |
| 60 | − oauthServer := claude.NewOAuthServer(a.CallbackPort) | |
| 65 | + oauthServer := claude.NewOAuthServer(callbackPort) | |
| 61 | 66 | if err = oauthServer.Start(); err != nil { |
| 62 | 67 | if strings.Contains(err.Error(), "already in use") { |
| 63 | 68 | return nil, claude.NewAuthenticationError(claude.ErrPortInUse, err) |
| @@ -84,15 +89,15 @@ func (a *ClaudeAuthenticator) Login(ctx context.Context, cfg *config.Config, opt · 20 unmodified lines | ||
| 84 | 89 | fmt.Println("Opening browser for Claude authentication") |
| 85 | 90 | if !browser.IsAvailable() { |
| 86 | 91 | log.Warn("No browser available; please open the URL manually") |
| 87 | − util.PrintSSHTunnelInstructions(a.CallbackPort) | |
| 92 | + util.PrintSSHTunnelInstructions(callbackPort) | |
| 88 | 93 | fmt.Printf("Visit the following URL to continue authentication:\n%s\n", authURL) |
| 89 | 94 | } else if err = browser.OpenURL(authURL); err != nil { |
| 90 | 95 | log.Warnf("Failed to open browser automatically: %v", err) |
| 91 | − util.PrintSSHTunnelInstructions(a.CallbackPort) | |
| 96 | + util.PrintSSHTunnelInstructions(callbackPort) | |
| 92 | 97 | fmt.Printf("Visit the following URL to continue authentication:\n%s\n", authURL) |
| 93 | 98 | } |
| 94 | 99 | } else { |
| 95 | − util.PrintSSHTunnelInstructions(a.CallbackPort) | |
| 100 | + util.PrintSSHTunnelInstructions(callbackPort) | |
| 96 | 101 | fmt.Printf("Visit the following URL to continue authentication:\n%s\n", authURL) |
| 97 | 102 | } |
| 98 | 103 | |
| @@ -47,6 +47,11 @@ func (a *CodexAuthenticator) Login(ctx context.Context, cfg *config.Config, opts · 46 unmodified lines | ||
| 47 | 47 | opts = &LoginOptions{} |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | + callbackPort := a.CallbackPort | |
| 51 | + if opts.CallbackPort > 0 { | |
| 52 | + callbackPort = opts.CallbackPort | |
| 53 | + } | |
| 54 | + | |
| 50 | 55 | pkceCodes, err := codex.GeneratePKCECodes() |
| 51 | 56 | if err != nil { |
| 52 | 57 | return nil, fmt.Errorf("codex pkce generation failed: %w", err) |
| @@ -57,7 +62,7 @@ func (a *CodexAuthenticator) Login(ctx context.Context, cfg *config.Config, opts · 4 unmodified lines | ||
| 57 | 62 | return nil, fmt.Errorf("codex state generation failed: %w", err) |
| 58 | 63 | } |
| 59 | 64 | |
| 60 | − oauthServer := codex.NewOAuthServer(a.CallbackPort) | |
| 65 | + oauthServer := codex.NewOAuthServer(callbackPort) | |
| 61 | 66 | if err = oauthServer.Start(); err != nil { |
| 62 | 67 | if strings.Contains(err.Error(), "already in use") { |
| 63 | 68 | return nil, codex.NewAuthenticationError(codex.ErrPortInUse, err) |
| @@ -83,15 +88,15 @@ func (a *CodexAuthenticator) Login(ctx context.Context, cfg *config.Config, opts · 19 unmodified lines | ||
| 83 | 88 | fmt.Println("Opening browser for Codex authentication") |
| 84 | 89 | if !browser.IsAvailable() { |
| 85 | 90 | log.Warn("No browser available; please open the URL manually") |
| 86 | − util.PrintSSHTunnelInstructions(a.CallbackPort) | |
| 91 | + util.PrintSSHTunnelInstructions(callbackPort) | |
| 87 | 92 | fmt.Printf("Visit the following URL to continue authentication:\n%s\n", authURL) |
| 88 | 93 | } else if err = browser.OpenURL(authURL); err != nil { |
| 89 | 94 | log.Warnf("Failed to open browser automatically: %v", err) |
| 90 | − util.PrintSSHTunnelInstructions(a.CallbackPort) | |
| 95 | + util.PrintSSHTunnelInstructions(callbackPort) | |
| 91 | 96 | fmt.Printf("Visit the following URL to continue authentication:\n%s\n", authURL) |
| 92 | 97 | } |
| 93 | 98 | } else { |
| 94 | − util.PrintSSHTunnelInstructions(a.CallbackPort) | |
| 99 | + util.PrintSSHTunnelInstructions(callbackPort) | |
| 95 | 100 | fmt.Printf("Visit the following URL to continue authentication:\n%s\n", authURL) |
| 96 | 101 | } |
| 97 | 102 | |
| @@ -45,8 +45,9 @@ func (a *GeminiAuthenticator) Login(ctx context.Context, cfg *config.Config, opt · 44 unmodified lines | ||
| 45 | 45 | |
| 46 | 46 | geminiAuth := gemini.NewGeminiAuth() |
| 47 | 47 | _, err := geminiAuth.GetAuthenticatedClient(ctx, &ts, cfg, &gemini.WebLoginOptions{ |
| 48 | − NoBrowser: opts.NoBrowser, | |
| 49 | − Prompt: opts.Prompt, | |
| 48 | + NoBrowser: opts.NoBrowser, | |
| 49 | + CallbackPort: opts.CallbackPort, | |
| 50 | + Prompt: opts.Prompt, | |
| 50 | 51 | }) |
| 51 | 52 | if err != nil { |
| 52 | 53 | return nil, fmt.Errorf("gemini authentication failed: %w", err) |
| @@ -42,9 +42,14 @@ func (a *IFlowAuthenticator) Login(ctx context.Context, cfg *config.Config, opts · 41 unmodified lines | ||
| 42 | 42 | opts = &LoginOptions{} |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | + callbackPort := iflow.CallbackPort | |
| 46 | + if opts.CallbackPort > 0 { | |
| 47 | + callbackPort = opts.CallbackPort | |
| 48 | + } | |
| 49 | + | |
| 45 | 50 | authSvc := iflow.NewIFlowAuth(cfg) |
| 46 | 51 | |
| 47 | − oauthServer := iflow.NewOAuthServer(iflow.CallbackPort) | |
| 52 | + oauthServer := iflow.NewOAuthServer(callbackPort) | |
| 48 | 53 | if err := oauthServer.Start(); err != nil { |
| 49 | 54 | if strings.Contains(err.Error(), "already in use") { |
| 50 | 55 | return nil, fmt.Errorf("iflow authentication server port in use: %w", err) |
| @@ -64,21 +69,21 @@ func (a *IFlowAuthenticator) Login(ctx context.Context, cfg *config.Config, opts · 13 unmodified lines | ||
| 64 | 69 | return nil, fmt.Errorf("iflow auth: failed to generate state: %w", err) |
| 65 | 70 | } |
| 66 | 71 | |
| 67 | − authURL, redirectURI := authSvc.AuthorizationURL(state, iflow.CallbackPort) | |
| 72 | + authURL, redirectURI := authSvc.AuthorizationURL(state, callbackPort) | |
| 68 | 73 | |
| 69 | 74 | if !opts.NoBrowser { |
| 70 | 75 | fmt.Println("Opening browser for iFlow authentication") |
| 71 | 76 | if !browser.IsAvailable() { |
| 72 | 77 | log.Warn("No browser available; please open the URL manually") |
| 73 | − util.PrintSSHTunnelInstructions(iflow.CallbackPort) | |
| 78 | + util.PrintSSHTunnelInstructions(callbackPort) | |
| 74 | 79 | fmt.Printf("Visit the following URL to continue authentication:\n%s\n", authURL) |
| 75 | 80 | } else if err = browser.OpenURL(authURL); err != nil { |
| 76 | 81 | log.Warnf("Failed to open browser automatically: %v", err) |
| 77 | − util.PrintSSHTunnelInstructions(iflow.CallbackPort) | |
| 82 | + util.PrintSSHTunnelInstructions(callbackPort) | |
| 78 | 83 | fmt.Printf("Visit the following URL to continue authentication:\n%s\n", authURL) |
| 79 | 84 | } |
| 80 | 85 | } else { |
| 81 | − util.PrintSSHTunnelInstructions(iflow.CallbackPort) | |
| 86 | + util.PrintSSHTunnelInstructions(callbackPort) | |
| 82 | 87 | fmt.Printf("Visit the following URL to continue authentication:\n%s\n", authURL) |
| 83 | 88 | } |
| 84 | 89 | |
| @@ -14,10 +14,11 @@ var ErrRefreshNotSupported = errors.New("cliproxy auth: refresh not supported") · 13 unmodified lines | ||
| 14 | 14 | // LoginOptions captures generic knobs shared across authenticators. |
| 15 | 15 | // Provider-specific logic can inspect Metadata for extra parameters. |
| 16 | 16 | type LoginOptions struct { |
| 17 | − NoBrowser bool | |
| 18 | − ProjectID string | |
| 19 | − Metadata map[string]string | |
| 20 | − Prompt func(prompt string) (string, error) | |
| 17 | + NoBrowser bool | |
| 18 | + ProjectID string | |
| 19 | + CallbackPort int | |
| 20 | + Metadata map[string]string | |
| 21 | + Prompt func(prompt string) (string, error) | |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | 24 | // Authenticator manages login and optional refresh flows for a provider. |