mirror of
https://github.com/home-assistant/core
synced 2024-09-09 12:51:22 +02:00
Fix Withings authentication to leverage default redirect URI (#79158)
This commit is contained in:
parent
7c448416e1
commit
d8a15f3dda
@ -44,12 +44,10 @@ from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
|||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import config_entry_oauth2_flow, entity_registry as er
|
from homeassistant.helpers import config_entry_oauth2_flow, entity_registry as er
|
||||||
from homeassistant.helpers.config_entry_oauth2_flow import (
|
from homeassistant.helpers.config_entry_oauth2_flow import (
|
||||||
AUTH_CALLBACK_PATH,
|
|
||||||
AbstractOAuth2Implementation,
|
AbstractOAuth2Implementation,
|
||||||
OAuth2Session,
|
OAuth2Session,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.network import get_url
|
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
from homeassistant.util import dt
|
from homeassistant.util import dt
|
||||||
|
|
||||||
@ -1084,12 +1082,6 @@ def get_platform_attributes(platform: str) -> tuple[WithingsAttribute, ...]:
|
|||||||
class WithingsLocalOAuth2Implementation(AuthImplementation):
|
class WithingsLocalOAuth2Implementation(AuthImplementation):
|
||||||
"""Oauth2 implementation that only uses the external url."""
|
"""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}"
|
|
||||||
|
|
||||||
async def _token_request(self, data: dict) -> dict:
|
async def _token_request(self, data: dict) -> dict:
|
||||||
"""Make a token request and adapt Withings API reply."""
|
"""Make a token request and adapt Withings API reply."""
|
||||||
new_token = await super()._token_request(data)
|
new_token = await super()._token_request(data)
|
||||||
|
@ -201,14 +201,14 @@ class ComponentFactory:
|
|||||||
self._hass,
|
self._hass,
|
||||||
{
|
{
|
||||||
"flow_id": result["flow_id"],
|
"flow_id": result["flow_id"],
|
||||||
"redirect_uri": "http://127.0.0.1:8080/auth/external/callback",
|
"redirect_uri": "https://example.com/auth/external/callback",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert result["type"] == data_entry_flow.FlowResultType.EXTERNAL_STEP
|
assert result["type"] == data_entry_flow.FlowResultType.EXTERNAL_STEP
|
||||||
assert result["url"] == (
|
assert result["url"] == (
|
||||||
"https://account.withings.com/oauth2_user/authorize2?"
|
"https://account.withings.com/oauth2_user/authorize2?"
|
||||||
f"response_type=code&client_id={self._client_id}&"
|
f"response_type=code&client_id={self._client_id}&"
|
||||||
"redirect_uri=http://127.0.0.1:8080/auth/external/callback&"
|
"redirect_uri=https://example.com/auth/external/callback&"
|
||||||
f"state={state}"
|
f"state={state}"
|
||||||
"&scope=user.info,user.metrics,user.activity,user.sleepevents"
|
"&scope=user.info,user.metrics,user.activity,user.sleepevents"
|
||||||
)
|
)
|
||||||
|
@ -13,7 +13,10 @@ from tests.test_util.aiohttp import AiohttpClientMocker
|
|||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def component_factory(
|
def component_factory(
|
||||||
hass: HomeAssistant, hass_client_no_auth, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant,
|
||||||
|
hass_client_no_auth,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
current_request_with_host: None,
|
||||||
):
|
):
|
||||||
"""Return a factory for initializing the withings component."""
|
"""Return a factory for initializing the withings component."""
|
||||||
with patch(
|
with patch(
|
||||||
|
Loading…
Reference in New Issue
Block a user