Expose ingress_session in qrcode to allow logins to babybuddy exposed via homeassistant ingress

This commit is contained in:
Paul Konstantin Gerke 2023-06-25 18:39:20 +02:00 committed by Christopher Charbonneau Wells
parent bb871257ff
commit a37258db1a
2 changed files with 8 additions and 4 deletions

View File

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

View File

@ -1,4 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import json
from django.contrib import messages from django.contrib import messages
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.auth import update_session_auth_hash from django.contrib.auth import update_session_auth_hash
@ -251,15 +253,17 @@ class UserAddDevice(LoginRequiredMixin, View):
qr_code_template = "babybuddy/login_qr_code.txt" qr_code_template = "babybuddy/login_qr_code.txt"
def get(self, request): def get(self, request):
session_cookie = "" session_cookies = {}
if request.is_homeassistant_ingress_request: if request.is_homeassistant_ingress_request:
session_cookie = request.headers.get("Cookie", "") session_cookies["ingress_session"] = (
request.COOKIES.get("ingress_session")
)
qr_code_response = render( qr_code_response = render(
request, request,
self.qr_code_template, self.qr_code_template,
{ {
"session_cookie": session_cookie, "session_cookies": json.dumps(session_cookies)
} }
) )