mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Prefer use cloud url for oauth2 for Withings (#36348)
This commit is contained in:
parent
8ccdaf2927
commit
fcef259021
@ -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}"
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user