過去 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" メソッドが変更されたため、例外が発生します。
新しいリリースでそれを行う方法に関するドキュメントが見つからないようです。
どんな助けでも大歓迎です!
オムリ。