Skip to content

Commit

Permalink
Merge pull request #9 from JanaPradacova/KNJ-15941-fix-authorization-…
Browse files Browse the repository at this point in the history
…header-missing-response

KNJ-15941 Fix 500 response for missing header
  • Loading branch information
xdaniel3 authored Mar 4, 2024
2 parents 0ae277b + b497f74 commit f9f94ae
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions chamber/multidomains/auth/middleware.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import logging

from django.core.exceptions import PermissionDenied
from django.http import HttpResponse
from django.utils.functional import SimpleLazyObject

from auth_token import utils # pylint: disable=E0401
Expand All @@ -10,6 +14,9 @@
from chamber.shortcuts import get_object_or_none


logger = logging.getLogger(__name__)


def get_token(request):
"""
Returns the token model instance associated with the given request token key.
Expand All @@ -34,3 +41,12 @@ def process_request(self, request):
request.token = get_token(request)
request.user = SimpleLazyObject(lambda: get_user(request))
request._dont_enforce_csrf_checks = dont_enforce_csrf_checks(request) # pylint: disable=W0212

def __call__(self, request):
try:
response = super().__call__(request)
except PermissionDenied as exp:
logger.warning(str(exp))
response = HttpResponse("Unauthorized", status=401)

return response

0 comments on commit f9f94ae

Please sign in to comment.