2014-09-10 11 views
1

我的應用使用python social-auth登錄以及允許帳戶「連接」。考慮到這一點我有一個自定義管道,如下所示:使用Python社交認證如何檢索從自定義管道中存儲在會話中的字段

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',] 

在我的應用程序視圖我呼籲社會-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調試工具欄我可以看到值在那裏,這個代碼有什麼問題,它不檢索它?謝謝你的幫助!

回答

相關問題