Disable welcome page if the new features are enabled (#86)

* Disable welcome page if frontend injection is enabled
* Make button indicate redirecting
This commit is contained in:
Christiaan Goossens
2025-07-13 20:07:47 +02:00
committed by GitHub
parent 27de2bcf71
commit 0888ea0400
3 changed files with 14 additions and 4 deletions

View File

@@ -92,10 +92,13 @@ async def async_setup(hass: HomeAssistant, config):
) )
# Register the views # Register the views
is_frontend_injection_enabled = (
features_config.get("disable_frontend_changes", False) is False
)
name = config[DOMAIN].get(DISPLAY_NAME, DEFAULT_TITLE) name = config[DOMAIN].get(DISPLAY_NAME, DEFAULT_TITLE)
name = re.sub(r"[^A-Za-z0-9 _\-\(\)]", "", name) name = re.sub(r"[^A-Za-z0-9 _\-\(\)]", "", name)
hass.http.register_view(OIDCWelcomeView(name)) hass.http.register_view(OIDCWelcomeView(name, is_frontend_injection_enabled))
hass.http.register_view(OIDCRedirectView(oidc_client)) hass.http.register_view(OIDCRedirectView(oidc_client))
hass.http.register_view(OIDCCallbackView(oidc_client, provider)) hass.http.register_view(OIDCCallbackView(oidc_client, provider))
hass.http.register_view(OIDCFinishView()) hass.http.register_view(OIDCFinishView())
@@ -104,7 +107,7 @@ async def async_setup(hass: HomeAssistant, config):
# Inject OIDC code into the frontend for /auth/authorize if the user has the # Inject OIDC code into the frontend for /auth/authorize if the user has the
# frontend injection feature enabled # frontend injection feature enabled
if features_config.get("disable_frontend_changes", False) is False: if is_frontend_injection_enabled:
await OIDCInjectedAuthPage.inject(hass, name) await OIDCInjectedAuthPage.inject(hass, name)
else: else:
_LOGGER.info("OIDC frontend changes are disabled, skipping injection") _LOGGER.info("OIDC frontend changes are disabled, skipping injection")

View File

@@ -2,7 +2,7 @@
from aiohttp import web from aiohttp import web
from homeassistant.components.http import HomeAssistantView from homeassistant.components.http import HomeAssistantView
from ..helpers import get_view from ..helpers import get_url, get_view
PATH = "/auth/oidc/welcome" PATH = "/auth/oidc/welcome"
@@ -14,10 +14,15 @@ class OIDCWelcomeView(HomeAssistantView):
url = PATH url = PATH
name = "auth:oidc:welcome" name = "auth:oidc:welcome"
def __init__(self, name: str) -> None: def __init__(self, name: str, is_frontend_injection_enabled: bool) -> None:
self.name = name self.name = name
self.is_enabled = not is_frontend_injection_enabled
async def get(self, _: web.Request) -> web.Response: async def get(self, _: web.Request) -> web.Response:
"""Receive response.""" """Receive response."""
if not self.is_enabled:
return web.HTTPTemporaryRedirect(get_url("/"))
view_html = await get_view("welcome", {"name": self.name}) view_html = await get_view("welcome", {"name": self.name})
return web.Response(text=view_html, content_type="text/html") return web.Response(text=view_html, content_type="text/html")

View File

@@ -133,6 +133,8 @@ function update() {
ssoButton.style.marginRight = "1em" ssoButton.style.marginRight = "1em"
ssoButton.addEventListener("click", () => { ssoButton.addEventListener("click", () => {
location.href = "/auth/oidc/redirect" location.href = "/auth/oidc/redirect"
ssoButton.innerHTML = "Redirecting, please wait..."
ssoButton.disabled = true
}) })
loginButton.parentElement.prepend(ssoButton) loginButton.parentElement.prepend(ssoButton)
} }