python-社交认证+移动应用



我有一个django应用程序,我为移动应用程序创建API。当涉及到用户认证时,我简单地获得login + pass并做标准的django登录东西。当用户登录时,我生成一个令牌,保存并提供给移动应用程序。

现在谈到Facebook,我想实现python-social-auth库。我知道如何为标准web实现它,它真的很琐碎。但我不知道,如何实现它到我的移动API,以及如何纳入我的令牌的东西。

想……是否有可能做编程验证,所以我将能够创建API方法,并从那里调用社会验证的东西?但是facebook侧的"允许访问XY应用程序到您的个人资料"页面呢?

任何建议都有帮助。

文档描述了如何简单地提供access_token来验证/创建用户。

from django.contrib.auth import login
from social.apps.django_app.utils import psa
# Define an URL entry to point to this view, call it passing the
# access_token parameter like ?access_token=<token>. The URL entry must
# contain the backend, like this:
#
#   url(r'^register-by-token/(?P<backend>[^/]+)/$',
#       'register_by_access_token')
@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'

最新更新