diff --git a/pyhon/connection/api.py b/pyhon/connection/api.py index 07bc528..1e17e4c 100644 --- a/pyhon/connection/api.py +++ b/pyhon/connection/api.py @@ -25,6 +25,7 @@ class HonAPI: password: str = "", anonymous: bool = False, mobile_id: str = "", + refresh_token: str = "", session: Optional[ClientSession] = None, ) -> None: super().__init__() @@ -32,6 +33,7 @@ class HonAPI: self._password: str = password self._anonymous: bool = anonymous self._mobile_id: str = mobile_id + self._refresh_token: str = refresh_token self._hon_handler: Optional[HonConnectionHandler] = None self._hon_anonymous_handler: Optional[HonAnonymousConnectionHandler] = None self._session: Optional[ClientSession] = session @@ -71,7 +73,10 @@ class HonAPI: ).create() if not self._anonymous: self._hon_handler = await HonConnectionHandler( - self._email, self._password, self._session, mobile_id=self._mobile_id + self._email, + self._password, + self._session, + mobile_id=self._mobile_id, ).create() return self diff --git a/pyhon/connection/auth.py b/pyhon/connection/auth.py index cf75410..5012bbf 100644 --- a/pyhon/connection/auth.py +++ b/pyhon/connection/auth.py @@ -48,6 +48,7 @@ class HonAuth: email: str, password: str, device: HonDevice, + refresh_token: str = "", ) -> None: self._session = session self._request = HonAuthConnectionHandler(session) @@ -57,6 +58,7 @@ 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: diff --git a/pyhon/connection/handler/hon.py b/pyhon/connection/handler/hon.py index 997fb5b..b7d808e 100644 --- a/pyhon/connection/handler/hon.py +++ b/pyhon/connection/handler/hon.py @@ -23,12 +23,14 @@ class HonConnectionHandler(ConnectionHandler): email: str, password: str, mobile_id: str = "", + refresh_token: str = "", session: Optional[aiohttp.ClientSession] = None, ) -> None: super().__init__(session=session) self._device: HonDevice = HonDevice(mobile_id) self._email: str = email self._password: str = password + self._refresh_token: str = refresh_token if not self._email: raise HonAuthenticationError("An email address must be specified") if not self._password: @@ -47,7 +49,13 @@ class HonConnectionHandler(ConnectionHandler): async def create(self) -> Self: await super().create() - self._auth = HonAuth(self.session, self._email, self._password, self._device) + self._auth = HonAuth( + self.session, + 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]: diff --git a/pyhon/hon.py b/pyhon/hon.py index c52d6eb..7f53fb4 100644 --- a/pyhon/hon.py +++ b/pyhon/hon.py @@ -22,6 +22,7 @@ class Hon: password: Optional[str] = "", session: Optional[ClientSession] = None, mobile_id: str = "", + refresh_token: str = "", test_data_path: Optional[Path] = None, ): self._email: Optional[str] = email @@ -31,6 +32,7 @@ class Hon: self._api: Optional[HonAPI] = None self._test_data_path: Path = test_data_path or Path().cwd() self._mobile_id: str = mobile_id + self._refresh_token: str = refresh_token async def __aenter__(self) -> Self: return await self.create() @@ -63,7 +65,11 @@ class Hon: async def create(self) -> Self: self._api = await HonAPI( - self.email, self.password, session=self._session + self.email, + self.password, + session=self._session, + mobile_id=self._mobile_id, + refresh_token=self._refresh_token, ).create() await self.setup() return self