add RefreshToken Method

This commit is contained in:
Preston Baxter 2023-11-14 12:55:20 -06:00
parent d87fd3250e
commit f088706217
1 changed files with 13 additions and 0 deletions

View File

@ -291,6 +291,19 @@ func (tf *TokenRefresher) Token() (*Token, error) {
return tk, err 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" // tokenRefresher is a TokenSource that makes "grant_type"=="refresh_token"
// HTTP requests to renew a token using a RefreshToken. // HTTP requests to renew a token using a RefreshToken.
type tokenRefresher struct { type tokenRefresher struct {