diff --git a/homeassistant/components/almond/manifest.json b/homeassistant/components/almond/manifest.json index 94203b46752..012450180ca 100644 --- a/homeassistant/components/almond/manifest.json +++ b/homeassistant/components/almond/manifest.json @@ -3,7 +3,7 @@ "name": "Almond", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/almond", - "dependencies": ["http", "conversation"], + "dependencies": ["auth", "conversation"], "codeowners": ["@gcampax", "@balloob"], "requirements": ["pyalmond==0.0.2"], "iot_class": "local_polling", diff --git a/homeassistant/components/auth/__init__.py b/homeassistant/components/auth/__init__.py index 4ddfccd032c..d6a351a4138 100644 --- a/homeassistant/components/auth/__init__.py +++ b/homeassistant/components/auth/__init__.py @@ -113,6 +113,12 @@ Result will be a long-lived access token: "result": "ABCDEFGH" } + +# POST /auth/external/callback + +This is an endpoint for OAuth2 Authorization callbacks used by integrations +that link accounts with other cloud providers using LocalOAuth2Implementation +as part of a config flow. """ from __future__ import annotations @@ -134,6 +140,7 @@ from homeassistant.components.http.ban import log_invalid_auth from homeassistant.components.http.data_validator import RequestDataValidator from homeassistant.components.http.view import HomeAssistantView from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers.config_entry_oauth2_flow import OAuth2AuthorizeCallbackView from homeassistant.helpers.typing import ConfigType from homeassistant.loader import bind_hass from homeassistant.util import dt as dt_util @@ -195,6 +202,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: hass.http.register_view(TokenView(retrieve_result)) hass.http.register_view(LinkUserView(retrieve_result)) + hass.http.register_view(OAuth2AuthorizeCallbackView()) websocket_api.async_register_command( hass, WS_TYPE_CURRENT_USER, websocket_current_user, SCHEMA_WS_CURRENT_USER diff --git a/homeassistant/components/google/manifest.json b/homeassistant/components/google/manifest.json index 589ecb25b21..07ebaa6f96e 100644 --- a/homeassistant/components/google/manifest.json +++ b/homeassistant/components/google/manifest.json @@ -2,7 +2,7 @@ "domain": "google", "name": "Google Calendars", "config_flow": true, - "dependencies": ["http"], + "dependencies": ["auth"], "documentation": "https://www.home-assistant.io/integrations/calendar.google/", "requirements": [ "google-api-python-client==2.38.0", diff --git a/homeassistant/components/home_connect/manifest.json b/homeassistant/components/home_connect/manifest.json index 784042f884c..e50053d2d1b 100644 --- a/homeassistant/components/home_connect/manifest.json +++ b/homeassistant/components/home_connect/manifest.json @@ -2,7 +2,7 @@ "domain": "home_connect", "name": "Home Connect", "documentation": "https://www.home-assistant.io/integrations/home_connect", - "dependencies": ["http"], + "dependencies": ["auth"], "codeowners": ["@DavidMStraub"], "requirements": ["homeconnect==0.7.0"], "config_flow": true, diff --git a/homeassistant/components/home_plus_control/manifest.json b/homeassistant/components/home_plus_control/manifest.json index 30ef34b6b34..bbfde5bbded 100644 --- a/homeassistant/components/home_plus_control/manifest.json +++ b/homeassistant/components/home_plus_control/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/home_plus_control", "requirements": ["homepluscontrol==0.0.5"], - "dependencies": ["http"], + "dependencies": ["auth"], "codeowners": ["@chemaaa"], "iot_class": "cloud_polling", "loggers": ["homepluscontrol"] diff --git a/homeassistant/components/lyric/manifest.json b/homeassistant/components/lyric/manifest.json index 146a3397297..da60b046eb7 100644 --- a/homeassistant/components/lyric/manifest.json +++ b/homeassistant/components/lyric/manifest.json @@ -3,7 +3,7 @@ "name": "Honeywell Lyric", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/lyric", - "dependencies": ["http"], + "dependencies": ["auth"], "requirements": ["aiolyric==1.0.8"], "codeowners": ["@timmo001"], "quality_scale": "silver", diff --git a/homeassistant/components/neato/manifest.json b/homeassistant/components/neato/manifest.json index b183548222d..f12f79c77a8 100644 --- a/homeassistant/components/neato/manifest.json +++ b/homeassistant/components/neato/manifest.json @@ -5,7 +5,7 @@ "documentation": "https://www.home-assistant.io/integrations/neato", "requirements": ["pybotvac==0.0.23"], "codeowners": ["@dshokouhi", "@Santobert"], - "dependencies": ["http"], + "dependencies": ["auth"], "iot_class": "cloud_polling", "loggers": ["pybotvac"] } diff --git a/homeassistant/components/nest/manifest.json b/homeassistant/components/nest/manifest.json index f59a8e6ac31..ce0b68c782a 100644 --- a/homeassistant/components/nest/manifest.json +++ b/homeassistant/components/nest/manifest.json @@ -2,7 +2,7 @@ "domain": "nest", "name": "Nest", "config_flow": true, - "dependencies": ["ffmpeg", "http"], + "dependencies": ["ffmpeg", "http", "auth"], "after_dependencies": ["media_source"], "documentation": "https://www.home-assistant.io/integrations/nest", "requirements": ["python-nest==4.2.0", "google-nest-sdm==1.8.0"], diff --git a/homeassistant/components/netatmo/manifest.json b/homeassistant/components/netatmo/manifest.json index 953ead88f33..565bd42594a 100644 --- a/homeassistant/components/netatmo/manifest.json +++ b/homeassistant/components/netatmo/manifest.json @@ -4,7 +4,7 @@ "documentation": "https://www.home-assistant.io/integrations/netatmo", "requirements": ["pyatmo==6.2.4"], "after_dependencies": ["cloud", "media_source"], - "dependencies": ["webhook"], + "dependencies": ["auth", "webhook"], "codeowners": ["@cgtobi"], "config_flow": true, "homekit": { diff --git a/homeassistant/components/ondilo_ico/manifest.json b/homeassistant/components/ondilo_ico/manifest.json index d3d9c7d1376..0fd542eab1d 100644 --- a/homeassistant/components/ondilo_ico/manifest.json +++ b/homeassistant/components/ondilo_ico/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/ondilo_ico", "requirements": ["ondilo==0.2.0"], - "dependencies": ["http"], + "dependencies": ["auth"], "codeowners": ["@JeromeHXP"], "iot_class": "cloud_polling", "loggers": ["ondilo"] diff --git a/homeassistant/components/smappee/manifest.json b/homeassistant/components/smappee/manifest.json index b9f94b94dde..5ab250aaf80 100644 --- a/homeassistant/components/smappee/manifest.json +++ b/homeassistant/components/smappee/manifest.json @@ -3,7 +3,7 @@ "name": "Smappee", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/smappee", - "dependencies": ["http"], + "dependencies": ["auth"], "requirements": ["pysmappee==0.2.29"], "codeowners": ["@bsmappee"], "zeroconf": [ diff --git a/homeassistant/components/somfy/manifest.json b/homeassistant/components/somfy/manifest.json index 144938b1822..76e3d281228 100644 --- a/homeassistant/components/somfy/manifest.json +++ b/homeassistant/components/somfy/manifest.json @@ -3,7 +3,7 @@ "name": "Somfy", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/somfy", - "dependencies": ["http"], + "dependencies": ["auth"], "codeowners": ["@tetienne"], "requirements": ["pymfy==0.11.0"], "zeroconf": [ diff --git a/homeassistant/components/spotify/manifest.json b/homeassistant/components/spotify/manifest.json index 9dcf1fee6dc..dd18a05bdc7 100644 --- a/homeassistant/components/spotify/manifest.json +++ b/homeassistant/components/spotify/manifest.json @@ -4,7 +4,7 @@ "documentation": "https://www.home-assistant.io/integrations/spotify", "requirements": ["spotipy==2.19.0"], "zeroconf": ["_spotify-connect._tcp.local."], - "dependencies": ["http"], + "dependencies": ["auth"], "codeowners": ["@frenck"], "config_flow": true, "quality_scale": "silver", diff --git a/homeassistant/components/toon/manifest.json b/homeassistant/components/toon/manifest.json index f6dc4ae2843..3edcae7f357 100644 --- a/homeassistant/components/toon/manifest.json +++ b/homeassistant/components/toon/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/toon", "requirements": ["toonapi==0.2.1"], - "dependencies": ["http"], + "dependencies": ["auth"], "after_dependencies": ["cloud"], "codeowners": [], "dhcp": [ diff --git a/homeassistant/components/withings/manifest.json b/homeassistant/components/withings/manifest.json index 8337068ba68..2e089bdbcc9 100644 --- a/homeassistant/components/withings/manifest.json +++ b/homeassistant/components/withings/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/withings", "requirements": ["withings-api==2.4.0"], - "dependencies": ["http", "webhook"], + "dependencies": ["auth", "http", "webhook"], "codeowners": ["@vangorra"], "iot_class": "cloud_polling", "loggers": ["withings_api"] diff --git a/homeassistant/components/xbox/manifest.json b/homeassistant/components/xbox/manifest.json index d02f9cc2279..432b3e84100 100644 --- a/homeassistant/components/xbox/manifest.json +++ b/homeassistant/components/xbox/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/xbox", "requirements": ["xbox-webapi==2.0.11"], - "dependencies": ["http"], + "dependencies": ["auth"], "codeowners": ["@hunterjm"], "iot_class": "cloud_polling" } diff --git a/homeassistant/helpers/config_entry_oauth2_flow.py b/homeassistant/helpers/config_entry_oauth2_flow.py index cf2d73715de..c2781a18797 100644 --- a/homeassistant/helpers/config_entry_oauth2_flow.py +++ b/homeassistant/helpers/config_entry_oauth2_flow.py @@ -32,7 +32,6 @@ from .network import NoURLAvailableError _LOGGER = logging.getLogger(__name__) DATA_JWT_SECRET = "oauth2_jwt_secret" -DATA_VIEW_REGISTERED = "oauth2_view_reg" DATA_IMPLEMENTATIONS = "oauth2_impl" DATA_PROVIDERS = "oauth2_providers" AUTH_CALLBACK_PATH = "/auth/external/callback" @@ -331,12 +330,6 @@ def async_register_implementation( hass: HomeAssistant, domain: str, implementation: AbstractOAuth2Implementation ) -> None: """Register an OAuth2 flow implementation for an integration.""" - if isinstance(implementation, LocalOAuth2Implementation) and not hass.data.get( - DATA_VIEW_REGISTERED, False - ): - hass.http.register_view(OAuth2AuthorizeCallbackView()) - hass.data[DATA_VIEW_REGISTERED] = True - implementations = hass.data.setdefault(DATA_IMPLEMENTATIONS, {}) implementations.setdefault(domain, {})[implementation.domain] = implementation diff --git a/script/scaffold/generate.py b/script/scaffold/generate.py index 8bde9504f41..a86c4e3a015 100644 --- a/script/scaffold/generate.py +++ b/script/scaffold/generate.py @@ -173,7 +173,7 @@ def _custom_tasks(template, info: Info) -> None: ) elif template == "config_flow_oauth2": - info.update_manifest(config_flow=True, dependencies=["http"]) + info.update_manifest(config_flow=True, dependencies=["auth"]) info.update_strings( config={ "step": { diff --git a/tests/helpers/test_config_entry_oauth2_flow.py b/tests/helpers/test_config_entry_oauth2_flow.py index ddd92bb943f..2cd3184b44b 100644 --- a/tests/helpers/test_config_entry_oauth2_flow.py +++ b/tests/helpers/test_config_entry_oauth2_flow.py @@ -26,7 +26,7 @@ TOKEN_URL = "https://example.como/auth/token" @pytest.fixture async def local_impl(hass): """Local implementation.""" - assert await setup.async_setup_component(hass, "http", {}) + assert await setup.async_setup_component(hass, "auth", {}) return config_entry_oauth2_flow.LocalOAuth2Implementation( hass, TEST_DOMAIN, CLIENT_ID, CLIENT_SECRET, AUTHORIZE_URL, TOKEN_URL )