aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Basche <andre.basche@gmail.com>2024-08-14 22:42:39 +0200
committerGitHub <noreply@github.com>2024-08-14 22:42:39 +0200
commit59e3d9949f8a342e05daba70451196e7497cacb2 (patch)
tree2d32fb0f865ff1368bcd43ce5da4c2cdba26a677
parent63752e13d6c8e74284ad72e04306e9fedde58b40 (diff)
parent3f39be53f31885fb84d72f91fb4123c2e39e7156 (diff)
Merge pull request #29 from addshore/updatedLoginHEADv0.17.5main
Update for new hOn login
-rw-r--r--pyhon/connection/auth.py11
-rw-r--r--setup.py2
2 files changed, 9 insertions, 4 deletions
diff --git a/pyhon/connection/auth.py b/pyhon/connection/auth.py
index 2096010..3ab491c 100644
--- a/pyhon/connection/auth.py
+++ b/pyhon/connection/auth.py
@@ -120,18 +120,23 @@ class HonAuth:
120 async with self._request.get(url) as response: 120 async with self._request.get(url) as response:
121 text = await response.text() 121 text = await response.text()
122 self._expires = datetime.utcnow() 122 self._expires = datetime.utcnow()
123 login_url: List[str] = re.findall("url = '(.+?)'", text) 123 login_url: List[str] = re.findall("(?:url|href) ?= ?'(.+?)'", text)
124 if not login_url: 124 if not login_url:
125 if "oauth/done#access_token=" in text: 125 if "oauth/done#access_token=" in text:
126 self._parse_token_data(text) 126 self._parse_token_data(text)
127 raise exceptions.HonNoAuthenticationNeeded() 127 raise exceptions.HonNoAuthenticationNeeded()
128 await self._error_logger(response) 128 await self._error_logger(response)
129 # As of July 2024 the login page has changed, and we started getting a /NewhOnLogin based relative URL in JS to parse
130 if login_url[0].startswith("/NewhOnLogin"):
131 # Force use of the old login page to avoid having to make the new one work..
132 login_url[0] = f"{const.AUTH_API}/s/login{login_url[0]}"
129 return login_url[0] 133 return login_url[0]
130 134
131 async def _manual_redirect(self, url: str) -> str: 135 async def _manual_redirect(self, url: str) -> str:
132 async with self._request.get(url, allow_redirects=False) as response: 136 async with self._request.get(url, allow_redirects=False) as response:
133 if not (new_location := response.headers.get("Location", "")): 137 new_location = response.headers.get("Location", "")
134 await self._error_logger(response) 138 if not new_location:
139 return url
135 return new_location 140 return new_location
136 141
137 async def _handle_redirects(self, login_url: str) -> str: 142 async def _handle_redirects(self, login_url: str) -> str:
diff --git a/setup.py b/setup.py
index 115205d..1e8e2fc 100644
--- a/setup.py
+++ b/setup.py
@@ -7,7 +7,7 @@ with open("README.md", "r", encoding="utf-8") as f:
7 7
8setup( 8setup(
9 name="pyhOn", 9 name="pyhOn",
10 version="0.17.4", 10 version="0.17.5",
11 author="Andre Basche", 11 author="Andre Basche",
12 description="Control hOn devices with python", 12 description="Control hOn devices with python",
13 long_description=long_description, 13 long_description=long_description,