social-core icon indicating copy to clipboard operation
social-core copied to clipboard

Redirection on login no longer works on 2.0.0

Open nijel opened this issue 8 years ago • 10 comments

Previously it was possible to pass next as redirect on login. Since https://github.com/python-social-auth/social-core/commit/def3aa8bb3b048017069b9c7df6a07d8c78df7f4 this no longer works on partial pipelines as the session holding the redirect url is trashed before it is read.

The problem is that the session cleanup:

https://github.com/python-social-auth/social-core/blob/5b7cf69c1a74bc836be7af5005608217e28968c1/social_core/actions.py#L40-L41

Is before reading the data from the session:

https://github.com/python-social-auth/social-core/blob/5b7cf69c1a74bc836be7af5005608217e28968c1/social_core/actions.py#L45-L48

nijel avatar Oct 29 '18 12:10 nijel

@nijel, clean_partial_pipeline doesn't clean the whole session, just removes the entry for partial_pipeline_token if you happen to still be using the session to store the partial pipeline data.

omab avatar Oct 29 '18 12:10 omab

Right, I've meanwhile found that the problem is not the actual redirect, that's just a symptom which shows in the tests. The actual problem is destroying the pipeline - I have more partial pipelines and this cleanup seems to break it. Right now I don't have time to diagnose this, but removing the clean_partial_pipeline invocation from do_complete does fix the issue for me.

nijel avatar Oct 29 '18 13:10 nijel

:+1: We have also got into this issue. During the pipeline we are returning a redirection for user to provide a few more things via a form and insert these into partial pipeline model data (we are using django here). Unfortunately, do_complete nukes the partial pipeline data completely thus our redirect breaks badly due to missing token in the session. Is there any workaround for this? How do we handle a flow when pipeline returns a redirection that modifies the pipeline data a little bit, and then returns back to the pipeline.

maciej-gol avatar Nov 09 '18 13:11 maciej-gol

I didn't yet find time to investigate this deeper, the workaround for me is to disable pipeline removal in the strategy:

https://github.com/WeblateOrg/weblate/commit/dffc040ee7c9ca8e9ec2b0e7352edf6b0fd176b7#diff-8c861f686356c5d8d5e42a2bdb7666cfR66

The proper fix probably would be to remove partial pipeline only once it's actually completed in do_complete and do_disconnect.

nijel avatar Nov 09 '18 13:11 nijel

@nijel Thanks! That looks like a workaround :D Plus removing the partial pipeline as the last step of the pipeline. Will consider that!

maciej-gol avatar Nov 09 '18 13:11 maciej-gol

I've looked into this issue as I'm still unable to reproduce it, maybe I'm not understanding it properly. My test was done using social-examples. For it I've done the following:

  1. Added two extra partial pipeline steps, one asking for country and another asking for city
  2. Added a next=/admin/ to the links to ensure there's a redirect location past the auth flow

Running this case worked without problems, once I've completed the two partial steps, I get sent to the original next value.

If there's anything else I need to take into account, please let me know.

omab avatar Nov 18 '18 19:11 omab

Steps to reproduce:

  • Enter social authorization flow as usual.
  • have one of the steps return a redirection to some view that makes use of partia token value stored in request.session.
  • fetch the partial pipeline model, modify its context a bit and Save.
  • make the view return redirection to do_complete social view.
  • after redirection, the pipeline should continue with New variables being available.

What happens instead: Step two fails. The view cant fetch the partial token from request.session because as soon ss redirection is returned from the pipeline, the partial pipeline is cleared

niedz., 18 lis 2018, 20:51: Matías Aguirre [email protected] napisał(a):

I've looked into this issue as I'm still unable to reproduce it, maybe I'm not understanding it properly. My test was done using social-examples https://github.com/python-social-auth/social-examples. For it I've done the following:

  1. Added two extra partial pipeline steps, one asking for country and another asking for city
  2. Added a next=/admin/ to the links to ensure there's a redirect location past the auth flow

Running this case worked without problems, once I've completed the two partial steps, I get sent to the original next value.

If there's anything else I need to take into account, please let me know.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/python-social-auth/social-core/issues/287#issuecomment-439720405, or mute the thread https://github.com/notifications/unsubscribe-auth/ABxoTSeeYP1ZrGzDHMMGJXUf7FqMZlWLks5uwbpGgaJpZM4X_FvY .

maciej-gol avatar Nov 18 '18 20:11 maciej-gol

I believe that another way to reproduce this is to have partial pipelines steps after email validations. The validation link in the email is (per the examples) to social:complete (in django), which then removes the pipeline. If it would help, I can try to work up a minimal example of this in 3.0.0--my use case is that after email is validated and a user is created, we create an attached user profile and prompt the user for additional information.

averymd avatar Mar 07 '19 00:03 averymd

@omab and @nijel, I ran into a different issue that was caused by the cleaning up logic. I realized that the problem is caused by this line.

    def clean_partial_pipeline(self, token):
        self.storage.partial.destroy(token)
        self.session_pop(PARTIAL_TOKEN_SESSION_NAME)

When there are multiple partials, the cleanup of the old partial happens after the new partial is created. As a result, when the token is removed from the session, it actually removes the token for the most recently created partial and not the old one. I was able to verify this in the Social Django Example project.

Using the Social Example project as an example, it collects the Country and the City from the user before the connection is finalized.

  • Try and connect to Google OAuth2, then it does the redirect to collect Country information
  • Create partial data for country
    • Create Partial in DB
    • Add country partial token to session
  • Redirect to collect country
  • Create partial data for city
    • Create city partial in DB
    • Add city partial token to session <--- this step
  • Clean up partial data for country
    • Remove country partial data in DB
    • Remove city partial token from the session <--- is undone by this step

To reproduce this in the Django Social Example project, you would need to not pass the partial_token as a query parameter. It tries to retrieve the partial_token from the request parameter or the session. I worked around this issue by passing the current_partial.token to /complete/<backend>/ requests.

I hope this helps.

jaywhy13 avatar Mar 19 '20 17:03 jaywhy13

@omab, I noticed you closed this issue. Is the problem I described going to be fixed? Should I log a separate issue?

jaywhy13 avatar Mar 23 '20 16:03 jaywhy13