gpt4 book ai didi

python-social-auth - python 社交身份验证加载策略并使用版本 0.1.26 手动验证用户

转载 作者:行者123 更新时间:2023-12-04 17:18:49 25 4
gpt4 key购买 nike

在过去的 2 个月里,我使用 python social auth 进行社交身份验证,效果非常好。我需要 QQ 支持,因此安装了最新的 git 提交(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”方法已更改而引发异常。

我似乎找不到任何关于如何使用新版本执行此操作的文档。

如有任何帮助,我们将不胜感激!

暗利。

最佳答案

存储库中的最后更改改变了策略的重要性,它不再是执行身份验证的主要实体,它只是一个将框架与后端粘合在一起的辅助类。尝试使用此代码段加载 strategybackend:

from social.apps.django_app.utils import load_strategy, load_backend

strategy = load_strategy(request)
backend = load_backend(strategy, backend, uri)
...
user = backend.do_auth(token)

关于python-social-auth - python 社交身份验证加载策略并使用版本 0.1.26 手动验证用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24351208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com