Skip to content

Commit

Permalink
Add proxy_url support for oauth2
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
  • Loading branch information
roidelapluie committed Mar 15, 2022
1 parent 00591a3 commit 0762b59
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
12 changes: 10 additions & 2 deletions config/http_config.go
Expand Up @@ -161,6 +161,8 @@ type OAuth2 struct {
TokenURL string `yaml:"token_url" json:"token_url"`
EndpointParams map[string]string `yaml:"endpoint_params,omitempty" json:"endpoint_params,omitempty"`

// HTTP proxy server to use to connect to the targets.
ProxyURL URL `yaml:"proxy_url,omitempty" json:"proxy_url,omitempty"`
// TLSConfig is used to connect to the token URL.
TLSConfig TLSConfig `yaml:"tls_config,omitempty"`
}
Expand Down Expand Up @@ -606,10 +608,16 @@ func (rt *oauth2RoundTripper) RoundTrip(req *http.Request) (*http.Response, erro

var t http.RoundTripper
if len(rt.config.TLSConfig.CAFile) == 0 {
t = &http.Transport{TLSClientConfig: tlsConfig}
t = &http.Transport{
TLSClientConfig: tlsConfig,
Proxy: http.ProxyURL(rt.config.ProxyURL.URL),
}
} else {
t, err = NewTLSRoundTripper(tlsConfig, rt.config.TLSConfig.CAFile, func(tls *tls.Config) (http.RoundTripper, error) {
return &http.Transport{TLSClientConfig: tls}, nil
return &http.Transport{
TLSClientConfig: tls,
Proxy: http.ProxyURL(rt.config.ProxyURL.URL),
}, nil
})
if err != nil {
return nil, err
Expand Down
7 changes: 7 additions & 0 deletions config/http_config_test.go
Expand Up @@ -1482,3 +1482,10 @@ func TestMarshalURLWithSecret(t *testing.T) {
t.Fatalf("URL not properly marshaled in YAML, got '%s'", string(b))
}
}

func TestOAuth2Proxy(t *testing.T) {
_, _, err := LoadHTTPConfigFile("testdata/http.conf.oauth2-proxy.good.yml")
if err != nil {
t.Errorf("Error loading OAuth2 client config: %v", err)
}
}
5 changes: 5 additions & 0 deletions config/testdata/http.conf.oauth2-proxy.good.yml
@@ -0,0 +1,5 @@
oauth2:
client_id: "myclient"
client_secret: "mysecret"
token_url: "http://auth"
proxy_url: "http://foo"

0 comments on commit 0762b59

Please sign in to comment.