forked from Mirrors/oauth2
add RefreshToken Method
This commit is contained in:
parent
d87fd3250e
commit
f088706217
13
oauth2.go
13
oauth2.go
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue