Skip to content

Commit 93ad3f4

Browse files
committed
remove cache
1 parent e62c791 commit 93ad3f4

11 files changed

+10
-262
lines changed

Diff for: cache.go

-55
This file was deleted.

Diff for: cache_test.go

-74
This file was deleted.

Diff for: example_test.go

-31
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,6 @@ func Example_config() {
5151
// start making authenticated requests.
5252
client := http.Client{Transport: t}
5353
client.Get("...")
54-
55-
// Alternatively, you can initiate a new transport
56-
// with tokens from a cache.
57-
cache := oauth2.NewFileCache("/path/to/file")
58-
// NewTransportWithCache will try to read the cached
59-
// token, if any error occurs, it returns the error.
60-
// If a token is available at the cache, initiates
61-
// a new transport authorized and authenticated with
62-
// the read token. If token expires, and a new access
63-
// token is retrieved, it writes the newly fetched
64-
// token to the cache.
65-
t, err = conf.NewTransportWithCache(cache)
66-
if err != nil {
67-
log.Fatal(err)
68-
}
69-
client = http.Client{Transport: t}
70-
client.Get("...")
7154
}
7255

7356
func Example_jWTConfig() {
@@ -95,18 +78,4 @@ func Example_jWTConfig() {
9578
// request will be made on the behalf of [email protected].
9679
client = http.Client{Transport: conf.NewTransportWithUser("[email protected]")}
9780
client.Get("...")
98-
99-
// Alternatively you can iniate a transport with
100-
// a token read from the cache.
101-
// If the existing access token expires, and a new access token is
102-
// retrieved, the newly fetched token will be written to the cache.
103-
cache := oauth2.NewFileCache("/path/to/file")
104-
t, err := conf.NewTransportWithCache(cache)
105-
if err != nil {
106-
log.Fatal(err)
107-
}
108-
client = http.Client{Transport: t}
109-
// The following request will be authorized by the token
110-
// retrieved from the cache.
111-
client.Get("...")
11281
}

Diff for: google/appengine.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ package google
55
import (
66
"strings"
77

8-
"appengine"
98
"github.com/golang/oauth2"
9+
10+
"appengine"
1011
)
1112

1213
// AppEngineConfig represents a configuration for an
@@ -28,12 +29,6 @@ func (c *AppEngineConfig) NewTransport() oauth2.Transport {
2829
return oauth2.NewAuthorizedTransport(c, nil)
2930
}
3031

31-
// NewTransport returns a token-caching transport that authorizes
32-
// the requests with the application's service account.
33-
func (c *AppEngineConfig) NewTransportWithCache(cache oauth2.Cache) (oauth2.Transport, error) {
34-
return oauth2.NewAuthorizedTransportWithCache(c, cache)
35-
}
36-
3732
// FetchToken fetches a new access token for the provided scopes.
3833
func (c *AppEngineConfig) FetchToken(existing *oauth2.Token) (*oauth2.Token, error) {
3934
token, expiry, err := appengine.AccessToken(c.context, strings.Join(c.scopes, " "))

Diff for: google/appenginevm.go

-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
type AppEngineConfig struct {
1515
context appengine.Context
1616
scopes []string
17-
cache oauth2.Cache
1817
}
1918

2019
// NewAppEngineConfig creates a new AppEngineConfig for the
@@ -29,12 +28,6 @@ func (c *AppEngineConfig) NewTransport() oauth2.Transport {
2928
return oauth2.NewAuthorizedTransport(c, nil)
3029
}
3130

32-
// NewTransport returns a token-caching transport that authorizes
33-
// the requests with the application's service account.
34-
func (c *AppEngineConfig) NewTransportWithCache(cache oauth2.Cache) (oauth2.Transport, error) {
35-
return oauth2.NewAuthorizedTransportWithCache(c, cache)
36-
}
37-
3831
// FetchToken fetches a new access token for the provided scopes.
3932
func (c *AppEngineConfig) FetchToken(existing *oauth2.Token) (*oauth2.Token, error) {
4033
token, expiry, err := appengine.AccessToken(c.context, strings.Join(c.scopes, " "))

Diff for: google/example_test.go

-31
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,6 @@ func Example_webServer() {
4545
}
4646
client := http.Client{Transport: t}
4747
client.Get("...")
48-
49-
// Alternatively you can initiate a new transport
50-
// with a token from a cache.
51-
cache := oauth2.NewFileCache("/path/to/file")
52-
// NewTransportWithCache will try to read the cached
53-
// token, if any error occurs, it returns the error.
54-
// If a token is available at the cache, initiates
55-
// a new transport authorized and authenticated with
56-
// the read token. If token expires, and a new access
57-
// token is retrieved, it writes the newly fetched
58-
// token to the cache.
59-
t, err = config.NewTransportWithCache(cache)
60-
if err != nil {
61-
log.Fatal(err)
62-
}
63-
client = http.Client{Transport: t}
64-
client.Get("...")
6548
}
6649

6750
func Example_serviceAccounts() {
@@ -92,20 +75,6 @@ func Example_serviceAccounts() {
9275
// request will be made on the behalf of [email protected].
9376
client = http.Client{Transport: config.NewTransportWithUser("[email protected]")}
9477
client.Get("...")
95-
96-
// Alternatively you can iniate a transport with
97-
// a token read from the cache.
98-
// If the existing access token expires, and a new access token is
99-
// retrieved, the newly fetched token will be written to the cache.
100-
cache := oauth2.NewFileCache("/path/to/file")
101-
t, err := config.NewTransportWithCache(cache)
102-
if err != nil {
103-
log.Fatal(err)
104-
}
105-
client = http.Client{Transport: t}
106-
// The following request will be authorized by the token
107-
// retrieved from the cache.
108-
client.Get("...")
10978
}
11079

11180
func Example_appEngine() {

Diff for: jwt.go

-7
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ func (c *JWTConfig) NewTransportWithUser(user string) Transport {
7070
return NewAuthorizedTransport(c, &Token{Subject: user})
7171
}
7272

73-
// NewTransportWithCache initializes a transport by reading the initial
74-
// token from the provided cache. If a token refreshing occurs, it
75-
// writes the newly fetched token back to the cache.
76-
func (c *JWTConfig) NewTransportWithCache(cache Cache) (Transport, error) {
77-
return NewAuthorizedTransportWithCache(c, cache)
78-
}
79-
8073
// fetchToken retrieves a new access token and updates the existing token
8174
// with the newly fetched credentials.
8275
func (c *JWTConfig) FetchToken(existing *Token) (token *Token, err error) {

Diff for: oauth2.go

-7
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,6 @@ func (c *Config) NewTransportWithCode(exchangeCode string) (Transport, error) {
153153
return NewAuthorizedTransport(c, token), nil
154154
}
155155

156-
// NewTransportWithCache initializes a transport by reading the initial
157-
// token from the provided cache. If a token refreshing occurs, it
158-
// writes the newly fetched token back to the cache.
159-
func (c *Config) NewTransportWithCache(cache Cache) (Transport, error) {
160-
return NewAuthorizedTransportWithCache(c, cache)
161-
}
162-
163156
// FetchToken retrieves a new access token and updates the existing token
164157
// with the newly fetched credentials. If existing token doesn't
165158
// contain a refresh token, it returns an error.

Diff for: oauth2_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestExchangePayload(t *testing.T) {
6262
return nil, errors.New("no response")
6363
},
6464
}
65-
conf.Exchange("exchange-code")
65+
conf.exchange("exchange-code")
6666
}
6767

6868
func TestExchangingTransport(t *testing.T) {

Diff for: transport.go

-19
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ type Transport interface {
7676
}
7777

7878
type authorizedTransport struct {
79-
// Cache to persist changes to the token that
80-
// authorizes the current transport.
81-
cache Cache
8279
fetcher TokenFetcher
8380
token *Token
8481

@@ -93,19 +90,6 @@ func NewAuthorizedTransport(fetcher TokenFetcher, token *Token) Transport {
9390
return &authorizedTransport{fetcher: fetcher, token: token}
9491
}
9592

96-
// NewAuthorizedTransportWithCache creates a new transport that uses
97-
// the provided token fetcher and cache. Before constructing the new
98-
// transport, it will try to read from the cache to see if there
99-
// is an existing token.
100-
func NewAuthorizedTransportWithCache(fetcher TokenFetcher, cache Cache) (transport Transport, err error) {
101-
var token *Token
102-
if token, err = cache.Read(); err != nil {
103-
return
104-
}
105-
transport = &authorizedTransport{fetcher: fetcher, cache: cache, token: token}
106-
return
107-
}
108-
10993
// RoundTrip authorizes the request with the existing token.
11094
// If token is expired, tries to refresh/fetch a new token.
11195
func (t *authorizedTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
@@ -176,9 +160,6 @@ func (t *authorizedTransport) RefreshToken() error {
176160
}
177161

178162
t.token = token
179-
if t.cache != nil {
180-
return t.cache.Write(token)
181-
}
182163

183164
return nil
184165
}

0 commit comments

Comments
 (0)