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("")
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
// an access token and iniate a Transport that is
// authorized and authenticated the retrieved token.
var exchangeCode string
if _, err = fmt.Scan(&exchangeCode); err != nil {
// an access token and initiate a Transport that is
// authorized and authenticated by the retrieved token.
var authorizationCode string
if _, err = fmt.Scan(&authorizationCode); err != nil {
log.Fatal(err)
}
t, err := conf.NewTransportWithCode(exchangeCode)
t, err := conf.NewTransportWithCode(authorizationCode)
if err != nil {
log.Fatal(err)
}

View File

@ -154,12 +154,12 @@ func (c *Config) NewTransport() *Transport {
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
// 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)
func (c *Config) NewTransportWithCode(code string) (*Transport, error) {
token, err := c.Exchange(code)
if err != nil {
return nil, err
}
@ -191,13 +191,13 @@ func (c *Config) validate() error {
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.
func (c *Config) Exchange(exchangeCode string) (*Token, error) {
func (c *Config) Exchange(code string) (*Token, error) {
vals := url.Values{
"grant_type": {"authorization_code"},
"client_secret": {c.opts.ClientSecret},
"code": {exchangeCode},
"code": {code},
}
if len(c.opts.Scopes) != 0 {
vals.Set("scope", strings.Join(c.opts.Scopes, " "))