Skip to content

Commit

Permalink
fix: always authenticate on jwt
Browse files Browse the repository at this point in the history
  • Loading branch information
Lash-L committed Feb 23, 2023
1 parent 6b218c4 commit 42bface
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/southern_company_api/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ async def connect(self) -> None:
Connects to Southern company and gets all accounts
"""
self._request_token = await get_request_verification_token(self.session)
self._request_token_expiry = datetime.datetime.now() + datetime.timedelta(
hours=3
)
self._sc = await self._get_sc_web_token()
self._jwt = await self.get_jwt()
self._accounts = await self.get_accounts()
Expand Down Expand Up @@ -136,6 +139,7 @@ async def _get_sc_web_token(self) -> str:

async def _get_southern_jwt_cookie(self) -> str:
# update to use property
await self.authenticate()
if await self.sc is None:
raise CantReachSouthernCompany("Sc token cannot be refreshed")
data = {"ScWebToken": self._sc}
Expand All @@ -146,6 +150,7 @@ async def _get_southern_jwt_cookie(self) -> str:
) as resp:
# Checking for unsuccessful login
if resp.status != 200:
await self.authenticate()
raise NoScTokenFound(
f"Failed to get secondary ScWebToken: {resp.status} "
f"{resp.headers} {data} sc_expiry: {self._sc_expiry}"
Expand Down Expand Up @@ -215,7 +220,6 @@ async def get_jwt(self) -> str:
return token

async def get_accounts(self) -> List[Account]:
print("AHAHA")
if await self.jwt is None:
raise CantReachSouthernCompany("Can't get jwt. Expired and not refreshed")
headers = {"Authorization": f"bearer {self._jwt}"}
Expand Down

0 comments on commit 42bface

Please sign in to comment.