Skip to content

Commit 7faf878

Browse files
author
Pegasus
committed
Give the auth token 60 seconds safty margin
1 parent f962ef3 commit 7faf878

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,4 @@ pypirc
116116
*State.json
117117
tests/parse_level_two.py
118118
certs/
119+
td/td_state.json

td/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,25 +438,25 @@ def _token_seconds(self, token_type: str = 'access_token') -> int:
438438
if token_type == 'access_token':
439439

440440
# if the time to expiration is less than or equal to 0, return 0.
441-
if not self.state['access_token'] or time.time() >= self.state['access_token_expires_at']:
441+
if not self.state['access_token'] or time.time() + 60 >= self.state['access_token_expires_at']:
442442
return 0
443443

444444
# else return the number of seconds until expiration.
445-
token_exp = int(self.state['access_token_expires_at'] - time.time())
445+
token_exp = int(self.state['access_token_expires_at'] - time.time() - 60)
446446

447447
# if needed check the refresh token.
448448
elif token_type == 'refresh_token':
449449

450450
# if the time to expiration is less than or equal to 0, return 0.
451-
if not self.state['refresh_token'] or time.time() >= self.state['refresh_token_expires_at']:
451+
if not self.state['refresh_token'] or time.time() + 60 >= self.state['refresh_token_expires_at']:
452452
return 0
453453

454454
# else return the number of seconds until expiration.
455-
token_exp = int(self.state['refresh_token_expires_at'] - time.time())
455+
token_exp = int(self.state['refresh_token_expires_at'] - time.time() - 60)
456456

457457
return token_exp
458458

459-
def _token_validation(self, nseconds: int = 5):
459+
def _token_validation(self, nseconds: int = 60):
460460
"""Checks if a token is valid.
461461
462462
Verify the current access token is valid for at least N seconds, and

0 commit comments

Comments
 (0)