/_next/static/media/placeholder-social.f0796e1f.png
blog
Get user data using django-social-auth

Mon, Feb 13, 2012

quotes

August 2018: Please note that this post was written for an old version of Django. It is left here for historical purposes only.

Recently we had to add support for social networks login to an application we are developing and we chose django-social-auth to work with. It is a well documented and easy to use django application for authentication.

But we wanted to do more than just authenticating the user, we wanted to get extra data like the profile picture, gender, etc. Fortunately django-social-auth has an useful pipeline that you can expand to fulfill this kind of tasks. I will explain briefly how to achieve this. I will assume you already have authentication working which is very well explained in the documentation.

First of all, we should define the pipeline in our settings.py like this:

All the items in the pipeline except the last one are from django-social-auth and are part of the original pipeline, and the last one is the one in charge of getting the avatar and should be coded.

After we have our pipeline ready we need to implement the function that looks like this:

If you want to extend the functionality of getting the avatar from others social networks you should check the backend and get the image url accordingly.

On the other hand, if you want to get another kind of information like gender or age you should define another pipeline item and do something like we did above.

That's pretty much everything. Happy coding!

Wondering how AI can help you?

This website uses cookies to improve user experience. Read more