繁体   English   中英

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

[英]Django REST Framework and python-social-auth for registration/login user

我必须为移动应用程序实现一些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'

我得到了这个错误:

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

我还尝试在我的设置中添加此SOCIAL_AUTH_URL_NAMESPACE = 'myApp' ,但它无法解决问题。

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

我知道用户已经选择了答案,但由于答案将我们引导到另一个库,这是我的答案,以防有人稍后需要它:

“social”是您必须为python-social-auth提供的URL提供的命名空间。 您必须在项目的urls.py的urlpatterns列表中包含以下行:

urlpatterns = [
    url(r'^social/', include('social.apps.django_app.urls', namespace="social")
    # All other remaining urls here.
]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM