-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make OAuth 2.0 client_id and client_secret mandatory #294
Make OAuth 2.0 client_id and client_secret mandatory #294
Conversation
Signed-off-by: Levi Harrison <git@leviharrison.dev>
dd23553
to
e5fed51
Compare
config/http_config.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generally use == 0 to check this.
Can we have 2 distincts errors? This would be more readable and more direct for the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need the token url mandatory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks,
token URL is also mandatory.
Signed-off-by: Levi Harrison <git@leviharrison.dev>
Whoops, that too. Thanks! |
config/http_config.go
Outdated
@@ -210,6 +210,12 @@ 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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that I would still prefer to use == 0 like elsewhere and have 2 different errors for better readability.
config/http_config.go
Outdated
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.TokenURL) < 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if len(c.OAuth2.TokenURL) < 1 { | |
if len(c.OAuth2.TokenURL) == 0 { |
Signed-off-by: Levi Harrison <git@leviharrison.dev>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Final nits to be consistent with the other error messages. After this is changed I will merge and release 0.23.0
config/http_config.go
Outdated
return fmt.Errorf("the oauth2 client_id must be configured") | ||
} | ||
if len(c.OAuth2.ClientSecret) == 0 && len(c.OAuth2.ClientSecretFile) == 0 { | ||
return fmt.Errorf("either the oauth2 client_secret or client_secret_file must be configured") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return fmt.Errorf("either the oauth2 client_secret or client_secret_file must be configured") | |
return fmt.Errorf("either oauth2 client_secret or client_secret_file must be configured") |
config/http_config.go
Outdated
return fmt.Errorf("either the oauth2 client_secret or client_secret_file must be configured") | ||
} | ||
if len(c.OAuth2.TokenURL) == 0 { | ||
return fmt.Errorf("the oauth2 token_url must be configured") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return fmt.Errorf("the oauth2 token_url must be configured") | |
return fmt.Errorf("oauth2 token_url must be configured") |
config/http_config.go
Outdated
@@ -210,6 +210,15 @@ 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) == 0 { | |||
return fmt.Errorf("the oauth2 client_id must be configured") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return fmt.Errorf("the oauth2 client_id must be configured") | |
return fmt.Errorf("oauth2 client_id must be configured") |
Signed-off-by: Levi Harrison <git@leviharrison.dev>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!!!
These should be mandatory as per the spec.
cc @roidelapluie