forked from Mirrors/oauth2
oauth2: add func NewClient as per issue #66
Change-Id: Icfae8530e725f2f31774e395319e6e6db330262a Reviewed-on: https://go-review.googlesource.com/1701 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
79dad4e0f4
commit
7bbf2199a5
7
jwt.go
7
jwt.go
|
@ -74,12 +74,7 @@ func (c *JWTConfig) TokenSource(ctx Context, initialToken *Token) TokenSource {
|
||||||
//
|
//
|
||||||
// The returned client and its Transport should not be modified.
|
// The returned client and its Transport should not be modified.
|
||||||
func (c *JWTConfig) Client(ctx Context, initialToken *Token) *http.Client {
|
func (c *JWTConfig) Client(ctx Context, initialToken *Token) *http.Client {
|
||||||
return &http.Client{
|
return NewClient(ctx, c.TokenSource(ctx, initialToken))
|
||||||
Transport: &Transport{
|
|
||||||
Base: contextTransport(ctx),
|
|
||||||
Source: c.TokenSource(ctx, initialToken),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// jwtSource is a source that always does a signed JWT request for a token.
|
// jwtSource is a source that always does a signed JWT request for a token.
|
||||||
|
|
18
oauth2.go
18
oauth2.go
|
@ -275,12 +275,7 @@ func contextTransport(ctx Context) http.RoundTripper {
|
||||||
// HTTP transport will be obtained using the provided context.
|
// HTTP transport will be obtained using the provided context.
|
||||||
// The returned client and its Transport should not be modified.
|
// The returned client and its Transport should not be modified.
|
||||||
func (c *Config) Client(ctx Context, t *Token) *http.Client {
|
func (c *Config) Client(ctx Context, t *Token) *http.Client {
|
||||||
return &http.Client{
|
return NewClient(ctx, c.TokenSource(ctx, t))
|
||||||
Transport: &Transport{
|
|
||||||
Base: contextTransport(ctx),
|
|
||||||
Source: c.TokenSource(ctx, t),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TokenSource returns a TokenSource that returns t until t expires,
|
// TokenSource returns a TokenSource that returns t until t expires,
|
||||||
|
@ -474,3 +469,14 @@ var HTTPClient contextKey
|
||||||
// an immutable public variable with a unique type. It's immutable
|
// an immutable public variable with a unique type. It's immutable
|
||||||
// because nobody else can create a contextKey, being unexported.
|
// because nobody else can create a contextKey, being unexported.
|
||||||
type contextKey struct{}
|
type contextKey struct{}
|
||||||
|
|
||||||
|
// NewClient creates an *http.Client from a Context and TokenSource.
|
||||||
|
// The client's lifetime does not extend beyond the lifetime of the context.
|
||||||
|
func NewClient(ctx Context, src TokenSource) *http.Client {
|
||||||
|
return &http.Client{
|
||||||
|
Transport: &Transport{
|
||||||
|
Base: contextTransport(ctx),
|
||||||
|
Source: src,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue