diff --git a/custom_components/auth_oidc/__init__.py b/custom_components/auth_oidc/__init__.py index b49d574..355cc54 100644 --- a/custom_components/auth_oidc/__init__.py +++ b/custom_components/auth_oidc/__init__.py @@ -92,10 +92,13 @@ async def async_setup(hass: HomeAssistant, config): ) # 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 = 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(OIDCCallbackView(oidc_client, provider)) 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 # frontend injection feature enabled - if features_config.get("disable_frontend_changes", False) is False: + if is_frontend_injection_enabled: await OIDCInjectedAuthPage.inject(hass, name) else: _LOGGER.info("OIDC frontend changes are disabled, skipping injection") diff --git a/custom_components/auth_oidc/endpoints/welcome.py b/custom_components/auth_oidc/endpoints/welcome.py index a182d3f..66e1d5c 100644 --- a/custom_components/auth_oidc/endpoints/welcome.py +++ b/custom_components/auth_oidc/endpoints/welcome.py @@ -2,7 +2,7 @@ from aiohttp import web from homeassistant.components.http import HomeAssistantView -from ..helpers import get_view +from ..helpers import get_url, get_view PATH = "/auth/oidc/welcome" @@ -14,10 +14,15 @@ class OIDCWelcomeView(HomeAssistantView): url = PATH 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.is_enabled = not is_frontend_injection_enabled async def get(self, _: web.Request) -> web.Response: """Receive response.""" + + if not self.is_enabled: + return web.HTTPTemporaryRedirect(get_url("/")) + view_html = await get_view("welcome", {"name": self.name}) return web.Response(text=view_html, content_type="text/html") diff --git a/custom_components/auth_oidc/static/injection.js b/custom_components/auth_oidc/static/injection.js index 9612ae1..0f5de4b 100644 --- a/custom_components/auth_oidc/static/injection.js +++ b/custom_components/auth_oidc/static/injection.js @@ -133,6 +133,8 @@ function update() { ssoButton.style.marginRight = "1em" ssoButton.addEventListener("click", () => { location.href = "/auth/oidc/redirect" + ssoButton.innerHTML = "Redirecting, please wait..." + ssoButton.disabled = true }) loginButton.parentElement.prepend(ssoButton) }