Skip to content

Commit

Permalink
Made client_id and client_secret mandatory
Browse files Browse the repository at this point in the history
Levi Harrison <git@leviharrison.dev>
  • Loading branch information
LeviHarrison authored Apr 27, 2021
1 parent 2270f5d commit dd23553
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/http_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ func (c *HTTPClientConfig) Validate() error {
if c.BasicAuth != nil {
return fmt.Errorf("at most one of basic_auth, oauth2 & authorization must be configured")
}
if len(c.OAuth2.ClientID) < 1 || (len(c.OAuth2.ClientSecret) < 1 || len(c.OAuth2.ClientSecretFile) < 1) {
return fmt.Errorf("the oauth2 client_id and either the client_secret or client_secret_file must be configured")
}
if len(c.OAuth2.ClientSecret) > 0 && len(c.OAuth2.ClientSecretFile) > 0 {
return fmt.Errorf("at most one of oauth2 client_secret & client_secret_file must be configured")
}
Expand Down
8 changes: 8 additions & 0 deletions config/http_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ var invalidHTTPClientConfigs = []struct {
httpClientConfigFile: "testdata/http.conf.oauth2-secret-and-file-set.bad.yml",
errMsg: "at most one of oauth2 client_secret & client_secret_file must be configured",
},
{
httpClientConfigFile: "testdata/http.conf.oauth2-no-client-id.bad.yaml",
errMsg: "the oauth2 client_id and either the client_secret or client_secret_file must be configured",
},
{
httpClientConfigFile: "testdata/http.conf.oauth2-no-client-secret.bad.yaml",
errMsg: "the oauth2 client_id and either the client_secret or client_secret_file must be configured",
},
}

func newTestServer(handler func(w http.ResponseWriter, r *http.Request)) (*httptest.Server, error) {
Expand Down
2 changes: 2 additions & 0 deletions config/testdata/http.conf.oauth2-no-client-id.bad.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
oauth2:
client_secret: "mysecret"
2 changes: 2 additions & 0 deletions config/testdata/http.conf.oauth2-no-client-secret.bad.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
oauth2:
client_id: "myclientid"
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
oauth2:
client_id: "myclient"
client_secret: "mysecret"
client_secret_file: "mysecret"

0 comments on commit dd23553

Please sign in to comment.