Debugging django-allauth Social Network Login Failure

后端 未结 6 1623
温柔的废话
温柔的废话 2020-12-11 06:43

When using django-allauth to do an OAuth login via a social provider, sometimes it fails with the error page \"Social Network Login Failure\". There is no log output contai

6条回答
  •  忘掉有多难
    2020-12-11 07:31

    If you use a custom SocialAccountAdapter (can be set in your settings.py, read more here) then you can simply overwrite the function authentication_error to log all of the errors.

    The function signature (source here) looks like this:

    (main/wherever.py):

    class SocialAccountAdapter(DefaultSocialAccountAdapter):
        def authentication_error(self, request, provider_id, error, exception, extra_context):
            your_log_function(
                'SocialAccount authentication error!',
                'error',
                request,
                extra_data = {'provider_id': provider_id, 'error': error.__str__(), 'exception': exception.__str__(), 'extra_context': extra_context},
            )
    

    (and in settings.py)

    SOCIALACCOUNT_ADAPTER = "main.wherever.SocialAccountAdapter"
    

    I'm doing this in my app and it works great!

提交回复
热议问题