20 lines
694 B
Python
20 lines
694 B
Python
from mdrsclient.api.user import UserApi
|
|
from mdrsclient.connection import MDRSConnection
|
|
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 = UserApi(connection)
|
|
try:
|
|
connection.token = user_api.refresh(connection.token)
|
|
except UnauthorizedException:
|
|
connection.logout()
|
|
elif connection.token.is_expired:
|
|
connection.logout()
|
|
finally:
|
|
connection.lock.release()
|