1

私のアプリは、ログインに python social-auth を使用し、アカウントを「接続」できるようにします。それを念頭に置いて、次のようなカスタム パイプラインがあります。

SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'jdconnections.utils.get_username', #<<here
'social.pipeline.social_auth.associate_by_email', 
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details'
)

私も設定しました:

SOCIAL_AUTH_FIELDS_STORED_IN_SESSION = ['connection',] 

私のアプリ ビューでは、たとえば twitter の場合、次のように social-auth を呼び出します。

  return HttpResponseRedirect(reverse('social:begin', args=('twitter',)) + "?connection=" + request.POST.get('origin') )

これは正常に動作し、Twitter にアクセスして認証が完了しましたが、カスタム パイプライン ユーティリティに戻ったときにセッション値を取得できません。これが私が行っていることです。

from django.conf import settings
from django.contrib.sessions.backends.db import SessionStore
from jdconnections.models import Connections

from social.pipeline.user import get_username as social_get_username

def get_username(strategy, details, user=None, *args, **kwargs):

   current_session = SessionStore()
   if 'connection' not in current_session:
      result = social_get_username(strategy, details, user=user, *args, **kwargs)   
      return result
   else:
    if current_session['connection'] == 'TW':
        social = user.social_auth.get(provider='twitter')
        access_token = social.extra_data['access_token']
        cn = Connections.objects.create(origin='TW',ctoken = access_token)
    return None

PDB と django デバッグ ツールバーを使用すると、値がそこにあることがわかります。値が取得されないというこのコードの何が問題なのですか? 助けてくれてありがとう!

4

1 に答える 1

1

ドキュメントによると、データを取得する適切な方法は次のとおりです。

strategy.session_get('connection')

おそらくこれが役立ちますか?

http://psa.matiasaguirre.net/docs/use_cases.html#pass-custom-get-post-parameters-and-retrieve-them-on-authenticationを参照してください。

于 2015-10-26T22:17:35.193 に答える