Skip to content

Commit

Permalink
oauth: if a client is unconfigured return the error in place, no temp…
Browse files Browse the repository at this point in the history
…late error
  • Loading branch information
martinrode committed Jul 30, 2021
1 parent 25bd527 commit 5215d26
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/lib/template/oauth2_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type oAuth2TokenExtended struct {

// ReadOAuthReturnValue checks the return values from an OAUTH client and
// stores the error in an extended struct of the oAuth token
func readOAuthReturnValue(t *oauth2.Token, err error) (tE oAuth2TokenExtended, err2 error) {
func readOAuthReturnValue(t *oauth2.Token, err error) (tE oAuth2TokenExtended) {
if t == nil {
t = &oauth2.Token{} // Make sure we have "AccessToken" in our struct
}
Expand All @@ -30,5 +30,5 @@ func readOAuthReturnValue(t *oauth2.Token, err error) (tE oAuth2TokenExtended, e
}
}
}
return tE, err
return tE
}
16 changes: 8 additions & 8 deletions pkg/lib/template/template_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,35 +370,35 @@ func (loader *Loader) Render(
}
return reflect.ValueOf(v).IsZero()
},
"oauth2_password_token": func(client string, login string, password string) (tE oAuth2TokenExtended, err error) {
"oauth2_password_token": func(client string, login string, password string) (tE oAuth2TokenExtended) {
oAuthClient, ok := loader.OAuthClient[client]
if !ok {
return tE, errors.Errorf("OAuth client %s not configured", client)
return readOAuthReturnValue(nil, errors.Errorf("OAuth client %q not configured", client))
}
oAuthClient.Client = client
return readOAuthReturnValue(oAuthClient.GetPasswordCredentialsAuthToken(login, password))

},
"oauth2_client_token": func(client string) (tE oAuth2TokenExtended, err error) {
"oauth2_client_token": func(client string) (tE oAuth2TokenExtended) {
oAuthClient, ok := loader.OAuthClient[client]
if !ok {
return tE, errors.Errorf("OAuth client %s not configured", client)
return readOAuthReturnValue(nil, errors.Errorf("OAuth client %q not configured", client))
}
oAuthClient.Client = client
return readOAuthReturnValue(oAuthClient.GetClientCredentialsAuthToken())
},
"oauth2_code_token": func(client string, params ...string) (tE oAuth2TokenExtended, err error) {
"oauth2_code_token": func(client string, params ...string) (tE oAuth2TokenExtended) {
oAuthClient, ok := loader.OAuthClient[client]
if !ok {
return tE, errors.Errorf("OAuth client %s not configured", client)
return readOAuthReturnValue(nil, errors.Errorf("OAuth client %q not configured", client))
}
oAuthClient.Client = client
return readOAuthReturnValue(oAuthClient.GetCodeAuthToken(params...))
},
"oauth2_implicit_token": func(client string, params ...string) (tE oAuth2TokenExtended, err error) {
"oauth2_implicit_token": func(client string, params ...string) (tE oAuth2TokenExtended) {
oAuthClient, ok := loader.OAuthClient[client]
if !ok {
return tE, errors.Errorf("OAuth client %s not configured", client)
return readOAuthReturnValue(nil, errors.Errorf("OAuth client %q not configured", client))
}
oAuthClient.Client = client
return readOAuthReturnValue(oAuthClient.GetAuthToken(params...))
Expand Down

0 comments on commit 5215d26

Please sign in to comment.