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.
最近,我们不得不在开发中的应用程序中添加对社交网络登录的支持,并且选择了django-social-auth进行处理。 这是一个有据可查且易于使用的django应用程序,用于身份验证。
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.
但是,我们不仅要验证用户身份,还想获得更多信息,例如个人资料图片,性别等。幸运的是,django-social-auth具有有用的管道,您可以扩展该管道来完成此类任务。 我将简要说明如何实现这一目标。 我将假定您已经具有身份验证功能,在文档中对此进行了很好的说明。
First of all, we should define the pipeline in our settings.py like this:
首先,我们应该在settings.py中定义管道,如下所示:
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.
管道中除最后一个项目外的所有项目都来自django-social-auth,并且是原始管道的一部分,最后一个项目是负责管理化身的项目,应进行编码。
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.
如果您想扩展从其他社交网络获取头像的功能,则应检查后端并相应地获取图片网址。
翻译自: https://www.pybloggers.com/2012/02/get-user-data-using-django-social-auth/