Skip to content

Commit cfd081e

Browse files
committed
Disable session cookie quoting to work with aiohttp v3.12.12. Fix issue #684
1 parent 948ec9e commit cfd081e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pyhilo/oauth2.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from homeassistant.core import HomeAssistant
66
from homeassistant.helpers.config_entry_oauth2_flow import LocalOAuth2Implementation
77

8+
from homeassistant.helpers.aiohttp_client import async_create_clientsession
9+
from aiohttp import CookieJar
810
from pyhilo.const import AUTH_AUTHORIZE, AUTH_CLIENT_ID, AUTH_TOKEN, DOMAIN
911
from pyhilo.oauth2helper import OAuth2Helper
1012

@@ -26,6 +28,7 @@ def __init__(
2628
AUTH_TOKEN,
2729
)
2830

31+
self.session = async_create_clientsession(self.hass, cookie_jar=CookieJar(quote_cookie=False))
2932
self.oauth_helper = OAuth2Helper()
3033

3134
# ... Override AbstractOAuth2Implementation details
@@ -49,3 +52,21 @@ async def async_resolve_external_data(self, external_data: Any) -> dict:
4952
)
5053
),
5154
)
55+
56+
async def _token_request(self, data: dict) -> dict:
57+
"""Make a token request."""
58+
data["client_id"] = self.client_id
59+
60+
if self.client_secret:
61+
data["client_secret"] = self.client_secret
62+
63+
resp = await self.session.post(self.token_url, data=data)
64+
if resp.status >= 400:
65+
try:
66+
error_response = await resp.json()
67+
except (ClientError, JSONDecodeError):
68+
error_response = {}
69+
error_code = error_response.get("error", "unknown")
70+
error_description = error_response.get("error_description", "unknown error")
71+
resp.raise_for_status()
72+
return cast(dict, await resp.json())

0 commit comments

Comments
 (0)