【问题标题】:How to get backend instance from python-social-auth如何从 python-social-auth 获取后端实例
【发布时间】:2013-12-13 22:38:42
【问题描述】:

我目前正在使用 python-social-auth 并添加了一个后端MyOAuth 其中BaseOAuth1,在BaseOAuth1 类中有一个方便的oauth_request 实例方法,我想在外部使用它类。

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

我尝试直接实例化该类,但看起来我缺少一些上下文。

有没有办法引用MyOAuth 后端实例?我期待类似的东西

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

【问题讨论】:

    标签: python django python-social-auth


    【解决方案1】:

    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()
    

    【讨论】:

      猜你喜欢
      • 2021-08-03
      • 1970-01-01
      • 1970-01-01
      • 2014-08-04
      • 1970-01-01
      • 2013-12-07
      • 2014-11-02
      • 1970-01-01
      • 2017-07-16
      相关资源
      最近更新 更多