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