python-social-auth +手机应用 [英] python-social-auth + mobile app

查看:155
本文介绍了python-social-auth +手机应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a django app and I create API for mobile app. When it comes to user authentication I simple gets login + pass and do standard django login stuff. When user is logged in I generate a token, save it and provide to the mobile app.

现在来到Facebook,我想实现python-social-auth图书馆。我知道如何实现标准的网络,这真是微不足道。但是我不知道如何将其实现到我的移动API中,以及如何将我的令牌内容合并到一起。

Now it comes to Facebook and I would like to implement python-social-auth library. I do know how to implement it for standard web, it's really trivial. But I have no idea, how to implement it into my mobile API and how to incorporate there my token stuff.

只是想...
有没有做程序认证的可能性,所以我可以创建API方法,并从那里调用社会认证的东西?但是如何在Facebook侧面上允许访问XY应用程序到您的个人资料页面?

Just thinking... Is there a possibility to do programatical auth so I would be able to create API method and call the social auth stuff from there? But how about the "Allow access to XY app to your profile" page on facebook side?

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

Any advice helps. Thank you in advance.

推荐答案

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

The documentation describes how you can simply provide the access_token to authenticate/create a user.

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'

这篇关于python-social-auth +手机应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆