introduce mutex to avoid multiple token refresh when using threads.

This commit is contained in:
2023-05-09 19:30:07 +09:00
parent 8ee220137f
commit 35defa39a6
3 changed files with 20 additions and 12 deletions

View File

@ -26,16 +26,16 @@ class Token:
@property
def is_expired(self) -> bool:
now = int(time.time()) + 10
now = int(time.time())
refresh_decoded = self.__decode(self.refresh)
return now > refresh_decoded.exp
return (now - 10) > refresh_decoded.exp
@property
def is_refresh_required(self) -> bool:
now = int(time.time()) + 10
now = int(time.time())
access_decoded = self.__decode(self.access)
refresh_decoded = self.__decode(self.refresh)
return now > access_decoded.exp and now < refresh_decoded.exp
return (now + 10) > access_decoded.exp and (now - 10) < refresh_decoded.exp
def __decode(self, token: str) -> DecodedJWT:
data = jwt.decode(token, options={"verify_signature": False})