Prefer use cloud url for oauth2 for Withings (#36348)

This commit is contained in:
Robert Van Gorkom authored and GitHub committed 2020-06-03 12:40:46 +02:00
1 parent 8ccdaf2927
commit fcef259021
3 files changed
+26 -4

No files matched your search

@@ -12,7 +12,12 @@ from homeassistant.helpers import config_entry_oauth2_flow, config_validation as
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
from . import config_flow
from .common import _LOGGER, NotAuthenticatedError, get_data_manager
from .common import (
_LOGGER,
NotAuthenticatedError,
WithingsLocalOAuth2Implementation,
get_data_manager,
)
from .const import CONF_PROFILES, CONFIG, CREDENTIALS, DOMAIN
CONFIG_SCHEMA = vol.Schema(
@@ -44,7 +49,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
config_flow.WithingsFlowHandler.async_register_implementation(
hass,
config_entry_oauth2_flow.LocalOAuth2Implementation(
WithingsLocalOAuth2Implementation(
hass,
DOMAIN,
conf[CONF_CLIENT_ID],
@@ -20,9 +20,12 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError, PlatformNotReady
from homeassistant.helpers.config_entry_oauth2_flow import (
AUTH_CALLBACK_PATH,
AbstractOAuth2Implementation,
LocalOAuth2Implementation,
OAuth2Session,
)
from homeassistant.helpers.network import get_url
from homeassistant.util import dt, slugify
from . import const
@@ -335,3 +338,13 @@ def get_data_manager(
)
return dm_dict[entry_id]
class WithingsLocalOAuth2Implementation(LocalOAuth2Implementation):
"""Oauth2 implementation that only uses the external url."""
@property
def redirect_uri(self) -> str:
"""Return the redirect uri."""
url = get_url(self.hass, allow_internal=False, prefer_cloud=True)
return f"{url}{AUTH_CALLBACK_PATH}"