diff --git a/homeassistant/helpers/config_entry_oauth2_flow.py b/homeassistant/helpers/config_entry_oauth2_flow.py index d0aaca71304..2d45269a82c 100644 --- a/homeassistant/helpers/config_entry_oauth2_flow.py +++ b/homeassistant/helpers/config_entry_oauth2_flow.py @@ -25,6 +25,7 @@ from homeassistant import config_entries from homeassistant.components import http from homeassistant.core import HomeAssistant, callback from homeassistant.data_entry_flow import FlowResult +from homeassistant.loader import async_get_application_credentials from .aiohttp_client import async_get_clientsession from .network import NoURLAvailableError @@ -239,6 +240,8 @@ class AbstractOAuth2FlowHandler(config_entries.ConfigFlow, metaclass=ABCMeta): return await self.async_step_auth() if not implementations: + if self.DOMAIN in await async_get_application_credentials(self.hass): + return self.async_abort(reason="missing_credentials") return self.async_abort(reason="missing_configuration") req = http.current_request.get() diff --git a/homeassistant/strings.json b/homeassistant/strings.json index 9dcf8c7fe49..e4d363c22be 100644 --- a/homeassistant/strings.json +++ b/homeassistant/strings.json @@ -71,6 +71,7 @@ "webhook_not_internet_accessible": "Your Home Assistant instance needs to be accessible from the internet to receive webhook messages.", "oauth2_error": "Received invalid token data.", "oauth2_missing_configuration": "The component is not configured. Please follow the documentation.", + "oauth2_missing_credentials": "The integration requires application credentials.", "oauth2_authorize_url_timeout": "Timeout generating authorize URL.", "oauth2_no_url_available": "No URL available. For information about this error, [check the help section]({docs_url})", "reauth_successful": "Re-authentication was successful", diff --git a/tests/components/google/test_config_flow.py b/tests/components/google/test_config_flow.py index f061aeb3057..9339ca9988f 100644 --- a/tests/components/google/test_config_flow.py +++ b/tests/components/google/test_config_flow.py @@ -327,7 +327,7 @@ async def test_missing_configuration( DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result.get("type") == "abort" - assert result.get("reason") == "missing_configuration" + assert result.get("reason") == "missing_credentials" @pytest.mark.parametrize("google_config", [None]) @@ -342,7 +342,7 @@ async def test_missing_configuration_yaml_empty( DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result.get("type") == "abort" - assert result.get("reason") == "missing_configuration" + assert result.get("reason") == "missing_credentials" async def test_wrong_configuration( diff --git a/tests/components/spotify/test_config_flow.py b/tests/components/spotify/test_config_flow.py index e2f1878c04d..3b1e4851ff1 100644 --- a/tests/components/spotify/test_config_flow.py +++ b/tests/components/spotify/test_config_flow.py @@ -31,14 +31,14 @@ async def test_abort_if_no_configuration(hass): ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT - assert result["reason"] == "missing_configuration" + assert result["reason"] == "missing_credentials" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_ZEROCONF}, data=BLANK_ZEROCONF_INFO ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT - assert result["reason"] == "missing_configuration" + assert result["reason"] == "missing_credentials" async def test_zeroconf_abort_if_existing_entry(hass): diff --git a/tests/components/yolink/test_config_flow.py b/tests/components/yolink/test_config_flow.py index 4dd347f4076..5d6bb8fd727 100644 --- a/tests/components/yolink/test_config_flow.py +++ b/tests/components/yolink/test_config_flow.py @@ -25,7 +25,7 @@ async def test_abort_if_no_configuration(hass): DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT - assert result["reason"] == "missing_configuration" + assert result["reason"] == "missing_credentials" async def test_abort_if_existing_entry(hass: HomeAssistant): diff --git a/tests/helpers/test_config_entry_oauth2_flow.py b/tests/helpers/test_config_entry_oauth2_flow.py index 97e728d022d..248f3b8dbb0 100644 --- a/tests/helpers/test_config_entry_oauth2_flow.py +++ b/tests/helpers/test_config_entry_oauth2_flow.py @@ -114,6 +114,17 @@ async def test_abort_if_no_implementation(hass, flow_handler): assert result["reason"] == "missing_configuration" +async def test_missing_credentials_for_domain(hass, flow_handler): + """Check flow abort for integration supporting application credentials.""" + flow = flow_handler() + flow.hass = hass + + with patch("homeassistant.loader.APPLICATION_CREDENTIALS", [TEST_DOMAIN]): + result = await flow.async_step_user() + assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT + assert result["reason"] == "missing_credentials" + + async def test_abort_if_authorization_timeout( hass, flow_handler, local_impl, current_request_with_host ):