使用 python-social-auth 时不显示登录错误页面

Login-error page not displayed when using python-social-auth

我正在使用 social-app-django(python-social-auth 的一部分)为我的 Django 站点的用户实现 Facebook 登录。我有一个要求,用户必须先在本地用户数据库中找到,然后才能使用 Facebook 登录。我已经替换了身份验证管道的 auth_allowed-part,以执行此检查:

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)

其中 is_registered_user() 是一个自定义函数,用于检查用户是否存在于本地。

我的问题是 用户不会被重定向到登录错误 URL,如果此检查失败并抛出 AuthForbidden 异常。相反,网站 return 是 500。

错误页面URL在settings.py中配置如下:

LOGIN_ERROR_URL = "/"

我正在使用 Django CMS,所以我也尝试实现覆盖 SocialAuthExceptionMiddleware 的中间件(它应该在标准设置中处理 AuthForbidden 异常)到 return CMS 页面而不是 settings.py 中的 URL,但据我所知,此中间件未在此过程中调用。

关于如何解决这个问题有什么想法吗?我是否缺少某些配置?

我想我解决了问题:我不小心使用了

social.apps.django_app.middleware.SocialAuthExceptionMiddleware

而不是

social_django.middleware.SocialAuthExceptionMiddleware

当提到异常处理中间件时。该错误很可能是在一段时间前从 django-social-auth 升级到 python-social-auth/social-app-django 期间引入的。