python-social-auth AuthCanceled exception

前端 未结 7 688
礼貌的吻别
礼貌的吻别 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:59

    you can create a middleware and catch any exceptions, exception list: https://github.com/omab/python-social-auth/blob/master/social/exceptions.py in this case your AuthCanceled Exception.

    middleware.py

    
    
    from social.apps.django_app.middleware import SocialAuthExceptionMiddleware
    from django.shortcuts import HttpResponse
    from social import exceptions as social_exceptions
    
    class SocialAuthExceptionMiddleware(SocialAuthExceptionMiddleware):
        def process_exception(self, request, exception):
            if hasattr(social_exceptions, 'AuthCanceled'):
                return HttpResponse("I'm the Pony %s" % exception)
            else:
                raise exception
    
    
    

    settings.py

    
    
    MIDDLEWARE_CLASSES = (
            .....
            'pat_to_middleware.SocialAuthExceptionMiddleware',
    )
    
    
    
    0 讨论(0)
提交回复
热议问题