Search code examples
pythondjangopython-social-auth

Python Social Auth - How to know if social media connect is successful?


I have installed Python Social Auth. I use it to associate user site account with his social media accounts.

Facebook connect link is:

<a href="{% url 'social:begin' 'facebook' %}?next={{ request.path }}">Connect</a>

Redirection works but how to know if social media association is successful?

If an exception is catch, I can display get_messages() function. It's perfect! But any return if it's successful.

I have tried to custom a pipeline but I have not access to request variable to set message like it: messages.success(request, "Successful message!')


Solution

  • You do have access to request in your custom pipeline:

    The pipeline functions will get quite a lot of arguments, ranging from the backend in use, different model instances, server requests and provider responses.

    You can read more about it here.

    and you can get access to request object like this:

    def custom_pipeline(strategy, *args, *kwargs):
        request = strategy.request
    

    and do whatever you wanted with messages.