I am using social-app-django (part of python-social-auth) to implement Facebook login for the users of my Django site. I have a requirement that users must be found in the local user database before they can log in with Facebook. I have replaced the auth_allowed-part of the authentication pipeline, to perform this check:
def auth_allowed(backend, details, response, *args, **kwargs):
if not backend.auth_allowed(response, details) or not is_registered_user(response, details):
raise AuthForbidden(backend)
where is_registered_user()
is a custom function that checks whether the user exists locally.
My problem is that the users are not redirected to the login error URL , if this check fails and the AuthForbidden
exception is thrown. Instead, the site returns a 500.
The error-page URL is configured as follows in settings.py:
LOGIN_ERROR_URL = "/"
I am using Django CMS, so I have also tried implementing middleware that overwrites SocialAuthExceptionMiddleware
(which is supposed to handle the AuthForbidden
exception in a standard setup) to return a CMS-page instead of an URL from settings.py but this middleware is not invoked in the process, as far as I can see.
Any ideas on how to fix this? Am I missing some configuration?
I think I solved the problem: I accidentally used
social.apps.django_app.middleware.SocialAuthExceptionMiddleware
instead of
social_django.middleware.SocialAuthExceptionMiddleware
when referring to the exception-handling middleware. The bug was most likely introduced during an upgrade from django-social-auth
to python-social-auth
/ social-app-django
some time ago.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.