Code quality improvements (v0.2.0-pre-alpha) (#5)

* Bumped version to 0.2.0
* Implemented Github Actions for HACS, Hassfest, Linting
* Improved code quality (compliant with the linter now)
* Added link to the finish page to automatically login on the same device/browser
This commit is contained in:
Christiaan Goossens
2024-12-27 00:20:38 +01:00
committed by GitHub
parent a30d42ffce
commit b4a08b17ab
18 changed files with 1148 additions and 278 deletions

View File

@@ -1,10 +1,12 @@
from aiohttp import web
"""Finish route to allow the user to view their code."""
from homeassistant.components.http import HomeAssistantView
import logging
from aiohttp import web
from ..helpers import get_url
PATH = "/auth/oidc/finish"
_LOGGER = logging.getLogger(__name__)
class OIDCFinishView(HomeAssistantView):
"""OIDC Plugin Finish View."""
@@ -17,8 +19,20 @@ class OIDCFinishView(HomeAssistantView):
"""Receive response."""
code = request.query.get("code", "FAIL")
link = get_url("/")
return web.Response(
headers={"content-type": "text/html"},
text=f"<h1>Done!</h1><p>Your code is: <b>{code}</b></p><p>Please return to the Home Assistant login screen (or your mobile app) and fill in this code into the single login field. It should be visible if you select 'Login with OpenID Connect (SSO)'.</p>",
)
headers={
"content-type": "text/html",
"set-cookie": "auth_oidc_code="
+ code
+ "; Path=/auth/login_flow; SameSite=Strict; HttpOnly; Max-Age=300",
},
text=f"<h1>Done!</h1><p>Your code is: <b>{code}</b></p>"
+ "<p>Please return to the Home Assistant login "
+ "screen (or your mobile app) and fill in this code into the single login field. "
+ "It should be visible if you "
+ "select 'Login with OpenID Connect (SSO)'.</p><p><a href='"
+ link
+ "'>Click here to login automatically (on desktop).</a></p>",
)