mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Use the external URL set in Settings > System > Network if my is disabled as redirect URL for Google Drive instructions (#137791)
* Use the Assistant URL set in Settings > System > Network if my is disabled * fix * Remove async_get_redirect_uri
This commit is contained in:
parent
ae55e26546
commit
c370fa0489
@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
from homeassistant.components.application_credentials import AuthorizationServer
|
from homeassistant.components.application_credentials import AuthorizationServer
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import config_entry_oauth2_flow
|
from homeassistant.helpers.config_entry_oauth2_flow import (
|
||||||
|
AUTH_CALLBACK_PATH,
|
||||||
|
MY_AUTH_CALLBACK_PATH,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_get_authorization_server(hass: HomeAssistant) -> AuthorizationServer:
|
async def async_get_authorization_server(hass: HomeAssistant) -> AuthorizationServer:
|
||||||
@ -15,9 +18,14 @@ async def async_get_authorization_server(hass: HomeAssistant) -> AuthorizationSe
|
|||||||
|
|
||||||
async def async_get_description_placeholders(hass: HomeAssistant) -> dict[str, str]:
|
async def async_get_description_placeholders(hass: HomeAssistant) -> dict[str, str]:
|
||||||
"""Return description placeholders for the credentials dialog."""
|
"""Return description placeholders for the credentials dialog."""
|
||||||
|
if "my" in hass.config.components:
|
||||||
|
redirect_url = MY_AUTH_CALLBACK_PATH
|
||||||
|
else:
|
||||||
|
ha_host = hass.config.external_url or "https://YOUR_DOMAIN:PORT"
|
||||||
|
redirect_url = f"{ha_host}{AUTH_CALLBACK_PATH}"
|
||||||
return {
|
return {
|
||||||
"oauth_consent_url": "https://console.cloud.google.com/apis/credentials/consent",
|
"oauth_consent_url": "https://console.cloud.google.com/apis/credentials/consent",
|
||||||
"more_info_url": "https://www.home-assistant.io/integrations/google_drive/",
|
"more_info_url": "https://www.home-assistant.io/integrations/google_drive/",
|
||||||
"oauth_creds_url": "https://console.cloud.google.com/apis/credentials",
|
"oauth_creds_url": "https://console.cloud.google.com/apis/credentials",
|
||||||
"redirect_url": config_entry_oauth2_flow.async_get_redirect_uri(hass),
|
"redirect_url": redirect_url,
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
"""Test the Google Drive application_credentials."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant import setup
|
||||||
|
from homeassistant.components.google_drive.application_credentials import (
|
||||||
|
async_get_description_placeholders,
|
||||||
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("additional_components", "external_url", "expected_redirect_uri"),
|
||||||
|
[
|
||||||
|
([], "https://example.com", "https://example.com/auth/external/callback"),
|
||||||
|
([], None, "https://YOUR_DOMAIN:PORT/auth/external/callback"),
|
||||||
|
(["my"], "https://example.com", "https://my.home-assistant.io/redirect/oauth"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_description_placeholders(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
additional_components: list[str],
|
||||||
|
external_url: str | None,
|
||||||
|
expected_redirect_uri: str,
|
||||||
|
) -> None:
|
||||||
|
"""Test description placeholders."""
|
||||||
|
for component in additional_components:
|
||||||
|
assert await setup.async_setup_component(hass, component, {})
|
||||||
|
hass.config.external_url = external_url
|
||||||
|
placeholders = await async_get_description_placeholders(hass)
|
||||||
|
assert placeholders == {
|
||||||
|
"oauth_consent_url": "https://console.cloud.google.com/apis/credentials/consent",
|
||||||
|
"more_info_url": "https://www.home-assistant.io/integrations/google_drive/",
|
||||||
|
"oauth_creds_url": "https://console.cloud.google.com/apis/credentials",
|
||||||
|
"redirect_url": expected_redirect_uri,
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user