oauth2: don't use http.DefaultTransport.
http.DefaultTransport is not available on App Engine.
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/golang/oauth2"
|
||||
|
||||
"appengine"
|
||||
"appengine/urlfetch"
|
||||
)
|
||||
|
||||
// AppEngineConfig represents a configuration for an
|
||||
@@ -26,7 +27,12 @@ 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.NewAuthorizedTransport(c, nil)
|
||||
transport := &urlfetch.Transport{
|
||||
Context: c.context,
|
||||
Deadline: 0,
|
||||
AllowInvalidServerCertificate: false,
|
||||
}
|
||||
return oauth2.NewAuthorizedTransport(transport, c, nil)
|
||||
}
|
||||
|
||||
// FetchToken fetches a new access token for the provided scopes.
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package google
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/oauth2"
|
||||
@@ -25,7 +26,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.NewAuthorizedTransport(c, nil)
|
||||
return oauth2.NewAuthorizedTransport(http.DefaultTransport, c, nil)
|
||||
}
|
||||
|
||||
// FetchToken fetches a new access token for the provided scopes.
|
||||
|
||||
@@ -61,7 +61,7 @@ func NewComputeEngineConfig(account string) *ComputeEngineConfig {
|
||||
|
||||
// NewTransport creates an authorized transport.
|
||||
func (c *ComputeEngineConfig) NewTransport() oauth2.Transport {
|
||||
return oauth2.NewAuthorizedTransport(c, nil)
|
||||
return oauth2.NewAuthorizedTransport(http.DefaultTransport, c, nil)
|
||||
}
|
||||
|
||||
// FetchToken retrieves a new access token via metadata server.
|
||||
@@ -76,7 +76,7 @@ func (c *ComputeEngineConfig) FetchToken(existing *oauth2.Token) (token *oauth2.
|
||||
return
|
||||
}
|
||||
req.Header.Add("X-Google-Metadata-Request", "True")
|
||||
resp, err := (&http.Client{Transport: oauth2.DefaultTransport}).Do(req)
|
||||
resp, err := (&http.Client{}).Do(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user