Skip to content

Commit

Permalink
Basic/TokenAuth: re-initialize is_explicit_auth before the start of…
Browse files Browse the repository at this point in the history
… each request
  • Loading branch information
jontsai committed Jul 29, 2024
1 parent bf22572 commit 045c63a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions apps/accounts/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
authenticate,
logout,
)
from django.http import HttpResponse
from django.utils.deprecation import MiddlewareMixin

# Django Extensions Imports
Expand Down Expand Up @@ -59,9 +60,8 @@ def _handle_auth_flow(self, request, auth_user=None):
)
):
request.user = None
logout(request)
# TODO: redirect user or display error?
pass
logout(request)
else:
# no security violations
pass
Expand All @@ -77,6 +77,10 @@ def _handle_auth_flow(self, request, auth_user=None):
# processed regularly, or denied
pass

def process_request(self, request):
# re-initialize `is_explicit_auth` as `False` for each request
self.is_explicit_auth = False

def process_response(self, request, response):
"""Checks whether in an explicit authorization flow
Expand All @@ -98,6 +102,7 @@ class HtkBasicAuthMiddleware(BaseHtkAuthMiddleware):
"""

def process_request(self, request):
super().process_request(request)
auth_user = None

if 'HTTP_AUTHORIZATION' in request.META:
Expand Down Expand Up @@ -145,6 +150,8 @@ class HtkUserTokenAuthMiddleware(BaseHtkAuthMiddleware):
"""

def process_request(self, request):
super().process_request(request)

if 'HTTP_AUTHORIZATION' in request.META:
self.is_explicit_auth = True
auth_header = request.META['HTTP_AUTHORIZATION']
Expand Down

0 comments on commit 045c63a

Please sign in to comment.