-
Notifications
You must be signed in to change notification settings - Fork 14
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?
Conversation
When using multiple authentication methods in Django it must be possible to direct the users to a login page where they can select the needed authentication method.
503202b
to
a2335f4
Compare
Django 5.1 introduced the LoginRequiredMiddleware that automatically requires an authenticated user on all views except those marked as not requiring a login.
a2335f4
to
e7d1362
Compare
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.
I see what you're trying to do here but I just want to assure myself that this is the best way of implementing it.
@@ -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) |
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.
Shouldn't there be a check on self.request.user.is_authenticated
before returning?
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.
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 self.request.user.is_authenticated
here is probably equally valid.
# If the token is valid (or a new valid one can be generated) | ||
if AuthHandler(request).user_is_authenticated: | ||
return func(request, *args, **kwargs) | ||
elif active_auth_backend != "azure_auth.auth_backends.AzureBackend": | ||
# User is handled by another backend | ||
return func(request, *args, **kwargs) |
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_authenticated
before returning?
When using multiple authentication methods in Django it must be possible to direct the users to a login page where they can select the needed authentication method.