Skip to content

Commit 59e3d99

Browse files
authored
Merge pull request #29 from addshore/updatedLogin
Update for new hOn login
2 parents 63752e1 + 3f39be5 commit 59e3d99

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

pyhon/connection/auth.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,23 @@ async def _introduce(self) -> str:
120120
async with self._request.get(url) as response:
121121
text = await response.text()
122122
self._expires = datetime.utcnow()
123-
login_url: List[str] = re.findall("url = '(.+?)'", text)
123+
login_url: List[str] = re.findall("(?:url|href) ?= ?'(.+?)'", text)
124124
if not login_url:
125125
if "oauth/done#access_token=" in text:
126126
self._parse_token_data(text)
127127
raise exceptions.HonNoAuthenticationNeeded()
128128
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]}"
129133
return login_url[0]
130134

131135
async def _manual_redirect(self, url: str) -> str:
132136
async with self._request.get(url, allow_redirects=False) as response:
133-
if not (new_location := response.headers.get("Location", "")):
134-
await self._error_logger(response)
137+
new_location = response.headers.get("Location", "")
138+
if not new_location:
139+
return url
135140
return new_location
136141

137142
async def _handle_redirects(self, login_url: str) -> str:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name="pyhOn",
10-
version="0.17.4",
10+
version="0.17.5",
1111
author="Andre Basche",
1212
description="Control hOn devices with python",
1313
long_description=long_description,

0 commit comments

Comments
 (0)