Skip to content

Commit

Permalink
use switch instead if
Browse files Browse the repository at this point in the history
  • Loading branch information
zetaab committed Apr 6, 2024
1 parent b318eac commit 0047888
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ func (c *fileTokenSource) Token() (*oauth2.Token, error) {
}

var tk *oauth2.Token
if c.style == authStyleNotKnown || c.style == authStyleInHeader {

switch {
case c.style == authStyleNotKnown, c.style == authStyleInHeader:
tk, err = retrieveToken(c.ctx, c.conf.TokenURL, c.conf.ClientID, string(content), v, authStyleInHeader)
if err == nil {
c.style = authStyleInHeader
Expand All @@ -86,7 +88,7 @@ func (c *fileTokenSource) Token() (*oauth2.Token, error) {
return tk, nil
}
}
} else if c.style == authStyleInParams {
case c.style == authStyleInParams:
tk, err = retrieveToken(c.ctx, c.conf.TokenURL, c.conf.ClientID, string(content), v, authStyleInParams)
if err == nil {
c.style = authStyleInParams
Expand All @@ -108,7 +110,7 @@ func buildHeadersAndBody(clientID, clientSecret string, v url.Values, style auth
"Content-Type": "application/x-www-form-urlencoded",
}
switch style {
case authStyleInHeader:
case authStyleInHeader, authStyleNotKnown:
headers["Authorization"] = "Basic " + BasicAuth(url.QueryEscape(clientID), url.QueryEscape(clientSecret))
case authStyleInParams:
v.Set("client_id", clientID)
Expand Down

0 comments on commit 0047888

Please sign in to comment.