2016-08-11 18 views
1

我正在使用我的公司帳戶(即「Google for works」帳戶)實施Google oauth2。 0登錄到我的django應用程序。python-social-auth:在/ complete/google-oauth2 /中的AttributeError /:'NoneType'對象沒有屬性'provider'

管道在 「settings.py」 的模樣:

SOCIAL_AUTH_PIPELINE = [ 
    'social.pipeline.social_auth.social_details', 
    'social.pipeline.social_auth.social_uid', 
    'social.pipeline.social_auth.auth_allowed', 
    'social.pipeline.social_auth.associate_by_email', 
    'social.pipeline.social_auth.associate_user', 
    'social.pipeline.social_auth.load_extra_data', 
    'social.pipeline.user.user_details', 
] 

添加條件後端到pipepline。

if config.GCPAuthentication.AUTO_CREATE_ACCOUNTS: 
    SOCIAL_AUTH_PIPELINE.extend([ 
    'social.pipeline.user.get_username', 
    'social.pipeline.user.create_user' 
]) 

在試圖登錄的第一次與一個新的用戶,我得到的錯誤:在/完整/谷歌的oauth2 AttributeError的/:「NoneType」對象有沒有屬性「供應商」

有趣的是,用戶正在創建並保存在數據庫中,並在下次登錄嘗試時允許我登錄。

它投擲的錯誤在這裏:https://github.com/omab/python-social-auth/blob/master/social/actions.py#L70

我公司谷歌帳戶可能沒有任何社會帳號(Google+已遭到停用)與它相關聯/相關的信息。這是一個問題嗎?

無論如何,你能告訴我任何解決方法來擺脫這個問題嗎?

+0

get_username()和create_user()返回什麼? –

+0

我該如何檢查? 在用戶中,獲取創建用戶名作爲我的電子郵件ID的新用戶,這是因爲我有, SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True在settings.py –

+0

我改變了函數管道的順序,它的工作: 我想它應該遵循這裏提到的方式是:https://github.com/omab/python-social-auth/blob/master/docs/pipeline.rst 謝謝@luke_aus。 –

回答

2

管道預期遵循需要調用函數的順序。 爲了我的解決方案正確的順序應該是這樣的:

SOCIAL_AUTH_PIPELINE = [ # Note: Sequence of functions matters here. 
    'social.pipeline.social_auth.social_details', # 0 
    'social.pipeline.social_auth.social_uid', # 1 
    'social.pipeline.social_auth.auth_allowed', # 2 
    'social.pipeline.social_auth.social_user', # 3 
    'social.pipeline.user.get_username', # 4 
    'social.pipeline.social_auth.associate_by_email', # 5 
    'social.pipeline.social_auth.associate_user', # 6 
    'social.pipeline.social_auth.load_extra_data', # 7 
    'social.pipeline.user.user_details', # 8 
] 

# Adding conditional functions to pipepline. 
# NOTE: Sequence of functions matters here. 
if config.GCPAuthentication.AUTO_CREATE_ACCOUNTS: 
    SOCIAL_AUTH_PIPELINE.insert(6, 'social.pipeline.user.create_user') 
+0

我正面臨類似的問題。我的管道訂單與上面相同,並在'user_details'後添加了自定義管道'create_user_account'。 'request'和'user'在傳遞給這個管道的'request'對象中都不存在。 http://stackoverflow.com/questions/38973264/on-upgrading-python-social-auth-from-0-1-17-to-0-2-4-session-attribute-is-not-p – Sid

+0

這可能是因爲user_details函數沒有將任何東西傳遞給管道中的下一個函數。按照您的要求,您可能需要更改管道中功能的順序: https://github.com/omab/python-social-auth/blob/master/social/pipeline/user.py#L75 –

1

是的,你是對的,在這裏管道事宜功能的序列作爲一個函數的返回將被輸入到管道中的下一個函數。

0

作爲一個旁註,我想補充一點,當我通過更改USER模型的主鍵時,我遇到了類似的問題。在這種情況下,僅爲新的USER模型運行遷移就不足夠。您還必須爲社交身份驗證運行遷移。我完成了&完成整個項目的強制遷移。

相關問題