2013-02-01 52 views
4

我正在为django应用程序编写一些测试脚本,它依靠django_social_auth来管理用户身份验证和登录(仅限Facebook登录)。如何以编程方式使用django_social_auth创建用户?

我想绕过django_social_auth的登录部分 - 我已经有了一些测试用户,并且通过其他测试获得了他们的认证令牌。

从技术上讲,我不应该再次将我的测试用户记录下来 - 现有的有效令牌应该足以用于此测试。

如何让django_social_auth系统使用我现有的auth令牌副本,绕过用户登录过程?

(我要补充一点,有些用户的数据可能已经从我自己的身份验证和点之间的数据库我跑在这个测试去掉)

+0

为什么你需要从社会身份验证登录,如果你已经在用户登录? – EsseTi

+1

最好的方法是查看django_social_auth的源代码,从这里的views.py开始https://github.com/omab/django-social-auth/blob/master/social_auth/views.py 我认为,方法auth_process和complete_process可能对您有用。 – Mounir

回答

1

我最近做了类似的定制。您必须覆盖默认的SOCIAL_AUTH_PIPELINE。我建议你写一些处理程序,并在管道中替换它。欲了解更多详细信息,您可以参考http://django-social-auth.readthedocs.org/en/latest/pipeline.html

我增强管道:

SOCIAL_AUTH_PIPELINE = (
       'social_auth.backends.pipeline.social.social_auth_user', 
       # Removed by default since it can be a dangerouse behavior that 
       # could lead to accounts take over. 
       #'social_auth.backends.pipeline.associate.associate_by_email', 
       'social_auth.backends.pipeline.user.get_username', 
       #'social_auth.backends.pipeline.user.create_user', 
       'myproject.custom.create_user', 
       'social_auth.backends.pipeline.social.associate_user', 
       #'social_auth.backends.pipeline.social.load_extra_data', 
       'myproject.custom.load_extra_data', 
       'social_auth.backends.pipeline.user.update_user_details', 
      ) 
相关问题