Skip to content

Commit

Permalink
Fix token expiration check for proactive refreshing
Browse files Browse the repository at this point in the history
  • Loading branch information
princekhunt committed Mar 21, 2024
1 parent 5ac4680 commit 3da1fdc
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions authlib/oauth2/rfc6749/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 3da1fdc

Please sign in to comment.