Skip to content

Commit

Permalink
Merge pull request #29 from addshore/updatedLogin
Browse files Browse the repository at this point in the history
Update for new hOn login
  • Loading branch information
Andre0512 authored Aug 14, 2024
2 parents 63752e1 + 3f39be5 commit 59e3d99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions pyhon/connection/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,23 @@ async def _introduce(self) -> str:
async with self._request.get(url) as response:
text = await response.text()
self._expires = datetime.utcnow()
login_url: List[str] = re.findall("url = '(.+?)'", text)
login_url: List[str] = re.findall("(?:url|href) ?= ?'(.+?)'", text)
if not login_url:
if "oauth/done#access_token=" in text:
self._parse_token_data(text)
raise exceptions.HonNoAuthenticationNeeded()
await self._error_logger(response)
# As of July 2024 the login page has changed, and we started getting a /NewhOnLogin based relative URL in JS to parse
if login_url[0].startswith("/NewhOnLogin"):
# Force use of the old login page to avoid having to make the new one work..
login_url[0] = f"{const.AUTH_API}/s/login{login_url[0]}"
return login_url[0]

async def _manual_redirect(self, url: str) -> str:
async with self._request.get(url, allow_redirects=False) as response:
if not (new_location := response.headers.get("Location", "")):
await self._error_logger(response)
new_location = response.headers.get("Location", "")
if not new_location:
return url
return new_location

async def _handle_redirects(self, login_url: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="pyhOn",
version="0.17.4",
version="0.17.5",
author="Andre Basche",
description="Control hOn devices with python",
long_description=long_description,
Expand Down

0 comments on commit 59e3d99

Please sign in to comment.