JWTConfig should provide a cached transport constructor.

This commit is contained in:
Burcu Dogan 2014-05-26 15:20:26 +02:00
parent 58513eb0ea
commit c376bb1dac
1 changed files with 9 additions and 0 deletions

9
jwt.go
View File

@ -76,6 +76,15 @@ func (c *JWTConfig) NewTransportWithUser(user string) Transport {
return NewAuthorizedTransport(c, &Token{Subject: user}) return NewAuthorizedTransport(c, &Token{Subject: user})
} }
func (c *JWTConfig) NewTransportWithCache(cache Cache) (Transport, error) {
token, err := cache.Read()
if err != nil {
return nil, err
}
c.cache = cache
return NewAuthorizedTransport(c, token), nil
}
// fetchToken retrieves a new access token and updates the existing token // fetchToken retrieves a new access token and updates the existing token
// with the newly fetched credentials. // with the newly fetched credentials.
func (c *JWTConfig) FetchToken(existing *Token) (token *Token, err error) { func (c *JWTConfig) FetchToken(existing *Token) (token *Token, err error) {