【问题标题】:python-social-auth + mobile apppython-social-auth + 移动应用
【发布时间】:2014-08-17 13:16:03
【问题描述】:

我有一个 django 应用程序,并为移动应用程序创建 API。当涉及到用户身份验证时,我简单地获取登录 + 通过并执行标准的 django 登录内容。当用户登录时,我会生成一个令牌,将其保存并提供给移动应用程序。

现在谈到 Facebook,我想实现 python-social-auth 库。我确实知道如何为标准网络实现它,这真的很简单。但我不知道如何在我的移动 API 中实现它以及如何将我的令牌内容合并到那里。

只是想... 是否有可能进行编程身份验证,以便我能够创建 API 方法并从那里调用社交身份验证内容?但是 facebook 端的“允许访问 XY 应用程序到您的个人资料”页面怎么样?

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

【问题讨论】:

标签: python django facebook python-social-auth


【解决方案1】:

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'

【讨论】:

  • 我正在这样做,但我还想要一个刷新令牌。即使客户端定义了access_type=offline,我也让用户完美注册但没有刷新令牌
猜你喜欢
  • 1970-01-01
  • 2016-09-05
  • 1970-01-01
  • 2017-02-28
  • 2014-02-13
  • 1970-01-01
  • 2014-01-21
  • 1970-01-01
  • 2019-08-10
相关资源
最近更新 更多