oauth2: add StaticTokenSource to return static tokens

Fixes #120

Change-Id: I2ef0cbf87c7124b89a68b5db0080f916c630072d
Reviewed-on: https://go-review.googlesource.com/9895
Reviewed-by: Burcu Dogan <jbd@google.com>
This commit is contained in:
Will Norris 2015-05-08 14:14:37 -07:00 committed by Brad Fitzpatrick
parent 2159a45684
commit e296c42d12
1 changed files with 16 additions and 0 deletions

View File

@ -253,6 +253,22 @@ func (s *reuseTokenSource) Token() (*Token, error) {
return t, nil
}
// StaticTokenSource returns a TokenSource that always returns the same token.
// Because the provided token t is never refreshed, StaticTokenSource is only
// useful for tokens that never expire.
func StaticTokenSource(t *Token) TokenSource {
return staticTokenSource{t}
}
// staticTokenSource is a TokenSource that always returns the same Token.
type staticTokenSource struct {
t *Token
}
func (s staticTokenSource) Token() (*Token, error) {
return s.t, nil
}
// HTTPClient is the context key to use with golang.org/x/net/context's
// WithValue function to associate an *http.Client value with a context.
var HTTPClient internal.ContextKey