pennersr / django-allauth

Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication.
https://allauth.org
MIT License
9.54k stars 3.03k forks source link

[Password Reset] Prevent reset requests for "social only" users #4011

Closed mecampbellsoup closed 3 months ago

mecampbellsoup commented 3 months ago

In some cases, users in our application will have joined an existing organization via e.g. SAML configuration (a SocialApp), and thus user.has_usable_password is False and user.socialaccount_set contains 1 SocialAccount that was produced/persisted by way of signing up w/ the previously mentioned SAML SocialApp instance.

We are interested in enabling some configuration to our customers so they can say, "My organization's users should only be able to signup and login via this SAML application." Is there any existing configuration to enforce that, so included but not limited to:

Currently it is possible for a user for whom user.has_usable_password is False to reset their password, and set a usable password, thereby allowing "local" login to their "social only" user account. (This is how our legacy app works, but in our new app we are making things more enterprise-focused and adding controls that give our customers more security features like enforcing SAML SSO authentication, etc.)

pennersr commented 3 months ago

There is no direct configuration for that, though you can easily override e.g. the ResetPasswordForm.clean_email() method to lookup the user from the email and handle things from there. There is also the adapter clean_password(self, password, user=None) method you can hookup to to reject moving from an unusable password.

I can imagine a allauth.policies sort of app at some future point in time handling account policies, including e.g. MFA restriction, but for now that's out of scope.

mecampbellsoup commented 2 months ago

you can easily override e.g. the ResetPasswordForm.clean_email() method to lookup the user from the email and handle things from there.

Will this work w/ headless endpoint as well? (I can of course play around and answer myself but wanted to include in this discussion for any future readers that may come along.) It looks like the answer is "yes" as the headless RequestPasswordResetInput inherits from ResetPasswordForm.