Dont export exchange.

This commit is contained in:
Burcu Dogan 2014-06-26 17:27:53 -07:00
parent ad322e7e30
commit de1f5a349e
1 changed files with 17 additions and 17 deletions

View File

@ -172,7 +172,7 @@ func (c *Config) NewTransport() Transport {
// it succesffully retrieves a new token, creates a new transport
// authorized with it.
func (c *Config) NewTransportWithCode(exchangeCode string) (Transport, error) {
token, err := c.Exchange(exchangeCode)
token, err := c.exchange(exchangeCode)
if err != nil {
return nil, err
}
@ -186,22 +186,6 @@ func (c *Config) NewTransportWithCache(cache Cache) (Transport, error) {
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
// with the newly fetched credentials. If existing token doesn't
// contain a refresh token, it returns an error.
@ -240,6 +224,22 @@ func (c *Config) validate() error {
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 {
v.Set("client_id", c.opts.ClientID)
v.Set("client_secret", c.opts.ClientSecret)