Fix nginx_jwt_resp HTTP responses

This commit is contained in:
Aarni Halinen
2022-07-28 01:04:38 +03:00
parent 6e74548206
commit 4419f1cf2c
+2 -2
View File
@@ -339,13 +339,13 @@ class SignupViewSet(ModelViewSet):
def nginx_jwt_resp(request, *args, **kwargs):
accessKey = request.COOKIES.get("jwt_access", None)
if not accessKey:
return HttpResponse("", status=401)
return HttpResponse("No valid access token", status=401)
try:
# This also verifies the signature.
# See https://pyjwt.readthedocs.io/en/latest/usage.html#reading-the-claimset-without-validation
token = decode(accessKey, settings.SECRET_KEY, algorithms=["HS256"])
except InvalidTokenError:
return HttpResponse("", status=403)
return HttpResponse("Invalid access token", status=401)
user = "admin" if token.get("username", "") == "admin" else "moderator"
resp = HttpResponse("", status=200)
resp["X-FBrowser-User"] = user