Support session/cookie based auth, see #1108

This commit is contained in:
Agate 2020-05-18 12:03:30 +02:00
parent a9ba323b13
commit 550dbe46cc
14 changed files with 172 additions and 62 deletions

View file

@ -10,6 +10,7 @@ import xml.sax.saxutils
from django import http
from django.conf import settings
from django.core.cache import caches
from django.middleware import csrf
from django import urls
from rest_framework import views
@ -81,7 +82,12 @@ def serve_spa(request):
body, tail = tail.split("</body>", 1)
css = "<style>{}</style>".format(css)
tail = body + "\n" + css + "\n</body>" + tail
return http.HttpResponse(head + tail)
# set a csrf token so that visitor can login / query API if needed
token = csrf.get_token(request)
response = http.HttpResponse(head + tail)
response.set_cookie("csrftoken", token, max_age=None)
return response
MANIFEST_LINK_REGEX = re.compile(r"<link [^>]*rel=(?:'|\")?manifest(?:'|\")?[^>]*>")