我有同样的问题谷歌登录,但经过几次修改,我能够激活它。但是对于facebook,我无法解决这个问题。
class GoogleOAuth2AdapterIdToken(GoogleOAuth2Adapter):
def complete_login(self, request, app, token, **kwargs):
idinfo = id_token.verify_oauth2_token(token.token, requests.Request(), app.client_id)
if idinfo['iss'] not in ['accounts.google.com', 'https://accounts.google.com']:
raise ValueError('Wrong issuer.')
extra_data = idinfo
login = self.get_provider()
.sociallogin_from_response(request,
extra_data)
return login
oauth2_login = OAuth2LoginView.adapter_view(GoogleOAuth2AdapterIdToken)
oauth2_callback = OAuth2CallbackView.adapter_view(GoogleOAuth2AdapterIdToken)
class GoogleLogin(SocialLoginView):
adapter_class = GoogleOAuth2AdapterIdToken
client_class = OAuth2Client
def get_serializer(self, *args, **kwargs):
serializer_class = self.get_serializer_class()
kwargs['context'] = self.get_serializer_context()
return serializer_class(*args, **kwargs)
class FacebookLogin(SocialLoginView):
adapter_class = FacebookOAuth2Adapter
authentication_classes = []
client_class = OAuth2Client
def get_serializer(self, *args, **kwargs):
serializer_class = self.get_serializer_class()
kwargs['context'] = self.get_serializer_context()
return serializer_class(*args, **kwargs)
这是我的views.py,在这里登录谷歌工作得很好。
Django==3.2.8
django-allauth==0.45.0
django-rest-auth==0.9.5
djangorestframework==3.12.4
下面是我得到的错误。
HTTP 400 Bad Request
Allow: POST, OPTIONS
Content-Type: application/json
Vary: Accept
{
"non_field_errors": [
"Incorrect value"
]
}
我只传递一个访问令牌作为输入。
您应该使用facebook的实际access_token
。
看起来像EAA...