remove cache

This commit is contained in:
Johan Euphrosine
2014-07-08 22:27:34 -07:00
parent e62c791d44
commit 93ad3f4a9e
11 changed files with 10 additions and 262 deletions

View File

@@ -5,8 +5,9 @@ package google
import (
"strings"
"appengine"
"github.com/golang/oauth2"
"appengine"
)
// AppEngineConfig represents a configuration for an
@@ -28,12 +29,6 @@ func (c *AppEngineConfig) NewTransport() oauth2.Transport {
return oauth2.NewAuthorizedTransport(c, nil)
}
// NewTransport returns a token-caching transport that authorizes
// the requests with the application's service account.
func (c *AppEngineConfig) NewTransportWithCache(cache oauth2.Cache) (oauth2.Transport, error) {
return oauth2.NewAuthorizedTransportWithCache(c, cache)
}
// FetchToken fetches a new access token for the provided scopes.
func (c *AppEngineConfig) FetchToken(existing *oauth2.Token) (*oauth2.Token, error) {
token, expiry, err := appengine.AccessToken(c.context, strings.Join(c.scopes, " "))

View File

@@ -14,7 +14,6 @@ import (
type AppEngineConfig struct {
context appengine.Context
scopes []string
cache oauth2.Cache
}
// NewAppEngineConfig creates a new AppEngineConfig for the
@@ -29,12 +28,6 @@ func (c *AppEngineConfig) NewTransport() oauth2.Transport {
return oauth2.NewAuthorizedTransport(c, nil)
}
// NewTransport returns a token-caching transport that authorizes
// the requests with the application's service account.
func (c *AppEngineConfig) NewTransportWithCache(cache oauth2.Cache) (oauth2.Transport, error) {
return oauth2.NewAuthorizedTransportWithCache(c, cache)
}
// FetchToken fetches a new access token for the provided scopes.
func (c *AppEngineConfig) FetchToken(existing *oauth2.Token) (*oauth2.Token, error) {
token, expiry, err := appengine.AccessToken(c.context, strings.Join(c.scopes, " "))

View File

@@ -45,23 +45,6 @@ func Example_webServer() {
}
client := http.Client{Transport: t}
client.Get("...")
// Alternatively you can initiate a new transport
// with a token from a cache.
cache := oauth2.NewFileCache("/path/to/file")
// NewTransportWithCache will try to read the cached
// token, if any error occurs, it returns the error.
// If a token is available at the cache, initiates
// a new transport authorized and authenticated with
// the read token. If token expires, and a new access
// token is retrieved, it writes the newly fetched
// token to the cache.
t, err = config.NewTransportWithCache(cache)
if err != nil {
log.Fatal(err)
}
client = http.Client{Transport: t}
client.Get("...")
}
func Example_serviceAccounts() {
@@ -92,20 +75,6 @@ func Example_serviceAccounts() {
// request will be made on the behalf of user@example.com.
client = http.Client{Transport: config.NewTransportWithUser("user@example.com")}
client.Get("...")
// Alternatively you can iniate a transport with
// a token read from the cache.
// If the existing access token expires, and a new access token is
// retrieved, the newly fetched token will be written to the cache.
cache := oauth2.NewFileCache("/path/to/file")
t, err := config.NewTransportWithCache(cache)
if err != nil {
log.Fatal(err)
}
client = http.Client{Transport: t}
// The following request will be authorized by the token
// retrieved from the cache.
client.Get("...")
}
func Example_appEngine() {