Merge pull request #1510 from dmcgowan/oauth-offline-access
Add offline token option
This commit is contained in:
commit
858a04160c
1 changed files with 19 additions and 12 deletions
|
@ -116,9 +116,10 @@ type tokenHandler struct {
|
||||||
transport http.RoundTripper
|
transport http.RoundTripper
|
||||||
clock clock
|
clock clock
|
||||||
|
|
||||||
forceOAuth bool
|
offlineAccess bool
|
||||||
clientID string
|
forceOAuth bool
|
||||||
scopes []Scope
|
clientID string
|
||||||
|
scopes []Scope
|
||||||
|
|
||||||
tokenLock sync.Mutex
|
tokenLock sync.Mutex
|
||||||
tokenCache string
|
tokenCache string
|
||||||
|
@ -149,9 +150,10 @@ type TokenHandlerOptions struct {
|
||||||
Transport http.RoundTripper
|
Transport http.RoundTripper
|
||||||
Credentials CredentialStore
|
Credentials CredentialStore
|
||||||
|
|
||||||
ForceOAuth bool
|
OfflineAccess bool
|
||||||
ClientID string
|
ForceOAuth bool
|
||||||
Scopes []Scope
|
ClientID string
|
||||||
|
Scopes []Scope
|
||||||
}
|
}
|
||||||
|
|
||||||
// An implementation of clock for providing real time data.
|
// An implementation of clock for providing real time data.
|
||||||
|
@ -180,12 +182,13 @@ func NewTokenHandler(transport http.RoundTripper, creds CredentialStore, scope s
|
||||||
// options structure.
|
// options structure.
|
||||||
func NewTokenHandlerWithOptions(options TokenHandlerOptions) AuthenticationHandler {
|
func NewTokenHandlerWithOptions(options TokenHandlerOptions) AuthenticationHandler {
|
||||||
handler := &tokenHandler{
|
handler := &tokenHandler{
|
||||||
transport: options.Transport,
|
transport: options.Transport,
|
||||||
creds: options.Credentials,
|
creds: options.Credentials,
|
||||||
forceOAuth: options.ForceOAuth,
|
offlineAccess: options.OfflineAccess,
|
||||||
clientID: options.ClientID,
|
forceOAuth: options.ForceOAuth,
|
||||||
scopes: options.Scopes,
|
clientID: options.ClientID,
|
||||||
clock: realClock{},
|
scopes: options.Scopes,
|
||||||
|
clock: realClock{},
|
||||||
}
|
}
|
||||||
|
|
||||||
return handler
|
return handler
|
||||||
|
@ -346,6 +349,10 @@ func (th *tokenHandler) fetchTokenWithBasicAuth(realm *url.URL, service string,
|
||||||
reqParams.Add("scope", scope)
|
reqParams.Add("scope", scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if th.offlineAccess {
|
||||||
|
reqParams.Add("offline_token", "true")
|
||||||
|
}
|
||||||
|
|
||||||
if th.creds != nil {
|
if th.creds != nil {
|
||||||
username, password := th.creds.Basic(realm)
|
username, password := th.creds.Basic(realm)
|
||||||
if username != "" && password != "" {
|
if username != "" && password != "" {
|
||||||
|
|
Loading…
Reference in a new issue