omab / python-social-auth

Social auth made simple
http://psa.matiasaguirre.net
BSD 3-Clause "New" or "Revised" License
2.83k stars 1.09k forks source link

Access user's request from the Pipeline #978

Closed rigaspapas closed 7 years ago

rigaspapas commented 8 years ago

When you add a function to the pipeline you have access to a request keyword argument. This request object contains only the GET (or POST) data we received when user got redirected to our callback URL. The only information we have about the authenticity of the user's request is the user parameter which is in fact the request.user value. Having a custom user system in Django won't work with that. We need to have access to the whole request object to decide whether it was authenticated. My workarround to achieve this was to override the complete view function in order to add the whole request object to the keyword arguments. Is there a better way to achieve this or any chance of making such changes in the future?

LennyLip commented 8 years ago

"request" at pipeline kwargs is not django request. It is QueryDict , that using by PSA with tokens and etc. If you want access django wsgi request, you must use "strategy.request" value.

rigaspapas commented 8 years ago

Thanks! I was expecting to find that information at the Pipeline page of the documentation. Another problem worth mentioning when having a custom user system in Django, is that when you disable the AuthenticationMiddleware, request.user is not defined, leading to an error. Is there a workarround with that?

siddharthsahu commented 8 years ago

I have recently upgraded from v0.1.17 to v0.2.4, and my code is breaking when it tried to access session as follows:

request = kwargs.get('request')
do_something(session_key=request.session.session_key)

Error: 'QueryDict' object has no attribute 'session' As per your conversation, since this request is not django request, hence I am getting above error, but this code was working fine before upgrade. Any idea, why is this so?

omab commented 7 years ago

The Django request can be accessed at strategy.request.