如何以编程方式使用django_social_auth创建用户?

时间:2013-02-01 20:01:44

标签: django facebook django-socialauth

我正在为django应用程序编写一些测试脚本,它依赖于django_social_auth来管理用户身份验证和登录(仅限facebook登录)。

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

从技术上讲,我不应该再次登录我的测试用户 - 现有的,有效的令牌应该足以进行此测试。

如何绕过用户登录过程来加工django_social_auth系统以使用我现有的auth令牌副本?

(我应该补充说,一些用户的数据可能已经从我的数据库中删除了他们的身份验证和我运行此测试的点)

1 个答案:

答案 0 :(得分: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',
           )
相关问题