Skip to content

Commit

Permalink
add oauth2 token renewal
Browse files Browse the repository at this point in the history
  • Loading branch information
vsychov committed Jan 10, 2025
1 parent aeaee0f commit 789ceca
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion oauthhelper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Auth struct {
ClientID string
ClientSecret string
Authenticate AuthenticateFunc
TokenFile string
}

// NewHTTPClient instantiates a new authentication client
Expand Down Expand Up @@ -55,7 +56,19 @@ func (auth *Auth) NewHTTPClient(ctx context.Context, scopes ...string) (*http.Cl
}
}

return config.Client(ctx, auth.Token), nil
ts := config.TokenSource(ctx, auth.Token)
newToken, err := ts.Token()
if err != nil {
return nil, err
}

auth.Token = newToken
err = StoreTokenToFile(auth.TokenFile, auth.Token)
if err != nil {
return nil, err
}

return oauth2.NewClient(ctx, ts), nil
}

func (auth *Auth) getTokenFromWeb(config *oauth2.Config) (*oauth2.Token, error) {
Expand Down

0 comments on commit 789ceca

Please sign in to comment.