forked from remote/oauth2
Do not assume that http.DefaultClient and http.DefaultTransport is always available.
This commit is contained in:
@@ -12,31 +12,32 @@ import (
|
||||
// AppEngineConfig represents a configuration for an
|
||||
// App Engine application's Google service account.
|
||||
type AppEngineConfig struct {
|
||||
// Default transport to be used while constructing
|
||||
// Transport represents the default transport to be used while constructing
|
||||
// oauth2.Transport instances from this configuration.
|
||||
Transport *urlfetch.Transport
|
||||
context appengine.Context
|
||||
scopes []string
|
||||
|
||||
context appengine.Context
|
||||
scopes []string
|
||||
}
|
||||
|
||||
// NewAppEngineConfig creates a new AppEngineConfig for the
|
||||
// provided auth scopes.
|
||||
func NewAppEngineConfig(context appengine.Context, scopes []string) *AppEngineConfig {
|
||||
return &AppEngineConfig{context: context, scopes: scopes}
|
||||
return &AppEngineConfig{
|
||||
Transport: &urlfetch.Transport{
|
||||
Context: context,
|
||||
Deadline: 0,
|
||||
AllowInvalidServerCertificate: false,
|
||||
},
|
||||
context: context,
|
||||
scopes: scopes,
|
||||
}
|
||||
}
|
||||
|
||||
// NewTransport returns a transport that authorizes
|
||||
// the requests with the application's service account.
|
||||
func (c *AppEngineConfig) NewTransport() *oauth2.Transport {
|
||||
if c.Transport != nil {
|
||||
return oauth2.NewTransport(c.Transport, c, nil)
|
||||
}
|
||||
transport := &urlfetch.Transport{
|
||||
Context: c.context,
|
||||
Deadline: 0,
|
||||
AllowInvalidServerCertificate: false,
|
||||
}
|
||||
return oauth2.NewTransport(transport, c, nil)
|
||||
return oauth2.NewTransport(c.Transport, c, nil)
|
||||
}
|
||||
|
||||
// FetchToken fetches a new access token for the provided scopes.
|
||||
|
||||
Reference in New Issue
Block a user