Fix 500 on redirect path (#201)

* Fix 500 on redirect path

Co-authored-by: anntnzrb <anntnzrb@proton.me>
This commit is contained in:
Christiaan Goossens
2026-02-06 11:07:46 +01:00
committed by GitHub
parent b2d07c28f0
commit 6f93a22c37
4 changed files with 8 additions and 4 deletions

View File

@@ -64,7 +64,9 @@ async def frontend_injection(hass: HomeAssistant, sso_name: str) -> None:
# Inject JS and register that route # Inject JS and register that route
injection_js = "<script src='/auth/oidc/static/injection.js?v=3'></script>" injection_js = "<script src='/auth/oidc/static/injection.js?v=3'></script>"
sso_name_js = f"<script>window.sso_name = {json.dumps(sso_name)};</script>" sso_name_js = f"<script>window.sso_name = {json.dumps(sso_name)};</script>"
frontend_code = frontend_code.replace("</body>", f"{injection_js}{sso_name_js}</body>") frontend_code = frontend_code.replace(
"</body>", f"{injection_js}{sso_name_js}</body>"
)
await hass.http.async_register_static_paths( await hass.http.async_register_static_paths(
[ [

View File

@@ -24,9 +24,8 @@ class OIDCRedirectView(HomeAssistantView):
async def get(self, _: web.Request) -> web.Response: async def get(self, _: web.Request) -> web.Response:
"""Receive response.""" """Receive response."""
redirect_uri = get_url("/auth/oidc/callback", self.force_https)
try: try:
redirect_uri = get_url("/auth/oidc/callback", self.force_https)
auth_url = await self.oidc_client.async_get_authorization_url(redirect_uri) auth_url = await self.oidc_client.async_get_authorization_url(redirect_uri)
if auth_url: if auth_url:

View File

@@ -43,3 +43,6 @@ packages = ["custom_components/auth_oidc"]
asyncio_mode = "auto" asyncio_mode = "auto"
addopts = "--cov=custom_components --cov-fail-under=0" addopts = "--cov=custom_components --cov-fail-under=0"
log_level = "DEBUG" log_level = "DEBUG"
[tool.ruff]
target-version = "py313"

View File

@@ -149,4 +149,4 @@ async def test_frontend_injection(hass: HomeAssistant, hass_client):
text = await resp.text() text = await resp.text()
assert "<script src='/auth/oidc/static/injection.js" in text assert "<script src='/auth/oidc/static/injection.js" in text
assert "window.sso_name = \"OpenID Connect (SSO)\";" in text assert 'window.sso_name = "OpenID Connect (SSO)";' in text