From 53b367afa0425a566a3d4b0e856cbe40586f1eb3 Mon Sep 17 00:00:00 2001 From: Krisjanis Lejejs Date: Mon, 26 Dec 2022 16:55:27 +0200 Subject: [PATCH] Remove legacy auth flow as it is not working anymore --- ThermiaOnlineAPI/api/ThermiaAPI.py | 56 +----------------------------- 1 file changed, 1 insertion(+), 55 deletions(-) diff --git a/ThermiaOnlineAPI/api/ThermiaAPI.py b/ThermiaOnlineAPI/api/ThermiaAPI.py index 95e5d6d..3db5178 100644 --- a/ThermiaOnlineAPI/api/ThermiaAPI.py +++ b/ThermiaOnlineAPI/api/ThermiaAPI.py @@ -13,7 +13,6 @@ REG_GROUP_OPERATIONAL_TIME, REG_GROUP_TEMPERATURES, THERMIA_API_CONFIG_URLS_BY_API_TYPE, - THERMIA_API_TYPE_CLASSIC, THERMIA_AZURE_AUTH_URL, THERMIA_AZURE_AUTH_CLIENT_ID_AND_SCOPE, THERMIA_AZURE_AUTH_REDIRECT_URI, @@ -35,7 +34,6 @@ def __init__(self, email, password, api_type): self.__password = password self.__token = None self.__token_valid_to = None - self.__api_type = api_type self.__refresh_token_valid_to = None self.__refresh_token = None @@ -397,20 +395,7 @@ def __fetch_configuration(self): return request.json() - def __authenticate(self): - result = False - - try: - result = self.__authenticate_azure() - except Exception as e: - _LOGGER.warn("Error authenticating with Azure auth." + str(e)) - - if not result and self.__api_type == THERMIA_API_TYPE_CLASSIC: - return self.__authenticate_legacy() - - return result - - def __authenticate_azure(self) -> bool: + def __authenticate(self) -> bool: # Azure auth URLs azure_auth_authorize_url = THERMIA_AZURE_AUTH_URL + "/oauth2/v2.0/authorize" azure_auth_get_token_url = THERMIA_AZURE_AUTH_URL + "/oauth2/v2.0/token" @@ -588,45 +573,6 @@ def __authenticate_azure(self) -> bool: return True - def __authenticate_legacy(self): - auth_url = self.configuration["authApiBaseUrl"] + "/api/v1/Jwt/login" - - json = { - "userName": self.__email, - "password": self.__password, - "rememberMe": True, - } - - request_auth = requests.post(auth_url, json=json) - status = request_auth.status_code - - if status != 200: - _LOGGER.error( - "Authentication request failed, please check credentials. " - + str(status) - ) - raise AuthenticationException( - "Authentication request failed, please check credentials.", status - ) - - auth_data = request_auth.json() - - token_valid_to = auth_data.get("tokenValidToUtc").split(".")[0] - datetime_object = datetime.strptime(token_valid_to, "%Y-%m-%dT%H:%M:%S") - token_valid_to = datetime_object.timestamp() - - self.__token = auth_data.get("token") - self.__token_valid_to = token_valid_to - - self.__default_request_headers = { - "Authorization": "Bearer " + self.__token, - "Content-Type": "application/json", - } - - _LOGGER.info("Authentication was successful, token set.") - - return True - def __check_token_validity(self): if ( self.__token_valid_to is None