【问题标题】:authenticate django rest framework with appid and access token?使用 appid 和访问令牌对 django rest 框架进行身份验证?
【发布时间】:2016-09-10 08:35:47
【问题描述】:

我有一个应用程序,它有一个客户端 ID some_client_id,用户通过 Facebook oauth 进行身份验证。返回的令牌(代码)是some_token_to_auth_the_user

我的后端是django rest framework,和rest_auth

现在我正在尝试使用 facebook code (token) 对用户进行身份验证

在网址上http://localhost.com:8000/rest-auth/facebook/

输入表单的凭据是什么?

client-idfacebook-token吗?

我都试过了,

输出是,

TypeError at /rest-auth/facebook/
__init__() takes exactly 2 arguments (1 given)
Request Method: POST
Request URL:    http://localhost.com:8000/rest-auth/facebook/
Django Version: 1.9.6
Exception Type: TypeError
Exception Value:    
__init__() takes exactly 2 arguments (1 given)
Exception Location: /home/xo/.virtualenvs/dj19/local/lib/python2.7/site-packages/rest_auth/registration/serializers.py in validate, line 63
Python Executable:  /home/xo/.virtualenvs/dj19/bin/python
Python Version: 2.7.10

这些是视图,

from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
from rest_auth.registration.views import SocialLoginView
from allauth.socialaccount.providers.twitter.views import TwitterOAuthAdapter
from rest_auth.views import LoginView
from rest_auth.social_serializers import TwitterLoginSerializer


class FacebookLogin(SocialLoginView):
    adapter_class = FacebookOAuth2Adapter


class TwitterLogin(LoginView):
    serializer_class = TwitterLoginSerializer
    adapter_class = TwitterOAuthAdapter

我做错了什么?谢谢你的帮助。

【问题讨论】:

    标签: django oauth-2.0 django-rest-framework django-rest-auth


    【解决方案1】:

    Facebook SDK 提供Login function

    它返回一个authResponse,其中包含access_tokencode。您需要将这些POST 发送到Django-rest-auth 端点,该端点将使用 Facebook 对用户进行身份验证。

    【讨论】:

      猜你喜欢
      • 2018-12-15
      • 2023-03-16
      • 1970-01-01
      • 2015-06-21
      • 2021-08-06
      • 2014-04-14
      • 1970-01-01
      • 2019-05-02
      • 2017-12-05
      相关资源
      最近更新 更多