So I have a referral url, something like http://.../ref/4Q3j9/
which when clicked takes them to a sign up page. They can signup using google account [Oauth2]. I store them in the template as a hidden variable. But when the user clicks on the google sign-in, I lose those values. Is there anyway I can pass those parameters and then get back again on the redirect in social_auth. I thought of using pipeline but thats only after the login process, by then I lose those params.

- 2,994
- 3
- 17
- 20
-
1why don't you use the session middleware to store the variables? https://docs.djangoproject.com/en/dev/topics/http/sessions/ – ppetrid Dec 26 '12 at 03:26
2 Answers
This is a bit tricky, storing on session it's not enough since django clears the session when the user is logged in. You could store it in the session when the user is sent to your signup page, but then you need a pipeline entry that does something like user.referral = request.session['referral']
, and then store it back into the session using a middleware that checks for request.user.referral
before the redirect done by django-social-auth is sent to the user (when auth is completed and the user is logged in).
You could try defining GOOGLE_OAUTH2_AUTH_EXTRA_ARGUMNTS = {'referral': None}
and ensure that Google OAuth2 link has a ?referral=foobar
added. But that will only avoid the first session storage of referral, you will need the pipeline (but this time check for request.GET['referral']
instead of session) entry and the middleware, and I'm not sure that Google will return the referral back when auth is done.

- 3,721
- 19
- 23
An old question, but as it is unanswered... I did this using cookies, setting a cookie in the view function with
response.set_cookie( cookie_name, my_needed_value, max_age=3600)
or in the web page with
document.cookie = 'cookie_name=my_needed_value; expires=Tue, 05 Nov 2014 00:00:00 UTC; path=/'
(set expires sensibly, or to a past date to delete) and then reading it in the view with
if request.COOKIES.has_key(cookie_name):
my_needed_value = request.COOKIES[cookie_name]

- 1,032
- 11
- 26