Skip to content

Conversation

@tobiasge
Copy link
Contributor

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.

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.
Django 5.1 introduced the LoginRequiredMiddleware that automatically
requires an authenticated user on all views except those marked as
not requiring a login.
Copy link
Collaborator

@regoawt regoawt left a 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.

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)
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

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)
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants