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