Expose session-header in case the home assistant ingress-server is used

This commit is contained in:
Paul Konstantin Gerke 2023-06-18 00:08:11 +02:00 committed by Christopher Charbonneau Wells
parent 1a946a2228
commit bb871257ff
3 changed files with 19 additions and 4 deletions

View File

@ -98,9 +98,9 @@ class HomeAssistant:
def __call__(self, request: HttpRequest):
def wrap_x_ingress_path(org_func):
if request.headers.get("HTTP_X_HASS_SOURCE") != "core.ingress":
if not request.is_homeassistant_ingress_request:
return org_func
x_ingress_path = request.headers.get("HTTP_X_INGRESS_PATH")
x_ingress_path = request.headers.get("X-Ingress-Path")
if x_ingress_path is None:
return org_func
@ -115,6 +115,10 @@ class HomeAssistant:
return url
return wrapper
request.is_homeassistant_ingress_request = (
request.headers.get("X-Hass-Source") == "core.ingress"
)
if self.use_x_ingress_path_rewrite:
request.build_absolute_uri = wrap_x_ingress_path(
request.build_absolute_uri

View File

@ -1,4 +1,4 @@
{% load i18n widget_tweaks babybuddy qr_code %}
{% url 'babybuddy:root-router' as relative_root_url %}
{% make_absolute_url relative_root_url as absolute_root_url %}
BABYBUDDY-LOGIN:{"url":"{{ absolute_root_url }}","api_key":"{{ user.settings.api_key }}"}
BABYBUDDY-LOGIN:{"url":"{{ absolute_root_url }}","api_key":"{{ user.settings.api_key }}","session-cookie":"{{ session_cookie }}"}

View File

@ -251,7 +251,18 @@ class UserAddDevice(LoginRequiredMixin, View):
qr_code_template = "babybuddy/login_qr_code.txt"
def get(self, request):
qr_code_response = render(request, self.qr_code_template)
session_cookie = ""
if request.is_homeassistant_ingress_request:
session_cookie = request.headers.get("Cookie", "")
qr_code_response = render(
request,
self.qr_code_template,
{
"session_cookie": session_cookie,
}
)
qr_code_data = qr_code_response.content.decode().strip()
return render(