diff --git a/authlib/oauth2/rfc6749/wrappers.py b/authlib/oauth2/rfc6749/wrappers.py index 2ecf8248..86d75bb4 100644 --- a/authlib/oauth2/rfc6749/wrappers.py +++ b/authlib/oauth2/rfc6749/wrappers.py @@ -10,11 +10,13 @@ def __init__(self, params): int(params['expires_in']) super().__init__(params) - def is_expired(self): + def is_expired(self, leeway=60): expires_at = self.get('expires_at') if not expires_at: return None - return expires_at < time.time() + # small timedelta to consider token as expired before it actually expires + expiration_threshold = expires_at - leeway + return expiration_threshold < time.time() @classmethod def from_dict(cls, token):