Rename exchange code to code, document as authorization code.

This commit is contained in:
Burcu Dogan 2014-08-16 19:29:11 -07:00
parent ee77246177
commit 3a5e8819eb
2 changed files with 12 additions and 12 deletions

View File

@ -31,15 +31,15 @@ func Example_config() {
url := conf.AuthCodeURL("") url := conf.AuthCodeURL("")
fmt.Printf("Visit the URL for the auth dialog: %v", url) fmt.Printf("Visit the URL for the auth dialog: %v", url)
// Use the exchange code that is handled by the redirect URL. // Use the authorization code that is pushed to the redirect URL.
// NewTransportWithCode will do the handshake to retrieve // NewTransportWithCode will do the handshake to retrieve
// an access token and iniate a Transport that is // an access token and initiate a Transport that is
// authorized and authenticated the retrieved token. // authorized and authenticated by the retrieved token.
var exchangeCode string var authorizationCode string
if _, err = fmt.Scan(&exchangeCode); err != nil { if _, err = fmt.Scan(&authorizationCode); err != nil {
log.Fatal(err) log.Fatal(err)
} }
t, err := conf.NewTransportWithCode(exchangeCode) t, err := conf.NewTransportWithCode(authorizationCode)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -154,12 +154,12 @@ func (c *Config) NewTransport() *Transport {
return NewTransport(http.DefaultTransport, c, nil) return NewTransport(http.DefaultTransport, c, nil)
} }
// NewTransportWithCode exchanges the OAuth 2.0 exchange code with // NewTransportWithCode exchanges the OAuth 2.0 authorization code with
// the provider to fetch a new access token (and refresh token). Once // the provider to fetch a new access token (and refresh token). Once
// 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(code string) (*Transport, error) {
token, err := c.Exchange(exchangeCode) token, err := c.Exchange(code)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -191,13 +191,13 @@ func (c *Config) validate() error {
return nil return nil
} }
// Exchange exchanges the exchange code with the OAuth 2.0 provider // Exchange exchanges the authorization code with the OAuth 2.0 provider
// to retrieve a new access token. // to retrieve a new access token.
func (c *Config) Exchange(exchangeCode string) (*Token, error) { func (c *Config) Exchange(code string) (*Token, error) {
vals := url.Values{ vals := url.Values{
"grant_type": {"authorization_code"}, "grant_type": {"authorization_code"},
"client_secret": {c.opts.ClientSecret}, "client_secret": {c.opts.ClientSecret},
"code": {exchangeCode}, "code": {code},
} }
if len(c.opts.Scopes) != 0 { if len(c.opts.Scopes) != 0 {
vals.Set("scope", strings.Join(c.opts.Scopes, " ")) vals.Set("scope", strings.Join(c.opts.Scopes, " "))