Moved azure login to local app. Removed ability for new users to be created automatically

This commit is contained in:
John Mullins
2023-12-15 15:00:41 +11:00
parent 7519585c84
commit 1240ab2538
9 changed files with 247 additions and 3 deletions
+32
View File
@@ -0,0 +1,32 @@
from django.conf import settings
from django.shortcuts import redirect
from django.urls import reverse
from .handlers import AuthHandler
class AzureMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
public_views = ["azure_auth:login", "azure_auth:logout", "azure_auth:callback"]
public_views.extend(settings.AZURE_AUTH.get("PUBLIC_URLS", []))
public_urls = [reverse(view_name) for view_name in public_views]
public_paths = settings.AZURE_AUTH.get(
"PUBLIC_PATHS", []
) # added to resolve paths
if request.path_info in public_urls:
return self.get_response(request)
# Added to resolve paths that can't be reversed
for path in public_paths:
if request.path_info.startswith(path):
return self.get_response(request)
if AuthHandler(request).get_token_from_cache():
# If the user is authenticated
if request.user.is_authenticated:
return self.get_response(request)
return redirect("azure_auth:login")