如何解决django social auth 不返回用户
我有一个 django 应用程序,它使用 django social auth 向 Google 验证用户身份。它工作得很好,然后……突然停止了。我不知道为什么。我已经尝试了所有我能想到的。
这是我的社交身份验证管道:
SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details','social_core.pipeline.social_auth.social_uid','myapp.custom_social_auth_pipeline.auth_allowed','social_core.pipeline.social_auth.social_user','social_core.pipeline.user.get_username','myapp.custom_social_auth_pipeline.create_user','social_core.pipeline.social_auth.associate_user','social_core.pipeline.social_auth.load_extra_data','social_core.pipeline.user.user_details',)
这是我的 custom_social_auth_pipeline 上的代码:
from django.contrib.auth.models import Group,User
from django.shortcuts import redirect
USER_FIELDS = ['username','email']
def create_user(strategy,details,backend,user=None,*args,**kwargs):
print("CREATE USER CALLED") <-- this is never called! :(
if user:
return {'is_new': False}
fields = dict((name,kwargs.get(name,details.get(name)))
for name in backend.setting('USER_FIELDS',USER_FIELDS))
try:
if User.objects.get(email=fields['email']):
return {'is_new': False,'user': User.objects.get(email=fields['email'])}
except:
pass
if not fields:
return
fields['is_staff'] = True
user = strategy.create_user(**fields)
staff = Group.objects.get(name='Staff')
user.groups.add(staff)
return {
'is_new': True,'user': user
}
def auth_allowed(backend,response,**kwargs):
print ("AUTH ALLOWED CALLED") <-- this prints in my logs
print(details) <-- this returns the correct user
if not backend.auth_allowed(response,details):
return redirect('/')
它没有返回任何错误,也没有重定向到我们的“错误”网址。如果没有人登录,它的行为就像它一样(该应用程序有一个面向公众的页面,供未登录的人使用,如果您尝试转到另一个网址,您会被退回到那个网址)。我觉得我一定遗漏了一些明显的东西,但我不知道是什么。
另一件事:它在我的本地机器上完美运行。在我的服务器 (AWS Lambda) 上没有。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。