-
Notifications
You must be signed in to change notification settings - Fork 15
Improve compatibility with multiple auth methods #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| from urllib.parse import urlparse | ||
|
|
||
| from django.conf import settings | ||
| from django.contrib.auth import BACKEND_SESSION_KEY | ||
| from django.http import HttpRequest | ||
| from django.shortcuts import redirect | ||
| from django.urls import reverse | ||
|
|
@@ -19,6 +20,8 @@ def __init__(self, get_response): | |
| ) # added to resolve paths | ||
|
|
||
| def __call__(self, request: HttpRequest): | ||
| active_auth_backend = request.session.get(BACKEND_SESSION_KEY, "") | ||
|
|
||
| if request.path_info in self.public_urls: | ||
| return self.get_response(request) | ||
|
|
||
|
|
@@ -29,6 +32,12 @@ def __call__(self, request: HttpRequest): | |
|
|
||
| if AuthHandler(request).user_is_authenticated: | ||
| return self.get_response(request) | ||
| elif active_auth_backend != "azure_auth.auth_backends.AzureBackend": | ||
| # User is handled by another backend | ||
| return self.get_response(request) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't there be a check on
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure. In our case we have a second middleware together with a second authentication backend. So each middleware is only checking the accounts that belong to it's backend. But checking |
||
|
|
||
| if settings.AZURE_AUTH.get("USE_LOGIN_URL", False): | ||
| return redirect(f"{settings.LOGIN_URL}?next={urlparse(request.path).path}") | ||
|
|
||
| return redirect( | ||
| f"{reverse('azure_auth:login')}?next={urlparse(request.path).path}" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as for in the middleware - shouldn't there be a check on
self.request.user.is_authenticatedbefore returning?