forked from Mirrors/oauth2
Dont export exchange.
This commit is contained in:
parent
ad322e7e30
commit
de1f5a349e
34
oauth2.go
34
oauth2.go
|
@ -172,7 +172,7 @@ func (c *Config) NewTransport() Transport {
|
||||||
// it succesffully retrieves a new token, creates a new transport
|
// it succesffully retrieves a new token, creates a new transport
|
||||||
// authorized with it.
|
// authorized with it.
|
||||||
func (c *Config) NewTransportWithCode(exchangeCode string) (Transport, error) {
|
func (c *Config) NewTransportWithCode(exchangeCode string) (Transport, error) {
|
||||||
token, err := c.Exchange(exchangeCode)
|
token, err := c.exchange(exchangeCode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -186,22 +186,6 @@ func (c *Config) NewTransportWithCache(cache Cache) (Transport, error) {
|
||||||
return NewAuthorizedTransportWithCache(c, cache)
|
return NewAuthorizedTransportWithCache(c, cache)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exchange exchanges the exchange code with the OAuth 2.0 provider
|
|
||||||
// to retrieve a new access token.
|
|
||||||
func (c *Config) Exchange(exchangeCode string) (*Token, error) {
|
|
||||||
token := &Token{}
|
|
||||||
err := c.updateToken(token, url.Values{
|
|
||||||
"grant_type": {"authorization_code"},
|
|
||||||
"redirect_uri": {c.opts.RedirectURL},
|
|
||||||
"scope": {strings.Join(c.opts.Scopes, " ")},
|
|
||||||
"code": {exchangeCode},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return token, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// FetchToken retrieves a new access token and updates the existing token
|
// FetchToken retrieves a new access token and updates the existing token
|
||||||
// with the newly fetched credentials. If existing token doesn't
|
// with the newly fetched credentials. If existing token doesn't
|
||||||
// contain a refresh token, it returns an error.
|
// contain a refresh token, it returns an error.
|
||||||
|
@ -240,6 +224,22 @@ func (c *Config) validate() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exchange exchanges the exchange code with the OAuth 2.0 provider
|
||||||
|
// to retrieve a new access token.
|
||||||
|
func (c *Config) exchange(exchangeCode string) (*Token, error) {
|
||||||
|
token := &Token{}
|
||||||
|
err := c.updateToken(token, url.Values{
|
||||||
|
"grant_type": {"authorization_code"},
|
||||||
|
"redirect_uri": {c.opts.RedirectURL},
|
||||||
|
"scope": {strings.Join(c.opts.Scopes, " ")},
|
||||||
|
"code": {exchangeCode},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return token, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Config) updateToken(tok *Token, v url.Values) error {
|
func (c *Config) updateToken(tok *Token, v url.Values) error {
|
||||||
v.Set("client_id", c.opts.ClientID)
|
v.Set("client_id", c.opts.ClientID)
|
||||||
v.Set("client_secret", c.opts.ClientSecret)
|
v.Set("client_secret", c.opts.ClientSecret)
|
||||||
|
|
Loading…
Reference in New Issue