mirror of
https://github.com/Andre0512/pyhOn.git
synced 2024-12-22 10:45:31 +00:00
Fix problems with refresh token
This commit is contained in:
parent
767cbe35de
commit
c4e8038652
|
@ -109,7 +109,7 @@ class HonCommandLoader:
|
|||
categories: Optional[Dict[str, "HonCommand"]] = None,
|
||||
category_name: str = "",
|
||||
) -> Optional[HonCommand]:
|
||||
"""Try to crate HonCommand object"""
|
||||
"""Try to create HonCommand object"""
|
||||
if not isinstance(data, dict):
|
||||
self._additional_data[command_name] = data
|
||||
return None
|
||||
|
|
|
@ -75,7 +75,7 @@ class HonAPI:
|
|||
self._hon_handler = await HonConnectionHandler(
|
||||
self._email,
|
||||
self._password,
|
||||
self._session,
|
||||
session=self._session,
|
||||
mobile_id=self._mobile_id,
|
||||
).create()
|
||||
return self
|
||||
|
|
|
@ -48,7 +48,6 @@ class HonAuth:
|
|||
email: str,
|
||||
password: str,
|
||||
device: HonDevice,
|
||||
refresh_token: str = "",
|
||||
) -> None:
|
||||
self._session = session
|
||||
self._request = HonAuthConnectionHandler(session)
|
||||
|
@ -58,7 +57,6 @@ class HonAuth:
|
|||
self._device = device
|
||||
self._expires: datetime = datetime.utcnow()
|
||||
self._auth = HonAuthData()
|
||||
self._auth.refresh_token = refresh_token
|
||||
|
||||
@property
|
||||
def cognito_token(self) -> str:
|
||||
|
@ -201,7 +199,7 @@ class HonAuth:
|
|||
if access_token := re.findall("access_token=(.*?)&", text):
|
||||
self._auth.access_token = access_token[0]
|
||||
if refresh_token := re.findall("refresh_token=(.*?)&", text):
|
||||
self._auth.refresh_token = refresh_token[0]
|
||||
self._auth.refresh_token = parse.unquote(refresh_token[0])
|
||||
if id_token := re.findall("id_token=(.*?)&", text):
|
||||
self._auth.id_token = id_token[0]
|
||||
return bool(access_token and refresh_token and id_token)
|
||||
|
@ -266,7 +264,9 @@ class HonAuth:
|
|||
except exceptions.HonNoAuthenticationNeeded:
|
||||
return
|
||||
|
||||
async def refresh(self) -> bool:
|
||||
async def refresh(self, refresh_token="") -> bool:
|
||||
if refresh_token:
|
||||
self._auth.refresh_token = refresh_token
|
||||
params = {
|
||||
"client_id": const.CLIENT_ID,
|
||||
"refresh_token": self._auth.refresh_token,
|
||||
|
|
|
@ -22,9 +22,9 @@ class HonConnectionHandler(ConnectionHandler):
|
|||
self,
|
||||
email: str,
|
||||
password: str,
|
||||
session: Optional[aiohttp.ClientSession] = None,
|
||||
mobile_id: str = "",
|
||||
refresh_token: str = "",
|
||||
session: Optional[aiohttp.ClientSession] = None,
|
||||
) -> None:
|
||||
super().__init__(session=session)
|
||||
self._device: HonDevice = HonDevice(mobile_id)
|
||||
|
@ -54,11 +54,12 @@ class HonConnectionHandler(ConnectionHandler):
|
|||
self._email,
|
||||
self._password,
|
||||
self._device,
|
||||
refresh_token=self._refresh_token,
|
||||
)
|
||||
return self
|
||||
|
||||
async def _check_headers(self, headers: Dict[str, str]) -> Dict[str, str]:
|
||||
if self._refresh_token:
|
||||
await self.auth.refresh(self._refresh_token)
|
||||
if not (self.auth.cognito_token and self.auth.id_token):
|
||||
await self.auth.authenticate()
|
||||
headers["cognito-token"] = self.auth.cognito_token
|
||||
|
|
Loading…
Reference in a new issue