diff --git a/pkg/cmd/auth/login/login.go b/pkg/cmd/auth/login/login.go index fd10f9194..88bc09f63 100644 --- a/pkg/cmd/auth/login/login.go +++ b/pkg/cmd/auth/login/login.go @@ -20,12 +20,13 @@ import ( ) type LoginOptions struct { - IO *iostreams.IOStreams - Config func() (gh.Config, error) - HttpClient func() (*http.Client, error) - GitClient *git.Client - Prompter shared.Prompt - Browser browser.Browser + IO *iostreams.IOStreams + Config func() (gh.Config, error) + HttpClient func() (*http.Client, error) + PlainHttpClient func() (*http.Client, error) + GitClient *git.Client + Prompter shared.Prompt + Browser browser.Browser MainExecutable string @@ -43,12 +44,13 @@ type LoginOptions struct { func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Command { opts := &LoginOptions{ - IO: f.IOStreams, - Config: f.Config, - HttpClient: f.HttpClient, - GitClient: f.GitClient, - Prompter: f.Prompter, - Browser: f.Browser, + IO: f.IOStreams, + Config: f.Config, + HttpClient: f.HttpClient, + PlainHttpClient: f.PlainHttpClient, + GitClient: f.GitClient, + Prompter: f.Prompter, + Browser: f.Browser, } var tokenStdin bool @@ -190,6 +192,11 @@ func loginRun(opts *LoginOptions) error { return cmdutil.SilentError } + plainHTTPClient, err := opts.PlainHttpClient() + if err != nil { + return err + } + httpClient, err := opts.HttpClient() if err != nil { return err @@ -210,16 +217,17 @@ func loginRun(opts *LoginOptions) error { } return shared.Login(&shared.LoginOptions{ - IO: opts.IO, - Config: authCfg, - HTTPClient: httpClient, - Hostname: hostname, - Interactive: opts.Interactive, - Web: opts.Web, - Scopes: opts.Scopes, - GitProtocol: opts.GitProtocol, - Prompter: opts.Prompter, - Browser: opts.Browser, + IO: opts.IO, + Config: authCfg, + HTTPClient: httpClient, + PlainHTTPClient: plainHTTPClient, + Hostname: hostname, + Interactive: opts.Interactive, + Web: opts.Web, + Scopes: opts.Scopes, + GitProtocol: opts.GitProtocol, + Prompter: opts.Prompter, + Browser: opts.Browser, CredentialFlow: &shared.GitCredentialFlow{ Prompter: opts.Prompter, HelperConfig: &gitcredentials.HelperConfig{ diff --git a/pkg/cmd/auth/login/login_test.go b/pkg/cmd/auth/login/login_test.go index 8e2a023e8..7ec174973 100644 --- a/pkg/cmd/auth/login/login_test.go +++ b/pkg/cmd/auth/login/login_test.go @@ -483,6 +483,9 @@ func Test_loginRun_nontty(t *testing.T) { tt.opts.HttpClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil } + tt.opts.PlainHttpClient = func() (*http.Client, error) { + return &http.Client{Transport: reg}, nil + } if tt.httpStubs != nil { tt.httpStubs(reg) } @@ -775,6 +778,9 @@ func Test_loginRun_Survey(t *testing.T) { tt.opts.HttpClient = func() (*http.Client, error) { return &http.Client{Transport: reg}, nil } + tt.opts.PlainHttpClient = func() (*http.Client, error) { + return &http.Client{Transport: reg}, nil + } if tt.httpStubs != nil { tt.httpStubs(reg) } else { diff --git a/pkg/cmd/auth/shared/login_flow.go b/pkg/cmd/auth/shared/login_flow.go index 6d713d647..cd018430d 100644 --- a/pkg/cmd/auth/shared/login_flow.go +++ b/pkg/cmd/auth/shared/login_flow.go @@ -30,6 +30,7 @@ type LoginOptions struct { IO *iostreams.IOStreams Config iconfig HTTPClient *http.Client + PlainHTTPClient *http.Client Hostname string Interactive bool Web bool @@ -149,7 +150,7 @@ func Login(opts *LoginOptions) error { if authMode == 0 { var err error - authToken, username, err = authflow.AuthFlow(hostname, opts.IO, "", append(opts.Scopes, additionalScopes...), opts.Interactive, opts.Browser, opts.CopyToClipboard) + authToken, username, err = authflow.AuthFlow(opts.PlainHTTPClient, hostname, opts.IO, "", append(opts.Scopes, additionalScopes...), opts.Interactive, opts.Browser, opts.CopyToClipboard) if err != nil { return fmt.Errorf("failed to authenticate via web browser: %w", err) }