Skip to content

Commit b4304c5

Browse files
authored
Make OAuth 2.0 token_url client_id and client_secret mandatory (#294)
* Made client_id and client_secret mandatory Signed-off-by: Levi Harrison <[email protected]>
1 parent 2270f5d commit b4304c5

6 files changed

+32
-0
lines changed

config/http_config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,15 @@ func (c *HTTPClientConfig) Validate() error {
210210
if c.BasicAuth != nil {
211211
return fmt.Errorf("at most one of basic_auth, oauth2 & authorization must be configured")
212212
}
213+
if len(c.OAuth2.ClientID) == 0 {
214+
return fmt.Errorf("oauth2 client_id must be configured")
215+
}
216+
if len(c.OAuth2.ClientSecret) == 0 && len(c.OAuth2.ClientSecretFile) == 0 {
217+
return fmt.Errorf("either oauth2 client_secret or client_secret_file must be configured")
218+
}
219+
if len(c.OAuth2.TokenURL) == 0 {
220+
return fmt.Errorf("oauth2 token_url must be configured")
221+
}
213222
if len(c.OAuth2.ClientSecret) > 0 && len(c.OAuth2.ClientSecretFile) > 0 {
214223
return fmt.Errorf("at most one of oauth2 client_secret & client_secret_file must be configured")
215224
}

config/http_config_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ var invalidHTTPClientConfigs = []struct {
107107
httpClientConfigFile: "testdata/http.conf.oauth2-secret-and-file-set.bad.yml",
108108
errMsg: "at most one of oauth2 client_secret & client_secret_file must be configured",
109109
},
110+
{
111+
httpClientConfigFile: "testdata/http.conf.oauth2-no-client-id.bad.yaml",
112+
errMsg: "oauth2 client_id must be configured",
113+
},
114+
{
115+
httpClientConfigFile: "testdata/http.conf.oauth2-no-client-secret.bad.yaml",
116+
errMsg: "either oauth2 client_secret or client_secret_file must be configured",
117+
},
118+
{
119+
httpClientConfigFile: "testdata/http.conf.oauth2-no-token-url.bad.yaml",
120+
errMsg: "oauth2 token_url must be configured",
121+
},
110122
}
111123

112124
func newTestServer(handler func(w http.ResponseWriter, r *http.Request)) (*httptest.Server, error) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
oauth2:
2+
client_secret: "mysecret"
3+
token_url: "http://auth"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
oauth2:
2+
client_id: "myclientid"
3+
token_url: "http://auth"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
oauth2:
2+
client_id: "myclientid"
3+
client_secret: "mysecret"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
oauth2:
2+
client_id: "myclient"
23
client_secret: "mysecret"
34
client_secret_file: "mysecret"
5+
token_url: "http://auth"

0 commit comments

Comments
 (0)