Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(666)

Unified Diff: oauth2.go

Issue 102640047: oauth2: avoid exporting Exchange, use NewTransportWithCode.
Patch Set: Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: oauth2.go
diff --git a/oauth2.go b/oauth2.go
index b87de7d66233ee258b7d656b92aa899aa6b4127c..edfd75de35c095098ca376c991cb0cfcafb18ce5 100644
--- a/oauth2.go
+++ b/oauth2.go
@@ -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)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b