简体   繁体   English

使用“ Python社交身份验证”更新后,无法刷新Google OAuth 2令牌

[英]Unable to refresh a Google OAuth 2 token after update using 'Python Social Auth'

I am using Python Social Auth in a Django project and everything was working fine. 我在Django项目中使用Python Social Auth ,并且一切正常。

I have just updated Python social authentication to 0.2.1, and I am getting an error with load_strategy when trying to refresh a Google OAuth 2 token. 我刚刚将Python社交身份验证更新为0.2.1,并且在尝试刷新Google OAuth 2令牌时出现load_strategy错误。

Until now I was using: 到目前为止,我一直在使用:

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

Now I am getting this error: 现在我收到此错误:

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

I was experiencing the same issue after update. 更新后,我遇到了同样的问题。

Here is example from the docs: 这是文档中的示例:

It's a common scenario that mobile applications will use an SDK to signup a user within the app, but that signup won't be reflected by python-social-auth unless the corresponding database entries are created. 常见的情况是,移动应用程序将使用SDK来在应用程序内注册用户,但是python-social-auth不会创建该注册,除非创建了相应的数据库条目。 In order to do so, it's possible to create a view / route that creates those entries by a given access_token. 为此,可以创建一个视图/路由,以通过给定的access_token创建这些条目。 Take the following code for instance (the code follows Django conventions, but versions for others frameworks can be implemented easily): 以以下代码为例(该代码遵循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'

Hope that helps 希望能有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python Social Auth、Google 和刷新令牌 - Python Social Auth, Google, and refresh token 确定何时使用Python Social Auth刷新OAUTH2令牌 - Decide when to refresh OAUTH2 token with Python Social Auth 如何使用 python-social-auth 和 django-graphql-auth 返回刷新令牌? - How can I return the refresh token using python-social-auth and django-graphql-auth? 在Google App Engine上使用python-social-auth进行的Google OAuth2身份验证失败 - Google OAuth2 authentication using python-social-auth on Google App Engine failed google oauth 登录后如何使用 django social_auth 打开原始页面 - How to open original page after google oauth login using django social_auth 使用Python Social Auth过滤或限制Django中的一组用户使用Google-Oauth2登录 - Filtering or restricting Google-Oauth2 login to a set of users in Django using Python Social Auth 使用&#39;hd&#39;param(Django / python-social-auth)限制对某个域的Google OAuth访问权限 - Limit Google OAuth access to one domain using 'hd' param (Django / python-social-auth) 在python中刷新Google云端硬盘(OAuth2)中的令牌 - Refresh token in Google Drive (OAuth2) in python 在Django中使用Python社交身份验证令牌身份验证时出现ValueError? - ValueError while using Python Social Auth token authentication in Django? 使用python social auth通过访问令牌注册用户 - Using python social auth to register users by access token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM