添加自定义管道时出现social_auth_pipeline错误

时间:2018-04-05 10:35:13

标签: django django-rest-framework python-social-auth django-socialauth

我添加了自定义管道

SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.auth_allowed',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'social_core.pipeline.social_auth.associate_by_email',
'social_core.pipeline.user.create_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',

'users.pipeline.return_token', <---- my custom pipeline//
)

pipeline.py

from django.http import JsonResponse, HttpResponse

def return_token(backend, user, response, *args, **kwargs):

if response is not None:
    data = {"token": response['access_token'], "backend": "google-oauth2"}
    return JsonResponse(data)

else:
    return

当用户注册/登录时,用户注册到数据库并且返回的访问令牌没有错误

当我转换为http://localhost:8000/auth/convert-token

它返回错误

AttributeError at /auth/convert-token
'JsonResponse' object has no attribute 'is_active'

当我禁用我的管道时没有错误

如何在不收到错误的情况下返回access_token

0 个答案:

没有答案