Skip to content

Commit

Permalink
Remove legacy auth flow as it is not working anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
klejejs committed Dec 26, 2022
1 parent 6130592 commit 53b367a
Showing 1 changed file with 1 addition and 55 deletions.
56 changes: 1 addition & 55 deletions ThermiaOnlineAPI/api/ThermiaAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 53b367a

Please sign in to comment.