oauth2: ignore monotonic time when considering whether Tokens are expired

This change ensures time comparisons Token expiry checking uses the wall
clock instead of the monotonic clock.

This situation can occur on laptops which enter sleep mode and don't
advance their monotonic clock.

Change-Id: If8518e96ca04f2137db4703440ff3b851d221aae
Reviewed-on: https://go-review.googlesource.com/83575
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Blake Mesdag 2017-12-12 15:00:05 -05:00 committed by Brad Fitzpatrick
parent e585185218
commit 00dc70155e
1 changed files with 1 additions and 1 deletions

View File

@ -123,7 +123,7 @@ func (t *Token) expired() bool {
if t.Expiry.IsZero() { if t.Expiry.IsZero() {
return false return false
} }
return t.Expiry.Add(-expiryDelta).Before(time.Now()) return t.Expiry.Round(0).Add(-expiryDelta).Before(time.Now())
} }
// Valid reports whether t is non-nil, has an AccessToken, and is not expired. // Valid reports whether t is non-nil, has an AccessToken, and is not expired.