Skip to content

Commit

Permalink
Fix async token (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
inverse authored Oct 13, 2021
1 parent 2209e9f commit 14b3a15
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 105 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Run `poetry run python scripts/example.py` and copy the URL to your browser of c

You will need the HTTP basic credentials you defined earlier within the `.env` file.

Be sure to run `poetry install -E dev` to get the required dependencies for this.

## Usage example

A jupyter notebook showcasing the heating interval scheduler can be found in `notebooks/Heating Scheduler.ipynb`. To
Expand Down
22 changes: 11 additions & 11 deletions iolite_client/oauth_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ def get_access_token(self, code: str, name: str) -> dict:
f"{BASE_URL}/ui/token?{query}", auth=(self.username, self.password)
)
response.raise_for_status()
json_dict = json.loads(response.text)
return json_dict
return json.loads(response.text)

def get_new_access_token(self, refresh_token: str) -> dict:
"""
Expand All @@ -76,8 +75,7 @@ def get_new_access_token(self, refresh_token: str) -> dict:
f"{BASE_URL}/ui/token?{query}", auth=(self.username, self.password)
)
response.raise_for_status()
json_dict = json.loads(response.text)
return json_dict
return json.loads(response.text)

def get_sid(self, access_token: str) -> str:
"""
Expand All @@ -90,8 +88,7 @@ def get_sid(self, access_token: str) -> str:
f"{BASE_URL}/ui/sid?{query}", auth=(self.username, self.password)
)
response.raise_for_status()
json_dict = json.loads(response.text)
return json_dict.get("SID")
return json.loads(response.text).get("SID")


class AsyncOAuthHandler:
Expand All @@ -111,7 +108,8 @@ async def get_access_token(self, code: str, name: str) -> dict:
"""
query = OAuthHandlerHelper.get_access_token_query(code, name)
response = await self.web_session.post(
f"{BASE_URL}/ui/token?{query}", auth=(self.username, self.password)
f"{BASE_URL}/ui/token?{query}",
auth=aiohttp.BasicAuth(self.username, self.password),
)
response.raise_for_status()
return await response.json()
Expand All @@ -124,10 +122,10 @@ async def get_new_access_token(self, refresh_token: str) -> dict:
"""
query = OAuthHandlerHelper.get_new_access_token_query(refresh_token)
response = await self.web_session.post(
f"{BASE_URL}/ui/token?{query}", auth=(self.username, self.password)
f"{BASE_URL}/ui/token?{query}",
auth=aiohttp.BasicAuth(self.username, self.password),
)
response.raise_for_status()
response.raise_for_status()
return await response.json()

async def get_sid(self, access_token: str) -> str:
Expand All @@ -138,10 +136,12 @@ async def get_sid(self, access_token: str) -> str:
"""
query = OAuthHandlerHelper.get_sid_query(access_token)
response = await self.web_session.get(
f"{BASE_URL}/ui/sid?{query}", auth=(self.username, self.password)
f"{BASE_URL}/ui/sid?{query}",
auth=aiohttp.BasicAuth(self.username, self.password),
)
response.raise_for_status()
return await response.json()
response_json = await response.json()
return response_json.get("SID")


class OAuthStorage:
Expand Down
Loading

0 comments on commit 14b3a15

Please sign in to comment.