Compare commits

...

2 Commits

Author SHA1 Message Date
33454f68b8 Encode username/password 2023-04-12 02:10:37 +02:00
6b2c60d552 Fix session issues 2023-04-12 01:07:33 +02:00
3 changed files with 15 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import secrets
import urllib
from pprint import pformat
from urllib import parse
from urllib.parse import quote
from yarl import URL
@ -86,7 +87,9 @@ class HonAuth:
):
await self._error_logger(redirect2)
return False
async with self._session.get(URL(url, encoded=True)) as login_screen:
async with self._session.get(
URL(url, encoded=True), headers={"user-agent": const.USER_AGENT}
) as login_screen:
self._called_urls.append(
(login_screen.status, login_screen.request_info.url)
)
@ -111,8 +114,8 @@ class HonAuth:
"descriptor": "apex://LightningLoginCustomController/ACTION$login",
"callingDescriptor": "markup://c:loginForm",
"params": {
"username": self._email,
"password": self._password,
"username": quote(self._email),
"password": quote(self._password),
"startUrl": parse.unquote(
login_url.split("startURL=")[-1]
).split("%3D")[0],

View File

@ -13,6 +13,7 @@ class HonBaseConnectionHandler:
_HEADERS = {"user-agent": const.USER_AGENT, "Content-Type": "application/json"}
def __init__(self, session=None):
self._create_session = session is None
self._session = session
self._auth = None
@ -23,7 +24,8 @@ class HonBaseConnectionHandler:
await self.close()
async def create(self):
self._session = aiohttp.ClientSession(headers=self._HEADERS)
if self._create_session:
self._session = aiohttp.ClientSession()
return self
@asynccontextmanager
@ -41,7 +43,8 @@ class HonBaseConnectionHandler:
yield response
async def close(self):
await self._session.close()
if self._create_session:
await self._session.close()
class HonConnectionHandler(HonBaseConnectionHandler):
@ -75,7 +78,7 @@ class HonConnectionHandler(HonBaseConnectionHandler):
self._request_headers["id-token"] = self._auth.id_token
else:
raise HonAuthenticationError("Can't login")
return headers | self._request_headers
return self._HEADERS | headers | self._request_headers
@asynccontextmanager
async def _intercept(self, method, *args, loop=0, **kwargs):
@ -95,6 +98,8 @@ class HonConnectionHandler(HonBaseConnectionHandler):
response.status,
await response.text(),
)
self._request_headers = {}
self._session.cookie_jar.clear_domain(const.AUTH_API.split("/")[-2])
await self.create()
async with self._intercept(
method, *args, loop=loop + 1, **kwargs

View File

@ -7,7 +7,7 @@ with open("README.md", "r") as f:
setup(
name="pyhOn",
version="0.7.0",
version="0.7.2",
author="Andre Basche",
description="Control hOn devices with python",
long_description=long_description,