forked from remote/oauth2
oauth2: perform caching ops at the transport level
This commit is contained in:
16
oauth2.go
16
oauth2.go
@@ -64,8 +64,6 @@ type TokenFetcher interface {
|
||||
// If the implementation doesn't know how to retrieve a new token,
|
||||
// it returns an error.
|
||||
FetchToken(existing *Token) (*Token, error)
|
||||
// Cache returns the Cache implementation to read/persist user tokens.
|
||||
Cache() Cache
|
||||
}
|
||||
|
||||
// Options represents options to provide OAuth 2.0 client credentials
|
||||
@@ -130,8 +128,6 @@ type Config struct {
|
||||
authURL string
|
||||
// TokenURL is the URL used to retrieve OAuth tokens.
|
||||
tokenURL string
|
||||
|
||||
cache Cache
|
||||
}
|
||||
|
||||
// AuthCodeURL returns a URL to OAuth 2.0 provider's consent page
|
||||
@@ -187,12 +183,7 @@ func (c *Config) NewTransportWithCode(exchangeCode string) (Transport, error) {
|
||||
// token from the provided cache. If a token refreshing occurs, it
|
||||
// writes the newly fetched token back to the cache.
|
||||
func (c *Config) NewTransportWithCache(cache Cache) (Transport, error) {
|
||||
token, err := cache.Read()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.cache = cache
|
||||
return NewAuthorizedTransport(c, token), nil
|
||||
return NewAuthorizedTransportWithCache(c, cache)
|
||||
}
|
||||
|
||||
// Exchange exchanges the exchange code with the OAuth 2.0 provider
|
||||
@@ -225,11 +216,6 @@ func (c *Config) FetchToken(existing *Token) (*Token, error) {
|
||||
return existing, err
|
||||
}
|
||||
|
||||
// Cache returns a cache if specified, otherwise nil.
|
||||
func (c *Config) Cache() Cache {
|
||||
return c.cache
|
||||
}
|
||||
|
||||
// Checks if all required configuration fields have non-zero values.
|
||||
func (c *Config) validate() error {
|
||||
if c.opts.ClientID == "" {
|
||||
|
||||
Reference in New Issue
Block a user