2013-02-01 53 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', 
      ) 
相關問題