Skip to content

Commit 5424190

Browse files
authored
Merge pull request #634 from princekhunt/master
Fix: fix token expiration check for proactive refreshing
2 parents f18c816 + 650748c commit 5424190

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

authlib/oauth2/rfc6749/wrappers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ def __init__(self, params):
1010
int(params['expires_in'])
1111
super().__init__(params)
1212

13-
def is_expired(self):
13+
def is_expired(self, leeway=60):
1414
expires_at = self.get('expires_at')
1515
if not expires_at:
1616
return None
17-
return expires_at < time.time()
17+
# small timedelta to consider token as expired before it actually expires
18+
expiration_threshold = expires_at - leeway
19+
return expiration_threshold < time.time()
1820

1921
@classmethod
2022
def from_dict(cls, token):

0 commit comments

Comments
 (0)