Ensure OAuth login preserves `return_to` parameter and goes there after logging in
In our regular signup process at https://publiclab.org/signup, we can set the destination AFTER signup using a return_to parameter, like this:
https://publiclab.org/signup?return_to=/post?title=My Title
This nice URL can even set a title on the post you are prompted to create! It works with this hidden input:
<input type="hidden" name="return_to" value="/post?title=My Title" /> (code here: https://github.com/publiclab/plots2/blob/cdef0bd7978836212c112f2295b4561d3f6a57f0/app/views/user_sessions/new.html.erb#L35)
We even have a test for this:
https://github.com/publiclab/plots2/blob/a8e9ffaa34319a3c7924ff735dc5231cf69b05d9/test/integration/login_flow_test.rb#L33-L41
Here's the controller logic that drives that redirect after account creation:
https://github.com/publiclab/plots2/blob/010bb27741625269e8c73d68bc65dcb7325b88a2/app/controllers/user_sessions_controller.rb#L108-L121
But for OAuth login (using Twitter, FB, Google logins) this doesn't seem to work.
I got the message on this line - but it didn't attempt to redirect me:
https://github.com/publiclab/plots2/blob/010bb27741625269e8c73d68bc65dcb7325b88a2/app/controllers/user_sessions_controller.rb#L41
I think we should look in the session[:return_to] parameter to see if it's there -- and we may need to store it there so it persists past the redirects through the external OmniAuth service.
I'd love some help with this one! I don't know if it'd be a quick one @SidharthBansal but interested in your thoughts!
Hi @SidharthBansal -- i know you're busy with Code-In and Outreachy, but I'm increasingly concerned that people on our site are losing their place when the log in with OAuth, and I want to ensure they get redirected back to their original page after login. I think we can use the session to do this, and I opened a starter PR to get this process going.
You know the OAuth code the best, though... what do you think about this approach?
https://github.com/publiclab/plots2/pull/3762
Hi Jeff, I will be happy to help here too asap. Right now a lot of things are going on and I want to give some time in analysing the wide range of Login related issues created by you. I don't want to hurry up things. Authentication is a really crucial part for running production website. So, I will try to take out 3-4 hours on Saturday for these issues. Please ping me on Sunday if I forget to do so. Can you please list all the login issues together? So that I can review all of them together.
That is very good of you! I know this is a lot of work and kind of a bad time. I tried to get a decent start on it but it's not my area of expertise in the code.
I think the big issues I worry about are mostly here: https://github.com/publiclab/plots2/labels/priority
But only this one (and the current one) are login-related: https://github.com/publiclab/plots2/issues/2592
The others are just small things we might improve! They aren't crucial, and I think several are ones we can get contributions for - esp. with GIFs.
Thanks, Sidharth!
I am trying this on my local machine. I need to make the developers account again. So creating them again.
@SidharthBansal You can also try having a look at https://github.com/publiclab/plots2/pull/3884 in case it helps. :)
I am looking onto it. Thanks
On Wed, Nov 7, 2018, 11:16 PM Radhika Dua [email protected] wrote:
@SidharthBansal https://github.com/SidharthBansal You can also try having a look at #3884 https://github.com/publiclab/plots2/pull/3884 in case it helps. :)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/publiclab/plots2/issues/3384#issuecomment-436713080, or mute the thread https://github.com/notifications/unsubscribe-auth/AUACQ3mwW84Md3MGDHZBwWUv2TWoIrjbks5usxvygaJpZM4W0-j5 .
@jywarren I guess https://github.com/publiclab/plots2/pull/3884/ has solved it. We can close this issue. I checked it on the production it works well.
This did work! However, I got a cached version of the page that did not look logged in until i refreshed. Browsers may respond differently. Going to suggest one follow-up change!
OK, i think every instance of this could be modified:
return_to = request.env['omniauth.origin'] || root_url
To:
return_to = request.env['omniauth.origin'] || root_url
return_to += '?_=' + Time.now.to_i.to_s
That way it busts the cache. @Radhikadua123 would you have any interest in opening an issue or a PR for this? Thanks everyone!
@jywarren So, do I have to open a pull request doing that you said in the last comment or I can do something more?
Yes, i think that's it! Thank you!
Great! I already did it. Let me test if everything is ok and after I'll do the pr for you!
Well, I can't test it locally but I think everything is okay
You can push it to unstable to check it.
On Thu, Nov 29, 2018, 4:23 AM Valentina Tironi <[email protected] wrote:
Well, I can't test it locally but I think everything is okay
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/publiclab/plots2/issues/3384#issuecomment-442636409, or mute the thread https://github.com/notifications/unsubscribe-auth/AUACQ3hU42nf-dU7s3Hrn44JnL3TrhAZks5uzxPYgaJpZM4W0-j5 .