forked from remote/oauth2
Allow configs to be initialised with zero values for Client and Transport.
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
package google
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/golang/oauth2"
|
||||
|
||||
"appengine"
|
||||
@@ -25,11 +27,6 @@ type AppEngineConfig struct {
|
||||
// provided auth scopes.
|
||||
func NewAppEngineConfig(context appengine.Context, scopes []string) *AppEngineConfig {
|
||||
return &AppEngineConfig{
|
||||
Transport: &urlfetch.Transport{
|
||||
Context: context,
|
||||
Deadline: 0,
|
||||
AllowInvalidServerCertificate: false,
|
||||
},
|
||||
context: context,
|
||||
scopes: scopes,
|
||||
}
|
||||
@@ -38,7 +35,7 @@ func NewAppEngineConfig(context appengine.Context, scopes []string) *AppEngineCo
|
||||
// NewTransport returns a transport that authorizes
|
||||
// the requests with the application's service account.
|
||||
func (c *AppEngineConfig) NewTransport() *oauth2.Transport {
|
||||
return oauth2.NewTransport(c.Transport, c, nil)
|
||||
return oauth2.NewTransport(c.transport(), c, nil)
|
||||
}
|
||||
|
||||
// FetchToken fetches a new access token for the provided scopes.
|
||||
@@ -52,3 +49,10 @@ func (c *AppEngineConfig) FetchToken(existing *oauth2.Token) (*oauth2.Token, err
|
||||
Expiry: expiry,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *AppEngineConfig) transport() http.RoundTripper {
|
||||
if c.Transport != nil {
|
||||
return c.Transport
|
||||
}
|
||||
return &urlfetch.Transport{Context: c.context}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user