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

This commit is contained in:
Robert Van Gorkom 2020-06-03 03:40:46 -07:00 committed by GitHub
parent 8ccdaf2927
commit fcef259021
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 4 deletions

View File

@ -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],

View File

@ -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}"

View File

@ -22,6 +22,7 @@ from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import (
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_EXTERNAL_URL,
CONF_UNIT_SYSTEM,
CONF_UNIT_SYSTEM_METRIC,
)
@ -56,8 +57,11 @@ async def setup_hass(hass: HomeAssistant) -> dict:
profiles = ["Person0", "Person1", "Person2", "Person3", "Person4"]
hass_config = {
"homeassistant": {CONF_UNIT_SYSTEM: CONF_UNIT_SYSTEM_METRIC},
api.DOMAIN: {"base_url": "http://localhost/"},
"homeassistant": {
CONF_UNIT_SYSTEM: CONF_UNIT_SYSTEM_METRIC,
CONF_EXTERNAL_URL: "http://example.local/",
},
api.DOMAIN: {},
http.DOMAIN: {"server_port": 8080},
const.DOMAIN: {
CONF_CLIENT_ID: "my_client_id",