[英]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.