Add application_credentials platform to geocaching integration (#71880)

This commit is contained in:
Allen Porter 2022-05-16 00:57:25 -07:00 committed by GitHub
parent aa35b87884
commit 7c68278482
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 90 deletions

View file

@ -3,37 +3,37 @@ from __future__ import annotations
from typing import Any, cast
from homeassistant.components.application_credentials import (
AuthImplementation,
AuthorizationServer,
ClientCredential,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_entry_oauth2_flow
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import DOMAIN, ENVIRONMENT, ENVIRONMENT_URLS
from .const import ENVIRONMENT, ENVIRONMENT_URLS
class GeocachingOAuth2Implementation(
config_entry_oauth2_flow.LocalOAuth2Implementation
):
class GeocachingOAuth2Implementation(AuthImplementation):
"""Local OAuth2 implementation for Geocaching."""
def __init__(
self, hass: HomeAssistant, client_id: str, client_secret: str, name: str
self,
hass: HomeAssistant,
auth_domain: str,
credential: ClientCredential,
) -> None:
"""Local Geocaching Oauth Implementation."""
self._name = name
super().__init__(
hass=hass,
client_id=client_id,
client_secret=client_secret,
domain=DOMAIN,
authorize_url=ENVIRONMENT_URLS[ENVIRONMENT]["authorize_url"],
token_url=ENVIRONMENT_URLS[ENVIRONMENT]["token_url"],
auth_domain=auth_domain,
credential=credential,
authorization_server=AuthorizationServer(
authorize_url=ENVIRONMENT_URLS[ENVIRONMENT]["authorize_url"],
token_url=ENVIRONMENT_URLS[ENVIRONMENT]["token_url"],
),
)
@property
def name(self) -> str:
"""Name of the implementation."""
return f"{self._name}"
@property
def extra_authorize_data(self) -> dict:
"""Extra data that needs to be appended to the authorize url."""