diff --git a/config/hcp.go b/config/hcp.go index 4f76394f..461f9cc3 100644 --- a/config/hcp.go +++ b/config/hcp.go @@ -103,6 +103,9 @@ type hcpConfig struct { // noBrowserLogin is an option to prevent automatic browser login when no local credentials are found. noBrowserLogin bool + // noDefaultBrowser is an option to prevent the browser login from opening the default browser. + noDefaultBrowser bool + // suppressLogging is an option to prevent this SDK from printing anything suppressLogging bool diff --git a/config/tokensource.go b/config/tokensource.go index f5a28e8f..c3b18e85 100644 --- a/config/tokensource.go +++ b/config/tokensource.go @@ -143,7 +143,7 @@ func (c *hcpConfig) getTokenSource() (oauth2.TokenSource, sourceType, string, er var loginTokenSource oauth2.TokenSource if !c.noBrowserLogin { - loginTokenSource = auth.NewBrowserLogin(&c.oauth2Config) + loginTokenSource = auth.NewBrowserLogin(&c.oauth2Config, c.noDefaultBrowser) } return loginTokenSource, sourceTypeLogin, "", nil diff --git a/config/with.go b/config/with.go index dcc0a80a..1106bf51 100644 --- a/config/with.go +++ b/config/with.go @@ -154,6 +154,12 @@ func WithoutBrowserLogin() HCPConfigOption { return nil } } +func WithoutOpenDefaultBrowser() HCPConfigOption { + return func(config *hcpConfig) error { + config.noDefaultBrowser = true + return nil + } +} // WithoutLogging disables this SDK from printing of any kind, this is necessary // since there is not a consistent logger that is used throughout the project so diff --git a/config/with_test.go b/config/with_test.go index ecccd9bb..7e74c1e6 100644 --- a/config/with_test.go +++ b/config/with_test.go @@ -127,6 +127,17 @@ func TestWithout_BrowserLogin(t *testing.T) { require.True(config.noBrowserLogin) } +func TestWithout_OpenDefaultBrowser(t *testing.T) { + require := requirepkg.New(t) + + // Exercise + config := &hcpConfig{} + require.NoError(apply(config, WithoutOpenDefaultBrowser())) + + // Ensure browser login doesn't use the default browser + require.True(config.noDefaultBrowser) +} + func TestWith_CredentialFile(t *testing.T) { require := requirepkg.New(t)