From 3da1fdc0ff765438cce6b7a7fd3c4e6ec1b42272 Mon Sep 17 00:00:00 2001 From: princekhunt Date: Thu, 21 Mar 2024 22:44:59 +0530 Subject: [PATCH 1/2] Fix token expiration check for proactive refreshing --- authlib/oauth2/rfc6749/wrappers.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/authlib/oauth2/rfc6749/wrappers.py b/authlib/oauth2/rfc6749/wrappers.py index 2ecf8248..891323a1 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, timedelta_seconds=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 - timedelta_seconds + return expiration_threshold < time.time() @classmethod def from_dict(cls, token): From 650748cb650edfaf7b49930e752ca02f24fc2dcb Mon Sep 17 00:00:00 2001 From: princekhunt Date: Sun, 31 Mar 2024 12:49:41 +0530 Subject: [PATCH 2/2] chnage the parameter to leeway --- authlib/oauth2/rfc6749/wrappers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/authlib/oauth2/rfc6749/wrappers.py b/authlib/oauth2/rfc6749/wrappers.py index 891323a1..86d75bb4 100644 --- a/authlib/oauth2/rfc6749/wrappers.py +++ b/authlib/oauth2/rfc6749/wrappers.py @@ -10,12 +10,12 @@ def __init__(self, params): int(params['expires_in']) super().__init__(params) - def is_expired(self, timedelta_seconds=60): + def is_expired(self, leeway=60): expires_at = self.get('expires_at') if not expires_at: return None # small timedelta to consider token as expired before it actually expires - expiration_threshold = expires_at - timedelta_seconds + expiration_threshold = expires_at - leeway return expiration_threshold < time.time() @classmethod