Refactor to extend RemoteUserMiddleware & add authentication for Django

This commit is contained in:
Michael Shamoon
2021-01-03 21:21:39 -08:00
parent 8caa61bd9d
commit 0286abd92a
2 changed files with 17 additions and 20 deletions

View File

@@ -2,7 +2,7 @@ from django.conf import settings
from django.contrib.auth.models import User
from django.utils.deprecation import MiddlewareMixin
from rest_framework import authentication
from rest_framework import exceptions
from django.contrib.auth.middleware import RemoteUserMiddleware
class AutoLoginMiddleware(MiddlewareMixin):
@@ -29,19 +29,9 @@ class AngularApiAuthenticationOverride(authentication.BaseAuthentication):
return None
class HttpRemoteUserAuthentication(authentication.BaseAuthentication):
class HttpRemoteUserMiddleware(RemoteUserMiddleware):
""" This class allows authentication via HTTP_REMOTE_USER which is set for
example by certain SSO applications.
"""
def authenticate(self, request):
username = request.META.get('HTTP_REMOTE_USER')
if not username:
return None
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
raise exceptions.AuthenticationFailed('No such user')
return (user, None)
header = 'HTTP_REMOTE_USER'