Skip to content

Commit

Permalink
chore: fix token refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Jul 27, 2023
1 parent 7c92e0d commit 7d6a391
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions util/oauth/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ func Refresh(log *util.Logger, token *oauth2.Token, ts oauth2.TokenSource, optMa
limitTokenLife(token, optMaxTokenLifetime...)

for range time.Tick(5 * time.Minute) {
if _, err := ts.Token(); err != nil {
t, err := ts.Token()
if err != nil {
failed++
if failed > 5 {
log.ERROR.Printf("token refresh: %v, giving up", err)
return
}

log.ERROR.Printf("token refresh: %v", err)
continue
// get token- either previous or new
t, err := ts.Token()
if err != nil {
// error means refresh failed
failed++
if failed > 5 {
log.ERROR.Printf("token refresh: %v, giving up", err)
return
}

failed = 0
log.ERROR.Printf("token refresh: %v", err)
continue
}

// limit lifetime of new tokens
if t.Expiry != token.Expiry {
token = t
limitTokenLife(token, optMaxTokenLifetime...)
}
failed = 0

// limit lifetime of new tokens
if t.Expiry != token.Expiry {
token = t
limitTokenLife(token, optMaxTokenLifetime...)
}
}
}
Expand Down

0 comments on commit 7d6a391

Please sign in to comment.