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 {