diff --git a/homeassistant/components/almond/manifest.json b/homeassistant/components/almond/manifest.json index 94203b46752f..012450180cab 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 4ddfccd032c3..d6a351a41380 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 589ecb25b212..07ebaa6f96e8 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 784042f884c1..e50053d2d1b7 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 30ef34b6b344..bbfde5bbded2 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 146a33972971..da60b046eb78 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 b183548222dd..f12f79c77a83 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 f59a8e6ac31a..ce0b68c782a5 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 953ead88f33c..565bd42594a9 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 d3d9c7d13761..0fd542eab1d0 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 b9f94b94dde6..5ab250aaf809 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 144938b18225..76e3d281228f 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 9dcf1fee6dc1..dd18a05bdc73 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 f6dc4ae28432..3edcae7f3574 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 8337068ba68d..2e089bdbcc91 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 d02f9cc2279b..432b3e841002 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 cf2d73715dec..c2781a18797c 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 8bde9504f410..a86c4e3a015b 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 ddd92bb943f4..2cd3184b44b7 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 )