python-social-auth AuthCanceled exception

前端 未结 7 686
礼貌的吻别
礼貌的吻别 2020-12-15 17:24

I\'m using python-social-auth in my Django application for authentication via Facebook. But when a user tries to login, they have been redirected to the Facebook app page, a

7条回答
  •  有刺的猬
    2020-12-15 17:46

    This is slight modification of @Nicolas answer and this works for me.

    middleware.py

    from social.apps.django_app.middleware import SocialAuthExceptionMiddleware
    from django.shortcuts import render
    from social.exceptions import AuthCanceled
    
    class SocialAuthExceptionMiddleware(SocialAuthExceptionMiddleware):
        def process_exception(self, request, exception):
            if type(exception) == AuthCanceled:
                return render(request, "pysocial/authcancelled.html", {})
            else:
                pass
    

    settings.py

    MIDDLEWARE_CLASSES += (
    'myapp.middleware.SocialAuthExceptionMiddleware',
    )
    

提交回复
热议问题