Skip to content

Commit

Permalink
🚸 Refresh token if expired
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenWaygate committed Mar 24, 2024
1 parent 2e3928c commit 4077905
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ func getClient(ctx context.Context, scope string) *http.Client {
cacheFile := tokenCacheFile(scope)

token, err := tokenFromFile(cacheFile)
if err != nil || !token.Valid() {
if err != nil {
return newClient(ctx, config, cacheFile)
} else if !token.Valid() {
tokenSource := config.TokenSource(ctx, token)
token, err = tokenSource.Token()
if err != nil {
return newClient(ctx, config, cacheFile)
}
}

return config.Client(ctx, token)
Expand Down

0 comments on commit 4077905

Please # to comment.