Reputation: 33
My app uses python social-auth for login as well as allowing accounts to "connect". With that in mind I have a custom pipeline as follows:
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'
)
I also have set:
SOCIAL_AUTH_FIELDS_STORED_IN_SESSION = ['connection',]
In my app view I call social-auth as follows e.g for twitter:
return HttpResponseRedirect(reverse('social:begin', args=('twitter',)) + "?connection=" + request.POST.get('origin') )
This works fine and I head out to twitter and the auth is completed, but when I get back to my custom pipeline util I cannot retrieve the session value, this is what I am doing:
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
Using PDB and also django debug toolbar I can see the value is there, what's wrong with this code that it does not retrieve it? Thanks for any help!
Upvotes: 1
Views: 991
Reputation: 709
According to the docs, the proper way to retrieve the data is:
strategy.session_get('connection')
Perhaps this helps?
Upvotes: 1