【问题标题】:Unable to refresh a Google OAuth 2 token after update using 'Python Social Auth'使用“Python Social Auth”更新后无法刷新 Google OAuth 2 令牌
【发布时间】:2015-01-30 20:10:35
【问题描述】:

我在Django 项目中使用Python Social Auth,一切正常。

我刚刚将 Python 社交身份验证更新到 0.2.1,在尝试刷新 Google OAuth2 令牌时,我遇到了 load_strategy 错误。

直到现在我还在使用:

strategy = load_strategy(backend='google-oauth2')
user = UserSocialAuth.objects.get(uid=..., provider="google-oauth2")
refresh_token(strategy=strategy, redirect_uri='http://.....')

现在我收到此错误:

TypeError: load_strategy() got an unexpected keyword argument 'backend'

【问题讨论】:

    标签: python django oauth-2.0 social


    【解决方案1】:

    更新后我遇到了同样的问题。

    以下是文档中的示例:

    移动应用程序将使用 SDK 在应用程序内注册用户是一种常见情况,但除非创建相应的数据库条目,否则该注册不会被 python-social-auth 反映。为此,可以创建一个视图/路由,通过给定的 access_token 创建这些条目。以以下代码为例(代码遵循 Django 约定,但其他框架的版本可以轻松实现):

    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'
    

    希望有帮助

    【讨论】:

    • 但你的回答与我的问题无关。
    猜你喜欢
    • 2018-07-18
    • 1970-01-01
    • 1970-01-01
    • 2016-09-04
    • 2017-05-18
    • 1970-01-01
    • 2021-11-01
    • 2015-06-27
    • 1970-01-01
    相关资源
    最近更新 更多