mdrs-client-python/mdrsclient/api/utils.py

20 lines
702 B
Python
Raw Normal View History

from mdrsclient.api.users import UsersApi
from mdrsclient.connection import MDRSConnection
2023-05-01 20:00:32 +09:00
from mdrsclient.exceptions import UnauthorizedException
def token_check(connection: MDRSConnection) -> None:
try:
connection.lock.acquire()
if connection.token is not None:
if connection.token.is_refresh_required:
user_api = UsersApi(connection)
try:
connection.token = user_api.tokenRefresh(connection.token)
except UnauthorizedException:
connection.logout()
elif connection.token.is_expired:
connection.logout()
finally:
connection.lock.release()