【发布时间】:2016-12-17 18:13:40
【问题描述】:
我正在使用我的公司帐户(即“Google forworks”帐户)来实现 Google oauth2.0 登录到我的 django 应用程序。
“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',
]
向管道添加条件后端。
if config.GCPAuthentication.AUTO_CREATE_ACCOUNTS:
SOCIAL_AUTH_PIPELINE.extend([
'social.pipeline.user.get_username',
'social.pipeline.user.create_user'
])
首次尝试使用新用户登录时,出现错误: /complete/google-oauth2/ 处的 AttributeError:“NoneType”对象没有属性“provider”
有趣的是,用户正在被创建并保存在数据库中,并且在下次登录尝试时它允许我登录。
这里的抛出错误:https://github.com/omab/python-social-auth/blob/master/social/actions.py#L70
我的公司 Google 帐户可能没有任何与之关联的社交帐户(Google+ 已禁用)/相关信息。这是个问题吗?
无论如何,您能告诉我解决此问题的任何解决方法吗?
【问题讨论】:
-
get_username() 和 create_user() 返回什么?
-
如何检查?在用户中,使用用户名作为我的电子邮件 ID 创建的新用户,这是因为我有 SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True in settings.py
-
我改变了函数管道的顺序并且它起作用了:我想它应该遵循这里提到的方式:github.com/omab/python-social-auth/blob/master/docs/… 谢谢@luke_aus。
标签: django python-2.7 google-oauth python-social-auth