1 """OAuth2 implementations for Toon."""
3 from __future__
import annotations
5 from typing
import Any, cast
11 from .
import config_flow
15 hass: HomeAssistant, client_id: str, client_secret: str
17 """Register Toon OAuth2 implementations."""
18 config_flow.ToonFlowHandler.async_register_implementation(
23 client_secret=client_secret,
26 issuer=
"identity.toon.eu",
29 config_flow.ToonFlowHandler.async_register_implementation(
34 client_secret=client_secret,
35 name=
"Engie Electrabel Boxx",
36 tenant_id=
"electrabel",
37 issuer=
"identity.toon.eu",
40 config_flow.ToonFlowHandler.async_register_implementation(
45 client_secret=client_secret,
53 """Local OAuth2 implementation for Toon."""
62 issuer: str |
None =
None,
64 """Local Toon Oauth Implementation."""
73 client_secret=client_secret,
74 authorize_url=
"https://api.toon.eu/authorize",
75 token_url=
"https://api.toon.eu/token",
80 """Name of the implementation."""
81 return f
"{self._name} via Configuration.yaml"
85 """Extra data that needs to be appended to the authorize url."""
86 data = {
"tenant_id": self.
tenant_idtenant_id}
88 if self.
issuerissuer
is not None:
89 data[
"issuer"] = self.
issuerissuer
94 """Initialize local Toon auth implementation."""
96 "grant_type":
"authorization_code",
97 "code": external_data[
"code"],
98 "redirect_uri": external_data[
"state"][
"redirect_uri"],
102 if self.
issuerissuer
is not None:
103 data[
"issuer"] = self.
issuerissuer
108 """Refresh tokens."""
110 "grant_type":
"refresh_token",
111 "client_id": self.client_id,
112 "refresh_token": token[
"refresh_token"],
117 return {**token, **new_token}
120 """Make a token request."""
124 data[
"client_id"] = self.client_id
125 data[
"tenant_id"] = self.
tenant_idtenant_id
127 if self.client_secret
is not None:
128 data[
"client_secret"] = self.client_secret
130 if self.
issuerissuer
is not None:
131 data[
"issuer"] = self.
issuerissuer
132 headers[
"issuer"] = self.
issuerissuer
134 resp = await session.post(self.token_url, data=data, headers=headers)
135 resp.raise_for_status()
136 resp_json = cast(dict, await resp.json())
139 resp_json[
"expires_in"] =
float(resp_json[
"expires_in"])
dict _async_refresh_token(self, dict token)
None __init__(self, HomeAssistant hass, str client_id, str client_secret, str name, str tenant_id, str|None issuer=None)
dict async_resolve_external_data(self, Any external_data)
dict _token_request(self, dict data)
dict extra_authorize_data(self)
None register_oauth2_implementations(HomeAssistant hass, str client_id, str client_secret)
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)