From 63e24f84cc1c0250ee5fa57c7f624bbed12e0221 Mon Sep 17 00:00:00 2001 From: tronikos Date: Fri, 9 Dec 2022 17:27:34 +0000 Subject: [PATCH] Remove async_entry_has_scopes check This is not needed. This was copied from google calendar integration where it was needed to reauth when the scope changed. --- .../components/google_sheets/__init__.py | 10 +------ .../components/google_sheets/config_flow.py | 4 +-- .../components/google_sheets/const.py | 1 - tests/components/google_sheets/test_init.py | 26 ------------------- 4 files changed, 3 insertions(+), 38 deletions(-) diff --git a/homeassistant/components/google_sheets/__init__.py b/homeassistant/components/google_sheets/__init__.py index 19f5ce81f5c..3b4ecfc649f 100644 --- a/homeassistant/components/google_sheets/__init__.py +++ b/homeassistant/components/google_sheets/__init__.py @@ -21,7 +21,7 @@ from homeassistant.helpers.config_entry_oauth2_flow import ( import homeassistant.helpers.config_validation as cv from homeassistant.helpers.selector import ConfigEntrySelector -from .const import DATA_CONFIG_ENTRY, DEFAULT_ACCESS, DOMAIN +from .const import DATA_CONFIG_ENTRY, DOMAIN DATA = "data" WORKSHEET = "worksheet" @@ -51,9 +51,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: raise ConfigEntryNotReady from err except aiohttp.ClientError as err: raise ConfigEntryNotReady from err - - if not async_entry_has_scopes(hass, entry): - raise ConfigEntryAuthFailed("Required scopes are not present, reauth required") hass.data.setdefault(DOMAIN, {})[entry.entry_id] = session await async_setup_service(hass) @@ -61,11 +58,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return True -def async_entry_has_scopes(hass: HomeAssistant, entry: ConfigEntry) -> bool: - """Verify that the config entry desired scope is present in the oauth token.""" - return DEFAULT_ACCESS in entry.data.get(CONF_TOKEN, {}).get("scope", "").split(" ") - - async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" hass.data[DOMAIN].pop(entry.entry_id) diff --git a/homeassistant/components/google_sheets/config_flow.py b/homeassistant/components/google_sheets/config_flow.py index 3805ee9d38b..a4ec42e6e24 100644 --- a/homeassistant/components/google_sheets/config_flow.py +++ b/homeassistant/components/google_sheets/config_flow.py @@ -13,7 +13,7 @@ from homeassistant.const import CONF_ACCESS_TOKEN, CONF_TOKEN from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers import config_entry_oauth2_flow -from .const import DEFAULT_ACCESS, DEFAULT_NAME, DOMAIN +from .const import DEFAULT_NAME, DOMAIN _LOGGER = logging.getLogger(__name__) @@ -36,7 +36,7 @@ class OAuth2FlowHandler( def extra_authorize_data(self) -> dict[str, Any]: """Extra data that needs to be appended to the authorize url.""" return { - "scope": DEFAULT_ACCESS, + "scope": "https://www.googleapis.com/auth/drive.file", # Add params to ensure we get back a refresh token "access_type": "offline", "prompt": "consent", diff --git a/homeassistant/components/google_sheets/const.py b/homeassistant/components/google_sheets/const.py index f8f065972f9..56b29ed6430 100644 --- a/homeassistant/components/google_sheets/const.py +++ b/homeassistant/components/google_sheets/const.py @@ -7,4 +7,3 @@ DOMAIN = "google_sheets" DATA_CONFIG_ENTRY: Final = "config_entry" DEFAULT_NAME = "Google Sheets" -DEFAULT_ACCESS = "https://www.googleapis.com/auth/drive.file" diff --git a/tests/components/google_sheets/test_init.py b/tests/components/google_sheets/test_init.py index f77edcbb491..14fe96fe6b4 100644 --- a/tests/components/google_sheets/test_init.py +++ b/tests/components/google_sheets/test_init.py @@ -95,32 +95,6 @@ async def test_setup_success( assert not len(hass.services.async_services().get(DOMAIN, {})) -@pytest.mark.parametrize( - "scopes", - [ - [], - [ - "https://www.googleapis.com/auth/drive.file+plus+extra" - ], # Required scope is a prefix - ["https://www.googleapis.com/auth/drive.readonly"], - ], - ids=["no_scope", "required_scope_prefix", "other_scope"], -) -async def test_missing_required_scopes_requires_reauth( - hass: HomeAssistant, setup_integration: ComponentSetup -) -> None: - """Test that reauth is invoked when required scopes are not present.""" - await setup_integration() - - entries = hass.config_entries.async_entries(DOMAIN) - assert len(entries) == 1 - assert entries[0].state is ConfigEntryState.SETUP_ERROR - - flows = hass.config_entries.flow.async_progress() - assert len(flows) == 1 - assert flows[0]["step_id"] == "reauth_confirm" - - @pytest.mark.parametrize("expires_at", [time.time() - 3600], ids=["expired"]) async def test_expired_token_refresh_success( hass: HomeAssistant,