【问题标题】:Authenticate with twitter tastypie python social auth return 403使用 twitter sweetpie python social auth 进行身份验证返回 403
【发布时间】:2014-07-03 15:59:35
【问题描述】:

我正在使用 sweetpie 和 python-social-auth 管理我的社交身份验证。 通过执行以下操作,我通过 facebook 进行身份验证没有问题:

from social.apps.django_app import load_strategy
provider = “facebook”
access_token = “CAAIkpON595IBADC8CqXgq615wfsls15u6RI23sreqbzntau”
strategy = load_strategy(backend=provider)   
user = strategy.backend.do_auth(access_token)

但是当我尝试对 provider="twitter" 和有效的访问令牌执行相同操作时,在调用 'do_auth' 方法时我不断收到 403。 我设法 cURL 到 twitter api,所以我的凭据是有效的。

我是否遗漏了任何步骤? twitter 的身份验证应该和 facebook 的不同吗?

谢谢!

【问题讨论】:

  • 你检查了redirect_uri 属性吗?还要检查响应错误代码的设置。应该有一些额外的消息来解释问题所在。
  • 此过程目前不适用于 Twitter,在github.com/omab/python-social-auth/issues/272 跟踪它存在问题,我需要设置时间来处理它。

标签: twitter tastypie python-social-auth


【解决方案1】:

我在 register_by_access_token 方法中遵循示例(我使用 django 作为 Angular 应用程序的 API)。

在示例中,行:

user = request.backend.do_auth(access_token)

使用 twitter 收到的 oauth_token 无法使用 twitter,要使其正常工作,我必须创建以下 access_token:

access_token = {
              'oauth_token': auth[1],
              'oauth_token_secret': auth[2]
        }

其中 auth[1] 和 [2] 是 twitter 返回的值。

这很奇怪,因为我没有在任何地方找到此文档,我只是发现错过 SOCIAL_AUTH_TWITTER_KEY 和 SOCIAL_AUTH_TWITTER_SECRET 的人可以正常工作。

fyi:我将它与 django rest 框架一起使用

【讨论】:

    【解决方案2】:

    问题是我在定义“load_strategy”时没有添加“redirect_uri”。 最后我得到了这段代码:

    # setup redirect uri in order to load strategy
        uri = redirect_uri = "social:complete"
        if uri and not uri.startswith('/'):
            uri = reverse(redirect_uri, args=(backend,))
    
        # load the strategy
        try:
            strategy = load_strategy(
                request=request, backend=backend,
                redirect_uri=uri, **kwargs
            )
        except MissingBackend:
            raise Http404('Backend not found')
    

    感谢 @omab 在 github 问题页面中对此发表评论。

    【讨论】:

      猜你喜欢
      • 2017-07-15
      • 2016-10-16
      • 2015-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-11
      • 1970-01-01
      • 2019-07-16
      相关资源
      最近更新 更多