-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
feat(mfa): Add RequireMFAMiddleware #3710
Conversation
…o-allauth into add_mfa_require_middleware
Has anyone had a chance to look at this? Or am I missing a step to get this into review? |
I must admit, I am not sure about this approach -- whether or not a middleware is the best way forward. For example, another way of nudging users into turning on MFA would be to add a login stage that must be completed before the user can proceed. Also, the scope of such functionality is more about policies than authentication, and without a clear de facto way of handling things I am not sure it is wise to bring that into allauth. As for implementation, the |
Fair enough. I hadn't thought of adding this as a login stage. Trying that out just now, however, it seems that you would end up in an infinite loop since MFA set-up requires reauthentication? |
Yeah, that won't be trivial either. For now, let's leave this all out of scope... |
@jmsmkn I should have done a better job at explaining the reasoning. Here goes, hopefully. First, the implementation over at #3710 is not without issues. It uses a middleware, with an Another way of implementing this would be to gently nudge the user to turn on MFA when the user signs in. Perhaps even allowing for a time window of a few days before this kicks in as mandatory. And, in case you are solely doing this for staff users, perhaps another way of handling this would be to override Which leads me to the "Clear de facto way of handling things" remark -- given that there may be multiple approaches to the problem, and given that the proposed solution is not trivial, I prefer to not take that on board. It is really rather trivial for any project to add this middleware themselves, it's just a 60 lines or so middleware. On the short term, I would be open to adding a more simple solution, e.g. a |
Just to add some color to this issue, the @mfa_required solution unfortunately wouldn't work for our use case. As a SaaS product, we allow users or organizations to optionally require MFA for their accounts or for members of their organization. Rather than having MFA required based on which view we're hitting, we need to require MFA based on which user is hitting the view. That's where having a middleware solution built-in (where we could tailor how to set The maintenence complexity makes sense, but I don't think this kind of middleware needs to be out-of-scope as a feature and seems like it may be a relatively common pattern and as you note it's not super complex, so including it as an option out-of-the box like in this issue would let allauth be a more complete MFA solution. |
This implementation was worked on independently, but it does bear a lot of resemblance to https://github.com/valohai/django-allauth-2fa/blob/main/allauth_2fa/middleware.py simply because there isn't really a different way of implementing middleware like this. Up to you whether and how you would want to reference the other implementation.
Submitting Pull Requests
General
Examples:
"fix(google): Fixed foobar bug"
,"feat(accounts): Added foobar feature"
.ChangeLog.rst
.AUTHORS
.Provider Specifics
In case you add a new provider:
test_settings.py::INSTALLED_APPS
anddocs/installation.rst::INSTALLED_APPS
.docs/providers/<provider name>.rst
anddocs/providers/index.rst
Provider Specifics toctree.docs/overview.rst
.