1 """OAuth2 implementations for Toon."""
3 from __future__
import annotations
6 from typing
import Any, cast
16 from .const
import SCOPE_VALUES
20 """Local OAuth2 implementation for Electric Kiwi."""
26 client_credential: ClientCredential,
27 authorization_server: AuthorizationServer,
29 """Set up Electric Kiwi oauth."""
33 credential=client_credential,
34 authorization_server=authorization_server,
41 """Extra data that needs to be appended to the authorize url."""
42 return {
"scope": SCOPE_VALUES}
45 """Initialize local Electric Kiwi auth implementation."""
47 "grant_type":
"authorization_code",
48 "code": external_data[
"code"],
49 "redirect_uri": external_data[
"state"][
"redirect_uri"],
57 "grant_type":
"refresh_token",
58 "refresh_token": token[
"refresh_token"],
62 return {**token, **new_token}
65 """Make a token request."""
67 client_str = f
"{self.client_id}:{self.client_secret}"
68 client_string_bytes = client_str.encode(
"ascii")
70 base64_bytes = base64.b64encode(client_string_bytes)
71 base64_client = base64_bytes.decode(
"ascii")
72 headers = {
"Authorization": f
"Basic {base64_client}"}
74 resp = await session.post(self.token_url, data=data, headers=headers)
75 resp.raise_for_status()
76 return cast(dict, await resp.json())
dict _async_refresh_token(self, dict token)
None __init__(self, HomeAssistant hass, str domain, ClientCredential client_credential, AuthorizationServer authorization_server)
dict _token_request(self, dict data)
dict async_resolve_external_data(self, Any external_data)
dict[str, Any] extra_authorize_data(self)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)