From f96116f4e5752abfff46a552e17e7482479b00cc Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Mon, 18 Sep 2023 14:47:18 +0200 Subject: [PATCH] added custom implementation of 'is_token_valid' --- common/ayon_common/connection/credentials.py | 23 +++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/common/ayon_common/connection/credentials.py b/common/ayon_common/connection/credentials.py index 52fd9ce64..f9af8518c 100644 --- a/common/ayon_common/connection/credentials.py +++ b/common/ayon_common/connection/credentials.py @@ -23,7 +23,6 @@ from ayon_api.exceptions import UrlError from ayon_api.utils import ( validate_url, - is_token_valid, logout_from_server, ) @@ -465,6 +464,28 @@ def create_global_connection(): ) +def is_token_valid(url, token): + """Check if token is valid. + + Note: + This function is available in 'ayon_api', but does not support to + validate service api key, only user's token. The support will be + added in future PRs of 'ayon_api'. + The function also did not support timeout which could cause + 'ayon_api.is_token_valid' to hang. + + Args: + url (str): Server url. + token (str): User's token. + + Returns: + bool: True if token is valid. + """ + + api = ayon_api.ServerAPI(url, token) + return api.has_valid_token + + def need_server_or_login() -> bool: """Check if server url or login to the server are needed.