1

I am currently using python-social-auth and added a backend MyOAuth which BaseOAuth1, inside the BaseOAuth1 class there is a handy oauth_request instance method which I would like to make use of outside of the class.

https://github.com/omab/python-social-auth/blob/master/social/backends/oauth.py

I tried instantiate the class directly but looks like I am missing some context.

Is there a way reference that MyOAuth backend instance? I am expecting something like

request.user.social_auth.get(provider='MyOAuth').backend.oauth_request(...)

4

1 回答 1

5

Sweet,贴在github项目上,得到了答案。

https://github.com/omab/python-social-auth/issues/114

目前:

from social.apps.django_app.utils import load_strategy

strategy = load_strategy(backend='MyOAuth')
social = request.user.social_auth.get(provider='MyOAuth')
backend = backend(strategy=strategy)
backend = social.get_backend(strategy)
backend.oauth_request(...)

作者将发布一个助手来轻松完成此操作。

social = request.user.social_auth.get(provider='MyOAuth')
backend = social.get_backend_instance()
于 2013-12-02T19:11:45.117 回答