From f088706217d0f51a8ed30f73791e3b3aebce5fda Mon Sep 17 00:00:00 2001 From: Preston Baxter Date: Tue, 14 Nov 2023 12:55:20 -0600 Subject: [PATCH] add RefreshToken Method --- oauth2.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/oauth2.go b/oauth2.go index bcefc11..df17194 100644 --- a/oauth2.go +++ b/oauth2.go @@ -291,6 +291,19 @@ func (tf *TokenRefresher) Token() (*Token, error) { return tk, err } +func RefreshToken(ctx context.Context, conf *Config, refreshToken string) (*Token, error) { + if refreshToken == "" { + return nil, errors.New("oauth2: token expired and refresh token is not set") + } + + tk, err := retrieveToken(ctx, conf, url.Values{ + "grant_type": {"refresh_token"}, + "refresh_token": {refreshToken}, + }) + + return tk, err +} + // tokenRefresher is a TokenSource that makes "grant_type"=="refresh_token" // HTTP requests to renew a token using a RefreshToken. type tokenRefresher struct {