在过去的 2 个月中,我使用 python social auth 进行社交身份验证,这很棒。我需要 QQ 支持,因此安装了最新的 git commit(23e4e289ec426732324af106c7c2e24efea34aeb - 不是发布的一部分)。到目前为止,我曾经使用以下代码对用户进行身份验证:
# 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
)
strategy = load_strategy(request=bundle.request)
except MissingBackend:
raise ImmediateHttpResponse(HttpNotFound('Backend not found'))
# get the backend for the strategy
backend = strategy.backend
# check backend type and set token accordingly
if isinstance(backend, BaseOAuth1):
token = {
'oauth_token': bundle.data.get('access_token'),
'oauth_token_secret': bundle.data.get('access_token_secret'),
}
elif isinstance(backend, BaseOAuth2):
token = bundle.data.get('access_token')
else:
raise ImmediateHttpResponse(HttpBadRequest('Wrong backend type'))
# authenticate the user
user = strategy.backend.do_auth(token)
效果很好。
在最新版本中,此行为已更改,并且由于“load_strategy”方法已更改而引发异常。
我似乎找不到任何关于如何使用新版本的文档。
任何帮助,将不胜感激!
暗里。