Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging django-allauth Social Network Login Failure

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 containing more information. There is a feature request for this log output (https://github.com/pennersr/django-allauth/issues/1120) but it has been open for over a year. In the mean time, how do I get more information to debug this error?

like image 336
Zags Avatar asked Apr 19 '16 20:04

Zags


2 Answers

More information is passed to the context used to render the error template but is not used in the default template.

You can get log output by overriding the template and including in your template the following:

{{ auth_error }}

or alternatively:

Code: {{ auth_error.code }}, Error: {{ auth_error.exception }}

To override the template, add a folder to your Django template DIRS. In Django 1.8+, this looks like the following:

TEMPLATES = [
    {
        ...
        DIRS: [os.path.join(BASE_DIR, 'templates')]
    }
]

Then, in that folder, make directory socialaccount and put in it a file called authentication_error.html

like image 72
Zags Avatar answered Sep 26 '22 03:09

Zags


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!

like image 22
Tristan Avatar answered Sep 26 '22 03:09

Tristan