python-social-auth +移动应用程序

时间:2014-06-26 15:35:42

标签: python django facebook python-social-auth

我有一个django应用程序,我为移动应用程序创建API。在用户身份验证方面,我简单地获取登录+传递并执行标准的django登录。当用户登录时,我生成一个令牌,保存并提供给移动应用程序。

现在谈到Facebook,我想实现python-social-auth库。我知道如何为标准网络实现它,它真的很微不足道。但是我不知道如何将它实现到我的移动API中,以及如何将其添加到我的令牌中。

想一想...... 是否有可能做programatical auth所以我可以创建API方法并从那里调用社交认证的东西?但是如何允许对您的个人资料进行XY应用访问" Facebook边的页面?

任何建议都有帮助。提前谢谢。

1 个答案:

答案 0 :(得分:5)

documentation描述了如何简单地提供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'
相关问题