pythondjangoauthenticationpython-social-auth

How can I display a meaningful login error messages to user within python-social-auth?


I am using python-social-auth with Django 1.6 and things are working well.

I defined SOCIAL_AUTH_LOGIN_ERROR_URL to point to a view I have within my app to show an error to the user when the login does not go as planned.

My system does not allow creation of new users. You must first log into your account using the regular credentials, associate your account with a social account, and only then can you log in using a social auth mechanism.

If a user attempts to log into my system using a social account which is not registered to a user within my system, I want to display a custom message. The problem is, the view located at SOCIAL_AUTH_LOGIN_ERROR_URL does not receive any info about what the error could be. The best I can do is say "An error occurred while trying to log in."

How would I trap such errors and display a custom message to my users when that particular error happens?


Solution

  • Take a look at the middleware from the django_app:

    https://github.com/omab/python-social-auth/blob/526439ac66b00ce801e4fc5df89633a66eb8ffb2/social/apps/django_app/middleware.py

    and either create your own based on this or extended by overriding. As mentioned there, probably the get_message method.