使用Python Social auth如何从自定义管道检索会话中存储的字段
我的应用程序使用python social auth进行登录,并允许帐户“连接”。考虑到这一点,我有一个自定义管道,如下所示:使用Python Social auth如何从自定义管道检索会话中存储的字段,python,django,python-social-auth,Python,Django,Python Social Auth,我的应用程序使用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_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,例如twitter:
return HttpResponseRedirect(reverse('social:begin', args=('twitter',)) + "?connection=" + request.POST.get('origin') )
这很好,我前往twitter,身份验证已经完成,但当我回到我的自定义管道util时,我无法检索会话值,这就是我正在做的:
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调试工具栏,我可以看到值在那里,这段代码有什么问题,它没有检索到它?谢谢你的帮助 根据文档,检索数据的正确方法是:
strategy.session_get('connection')
也许这有帮助
看
strategy.session_get('connection')