Set refresh token

This commit is contained in:
Andre Basche 2024-02-10 00:59:14 +01:00
parent df27729c2e
commit 767cbe35de
4 changed files with 24 additions and 3 deletions

View file

@ -25,6 +25,7 @@ class HonAPI:
password: str = "", password: str = "",
anonymous: bool = False, anonymous: bool = False,
mobile_id: str = "", mobile_id: str = "",
refresh_token: str = "",
session: Optional[ClientSession] = None, session: Optional[ClientSession] = None,
) -> None: ) -> None:
super().__init__() super().__init__()
@ -32,6 +33,7 @@ class HonAPI:
self._password: str = password self._password: str = password
self._anonymous: bool = anonymous self._anonymous: bool = anonymous
self._mobile_id: str = mobile_id self._mobile_id: str = mobile_id
self._refresh_token: str = refresh_token
self._hon_handler: Optional[HonConnectionHandler] = None self._hon_handler: Optional[HonConnectionHandler] = None
self._hon_anonymous_handler: Optional[HonAnonymousConnectionHandler] = None self._hon_anonymous_handler: Optional[HonAnonymousConnectionHandler] = None
self._session: Optional[ClientSession] = session self._session: Optional[ClientSession] = session
@ -71,7 +73,10 @@ class HonAPI:
).create() ).create()
if not self._anonymous: if not self._anonymous:
self._hon_handler = await HonConnectionHandler( 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() ).create()
return self return self

View file

@ -48,6 +48,7 @@ class HonAuth:
email: str, email: str,
password: str, password: str,
device: HonDevice, device: HonDevice,
refresh_token: str = "",
) -> None: ) -> None:
self._session = session self._session = session
self._request = HonAuthConnectionHandler(session) self._request = HonAuthConnectionHandler(session)
@ -57,6 +58,7 @@ class HonAuth:
self._device = device self._device = device
self._expires: datetime = datetime.utcnow() self._expires: datetime = datetime.utcnow()
self._auth = HonAuthData() self._auth = HonAuthData()
self._auth.refresh_token = refresh_token
@property @property
def cognito_token(self) -> str: def cognito_token(self) -> str:

View file

@ -23,12 +23,14 @@ class HonConnectionHandler(ConnectionHandler):
email: str, email: str,
password: str, password: str,
mobile_id: str = "", mobile_id: str = "",
refresh_token: str = "",
session: Optional[aiohttp.ClientSession] = None, session: Optional[aiohttp.ClientSession] = None,
) -> None: ) -> None:
super().__init__(session=session) super().__init__(session=session)
self._device: HonDevice = HonDevice(mobile_id) self._device: HonDevice = HonDevice(mobile_id)
self._email: str = email self._email: str = email
self._password: str = password self._password: str = password
self._refresh_token: str = refresh_token
if not self._email: if not self._email:
raise HonAuthenticationError("An email address must be specified") raise HonAuthenticationError("An email address must be specified")
if not self._password: if not self._password:
@ -47,7 +49,13 @@ class HonConnectionHandler(ConnectionHandler):
async def create(self) -> Self: async def create(self) -> Self:
await super().create() 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 return self
async def _check_headers(self, headers: Dict[str, str]) -> Dict[str, str]: async def _check_headers(self, headers: Dict[str, str]) -> Dict[str, str]:

View file

@ -22,6 +22,7 @@ class Hon:
password: Optional[str] = "", password: Optional[str] = "",
session: Optional[ClientSession] = None, session: Optional[ClientSession] = None,
mobile_id: str = "", mobile_id: str = "",
refresh_token: str = "",
test_data_path: Optional[Path] = None, test_data_path: Optional[Path] = None,
): ):
self._email: Optional[str] = email self._email: Optional[str] = email
@ -31,6 +32,7 @@ class Hon:
self._api: Optional[HonAPI] = None self._api: Optional[HonAPI] = None
self._test_data_path: Path = test_data_path or Path().cwd() self._test_data_path: Path = test_data_path or Path().cwd()
self._mobile_id: str = mobile_id self._mobile_id: str = mobile_id
self._refresh_token: str = refresh_token
async def __aenter__(self) -> Self: async def __aenter__(self) -> Self:
return await self.create() return await self.create()
@ -63,7 +65,11 @@ class Hon:
async def create(self) -> Self: async def create(self) -> Self:
self._api = await HonAPI( 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() ).create()
await self.setup() await self.setup()
return self return self