Skip to content

Commit

Permalink
oauth2: added improved error handling if pw is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrode committed Jul 5, 2023
1 parent 75869f7 commit 69bab04
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/lib/util/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"net/url"
"time"

"log"

"github.com/pkg/errors"
"golang.org/x/oauth2"
"golang.org/x/oauth2/clientcredentials"
Expand Down Expand Up @@ -52,8 +54,13 @@ func getOAuthClientCredentialsConfig(c OAuthClientConfig) clientcredentials.Conf

// GetPasswordCredentialsAuthToken sends request to oAuth token endpoint
// to get a token on behalf of a user
func (c OAuthClientConfig) GetPasswordCredentialsAuthToken(username string, password string) (*oauth2.Token, error) {
func (c OAuthClientConfig) GetPasswordCredentialsAuthToken(username string, password string) (tok *oauth2.Token, err error) {
cfg := getOAuthClientConfig(c)
defer func() {
if err != nil {
log.Printf("oauth2 password error: %s client: %s secret: %s", err.Error(), cfg.ClientID, cfg.ClientSecret)
}
}()
httpClient := &http.Client{Timeout: 60 * time.Second}
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, httpClient)
return cfg.PasswordCredentialsToken(ctx, username, password)
Expand Down

0 comments on commit 69bab04

Please sign in to comment.