forked from Mirrors/oauth2
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:
parent
2159a45684
commit
e296c42d12
16
oauth2.go
16
oauth2.go
|
@ -253,6 +253,22 @@ func (s *reuseTokenSource) Token() (*Token, error) {
|
||||||
return t, nil
|
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
|
// 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.
|
// WithValue function to associate an *http.Client value with a context.
|
||||||
var HTTPClient internal.ContextKey
|
var HTTPClient internal.ContextKey
|
||||||
|
|
Loading…
Reference in New Issue