gpt4 book ai didi

Django rest-auth/allauth 与微博集成

转载 作者:行者123 更新时间:2023-12-01 09:21:39 25 4
gpt4 key购买 nike

我正在尝试将 django rest-auth 和 allauth 一起用于 reactjs 前端应用程序的后端身份验证过程。我不确定我的设置是否正确,或者这是一个错误。响应中不存在“uid”,它只携带从 api 传递的 token 。我认为 uid 应该来自现有用户或来自新用户的新用户,并且“complete_login”应该传递这些 uid ...

如果有人有任何想法,请告诉我。

完整回溯如下:

Traceback:

File "/home/ubuntu/panbecopy/src/penv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)

File "/home/ubuntu/panbecopy/src/penv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/ubuntu/panbecopy/src/penv/local/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
58. return view_func(*args, **kwargs)

File "/home/ubuntu/panbecopy/src/penv/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)

File "/home/ubuntu/panbecopy/src/penv/local/lib/python2.7/site-packages/rest_framework/views.py" in dispatch
466. response = self.handle_exception(exc)

File "/home/ubuntu/panbecopy/src/penv/local/lib/python2.7/site-packages/rest_framework/views.py" in dispatch
463. response = handler(request, *args, **kwargs)

File "/home/ubuntu/panbecopy/src/penv/local/lib/python2.7/site-packages/rest_auth/views.py" in post
81. self.serializer.is_valid(raise_exception=True)

File "/home/ubuntu/panbecopy/src/penv/local/lib/python2.7/site-packages/rest_framework/serializers.py" in is_valid
213. self._validated_data = self.run_validation(self.initial_data)

File "/home/ubuntu/panbecopy/src/penv/local/lib/python2.7/site-packages/rest_framework/serializers.py" in run_validation
410. value = self.validate(value)

File "/home/ubuntu/panbecopy/src/penv/local/lib/python2.7/site-packages/rest_auth/registration/serializers.py" in validate
106. login = self.get_social_login(adapter, app, token, access_token)

File "/home/ubuntu/panbecopy/src/penv/local/lib/python2.7/site-packages/rest_auth/registration/serializers.py" in get_social_login
42. social_login = adapter.complete_login(request, app, token, response=response)

File "/home/ubuntu/panbecopy/src/penv/local/lib/python2.7/site-packages/allauth/socialaccount/providers/weibo/views.py" in complete_login
20. uid = kwargs.get('response', {}).get('uid')

Exception Type: AttributeError at /rest-auth/weibo/
Exception Value: 'unicode' object has no attribute 'get'

最佳答案

这意味着 allauth 没有得到正确的用户信息。您可以检查您使用的社交登录的源代码(views.py 和 provider.py)。例如,领英,

def complete_login(self, request, app, token, **kwargs):
extra_data = self.get_user_info(token)
return self.get_provider().sociallogin_from_response(
request, extra_data)

确保您使用了正确的参数( token 、kwargs)。请注意,不同社交身份验证插件的 token 参数不同。例如,对于 linkedin 它只是字符串,但是对于微博,它是

uid = kwargs.get('response', {}).get('uid')

这意味着“响应”应该是一个字典。

如果您以正确的格式使用了正确的参数,那应该可以工作。

希望有所帮助。

关于Django rest-auth/allauth 与微博集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42519650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com