oauth2, oauth2/google: add, use ReuseTokenSource

Token caching is now done whenever you make a Client, and
ReuseTokenSource is exported from the oauth2 package and used by the
Google TokenSources (Compute and App Engine).

Token.Expired is now Token.Valid, and works on nil receivers.

Some other wording cleanups in the process.

All tests pass. App Engine should pass, but is untested.

Change-Id: Ibe1d2599ac3ccfe9b399b1672f74bb24cfc8d311
Reviewed-on: https://go-review.googlesource.com/2195
Reviewed-by: Burcu Dogan <jbd@google.com>
This commit is contained in:
Brad Fitzpatrick
2014-12-30 13:25:01 -08:00
parent e5909d4679
commit a379e41d44
10 changed files with 97 additions and 68 deletions

View File

@@ -32,10 +32,10 @@ func TestTransportTokenSource(t *testing.T) {
client.Get(server.URL)
}
func TestExpiredWithNoAccessToken(t *testing.T) {
func TestTokenValidNoAccessToken(t *testing.T) {
token := &Token{}
if !token.Expired() {
t.Errorf("Token should be expired if no access token is provided")
if token.Valid() {
t.Errorf("Token should not be valid with no access token")
}
}
@@ -43,8 +43,8 @@ func TestExpiredWithExpiry(t *testing.T) {
token := &Token{
Expiry: time.Now().Add(-5 * time.Hour),
}
if !token.Expired() {
t.Errorf("Token should be expired if no access token is provided")
if token.Valid() {
t.Errorf("Token should not be valid if it expired in the past")
}
}