Pun*_*ddy 4 django django-rest-framework django-allauth nuxt.js django-rest-framework-simplejwt
尝试使用 Django Rest + allauth + dj-rest-auth 从 Nuxt 应用程序进行身份验证
第一个错误
allauth.socialaccount.models.SocialApp.DoesNotExist:SocialApp 匹配查询不存在。
通过将 SITE_ID = 1 更改为 2 解决了此问题
其次我收到这个错误
Traceback (most recent call last):
File "C:\Users\xyz\django-env\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\xyz\django-env\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\xyz\django-env\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\xyz\django-env\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "C:\Users\xyz\django-env\lib\site-packages\django\views\generic\base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Users\xyz\django-env\lib\site-packages\django\utils\decorators.py", line 45, in _wrapper
return bound_method(*args, **kwargs)
File "C:\Users\xyz\django-env\lib\site-packages\django\views\decorators\debug.py", line 76, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
File "C:\Users\xyz\django-env\lib\site-packages\dj_rest_auth\views.py", line 48, in dispatch
return super(LoginView, self).dispatch(*args, **kwargs)
File "C:\Users\xyz\django-env\lib\site-packages\rest_framework\views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "C:\Users\xyz\django-env\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "C:\Users\xyz\django-env\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
raise exc
File "C:\Users\xyz\django-env\lib\site-packages\rest_framework\views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "C:\Users\xyz\django-env\lib\site-packages\dj_rest_auth\views.py", line 138, in post
self.serializer.is_valid(raise_exception=True)
File "C:\Users\xyz\django-env\lib\site-packages\rest_framework\serializers.py", line 220, in is_valid
self._validated_data = self.run_validation(self.initial_data)
File "C:\Users\xyz\django-env\lib\site-packages\rest_framework\serializers.py", line 422, in run_validation
value = self.validate(value)
File "C:\Users\xyz\django-env\lib\site-packages\dj_rest_auth\registration\serializers.py", line 117, in validate
token = client.get_access_token(code)
File "C:\Users\xyz\django-env\lib\site-packages\allauth\socialaccount\providers\oauth2\client.py", line 91, in get_access_token
raise OAuth2Error("Error retrieving access token: %s" % resp.content)
allauth.socialaccount.providers.oauth2.client.OAuth2Error: Error retrieving access token: b'{\n
"error": "redirect_uri_mismatch",\n "error_description": "Bad Request"\n}'
Run Code Online (Sandbox Code Playgroud)
在 Django 视图中设置重定向 URL 以匹配 OAuth 客户端 (Google) 中配置的重定向 URI:
class GoogleLogin(SocialLoginView):
authentication_classes = []
adapter_class = GoogleOAuth2Adapter
callback_url = "http://localhost:3000/login" # <--- make sure this line is correct!
client_class = OAuth2Client
Run Code Online (Sandbox Code Playgroud)
如果没有提供任何代码,这将很难回答,但我看到了您对有关此主题的 Medium 教程的评论,并且遇到了同样的问题。示例代码省略/login了 URL。
| 归档时间: |
|
| 查看次数: |
1145 次 |
| 最近记录: |