用于注册/登录用户的Django REST Framework和python-social-auth

Saf*_*ari 7 python django rest django-rest-framework python-social-auth

我必须为移动应用程序实现一些REST api.

我想使用Django REST框架.

用户(移动端)只能使用Facebook注册帐户,我会使用python-social-auth进行此注册/登录.

我是新手,所以我看了很多关于它的教程/文档/示例.

我只找到了关于Django + python_social_auth的完整教程,但我想知道使用REST-api进行用户注册/登录的最佳实践.

我在哪里可以找到完整的例子?

在我的简单测试中,我也有一个问题:当我尝试使用这个例子:

@psa('social:complete')
def register_by_access_token(request, backend):
    # This view expects an access_token GET parameter, if it's needed,
    # request.backend and request.strategy will be loaded with the current
    # backend and strategy.
    token = request.GET.get('access_token')
    user = request.backend.do_auth(request.GET.get('access_token'))
    if user:
        login(request, user)
        return 'OK'
    else:
        return 'ERROR'
Run Code Online (Sandbox Code Playgroud)

我得到了这个错误:

u'social'不是注册的命名空间

我也尝试SOCIAL_AUTH_URL_NAMESPACE = 'myApp'在我的设置中添加它,但它没有解决问题.

Hai*_*ris 7

如果还为时不晚,那么为什么不使用https://github.com/pennersr/django-allauthhttps://github.com/Tivix/django-rest-auth,它们可以协同工作并简化基于API的操作(社交)登录/注销/密码重置令牌/密码重置从令牌等流程.

  • 您需要单独安装django-restframework和django-allauth然后是,您可以按照该链接的说明进行操作.如果你想看看如何在前端集成,那么一定要看看他们的角度应用程序https://github.com/Tivix/angular-django-registration-auth (2认同)