-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
/
Copy pathapplication_credentials.py
58 lines (49 loc) · 1.66 KB
/
application_credentials.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Application credentials platform for the Volvo integration."""
from volvocarsapi.auth import AUTHORIZE_URL, TOKEN_URL
from homeassistant.components.application_credentials import (
AuthorizationServer,
ClientCredential,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.config_entry_oauth2_flow import (
AbstractOAuth2Implementation,
LocalOAuth2ImplementationWithPkce,
)
from .const import SCOPES
async def async_get_auth_implementation(
hass: HomeAssistant, auth_domain: str, credential: ClientCredential
) -> AbstractOAuth2Implementation:
"""Return auth implementation for a custom auth implementation."""
return VolvoOAuth2Implementation(
hass,
auth_domain,
credential,
authorization_server=AuthorizationServer(
authorize_url=AUTHORIZE_URL,
token_url=TOKEN_URL,
),
)
class VolvoOAuth2Implementation(LocalOAuth2ImplementationWithPkce):
"""Volvo oauth2 implementation."""
def __init__(
self,
hass: HomeAssistant,
auth_domain: str,
credential: ClientCredential,
authorization_server: AuthorizationServer,
) -> None:
"""Initialize."""
super().__init__(
hass,
auth_domain,
credential.client_id,
authorization_server.authorize_url,
authorization_server.token_url,
credential.client_secret,
)
@property
def extra_authorize_data(self) -> dict:
"""Extra data that needs to be appended to the authorize url."""
return super().extra_authorize_data | {
"scope": " ".join(SCOPES),
}