mirror of
https://github.com/rclone/rclone.git
synced 2025-01-20 02:42:44 +08:00
oauthlib: add method to set a token as expired
This can be used by backends to trigger a refresh of an access token if they detect an invalid token.
This commit is contained in:
parent
62bcc84f6f
commit
53400d7edc
|
@ -269,6 +269,23 @@ func (ts *TokenSource) Invalidate() {
|
||||||
ts.mu.Unlock()
|
ts.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Expire marks the token as expired
|
||||||
|
//
|
||||||
|
// This also marks the token in the config file as expired, if it is the same one
|
||||||
|
func (ts *TokenSource) Expire() error {
|
||||||
|
ts.mu.Lock()
|
||||||
|
defer ts.mu.Unlock()
|
||||||
|
ts.token.Expiry = time.Now().Add(time.Hour * (-1)) // expire token
|
||||||
|
t, err := GetToken(ts.name, ts.m)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if t.AccessToken == ts.token.AccessToken {
|
||||||
|
err = PutToken(ts.name, ts.m, ts.token, false)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// timeToExpiry returns how long until the token expires
|
// timeToExpiry returns how long until the token expires
|
||||||
//
|
//
|
||||||
// Call with the lock held
|
// Call with the lock held
|
||||||
|
|
|
@ -67,3 +67,8 @@ func (r *Renew) Stop() {
|
||||||
func (r *Renew) Invalidate() {
|
func (r *Renew) Invalidate() {
|
||||||
r.ts.Invalidate()
|
r.ts.Invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Expire expires the token source
|
||||||
|
func (r *Renew) Expire() error {
|
||||||
|
return r.ts.Expire()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user