
Previously the destination parameter was added to the login-with.html.twig (#2925758: Respect the destination parameter when logging in)
However, the way it appends the destination to social login button will be cached with the template at the first time it was rendered.
The parameter could be dynamic to always redirect users back to where they were before login, e.g. a login link in comment block.
Additionally, the destination parameter was passed through Url::fromRoute() with a base:
prefix on return to Drupal after logging in, kludging away any query params that were contained therein.
(Original solution proposal with front-end JS removed)
Comment | File | Size | Author |
---|---|---|---|
#12 | social_auth-destination-2981743-12.patch | 3.39 KB | bradjones1 |
#7 | 2981743-7.patch | 2.78 KB | gvso |
#6 | interdiff-2981743-4-6.txt | 2.8 KB | gvso |
#6 | 2981743-6.patch | 2.83 KB | gvso |
#4 | social_auth-destination-2981743-4.patch | 2.81 KB | amourow |
Comments
Comment #2
gvsoAny ideas on how to solve it in Social Auth itself?
Comment #3
amourowrewrite the script from my theme into Social Auth module.
I also remove the destination preprocess from social_auth.module which is cached with the template.
Comment #4
amourowI accidentally removed the base_path from social_auth.module. Update the patch.
Comment #5
gvsoThanks for the patch!
It works perfectly if the user is not logged in. However, when the user is logged in, the destination parameter is concatenated more than once.
Comment #6
gvsoI made some changes to make it work
Comment #7
gvsoI removed unnecessary wrapper
Comment #8
amourowonce()
is not a core jquery method in Drupal 8 and it cause the TypeError issueAdd core/jquery.once to libraries.yml
Comment #9
amourowRe-upload the interdiff txt
Comment #10
davps CreditAttribution: davps as a volunteer and at DrupalJedi commentedI'm not sure that js solution is the correct way to resolve issue.
As possible case, it might be properly configured viewing element. As login_with is a theme with a preprocess you can add
$variables['#cache']['max-age'] = 0;
in the preprocess and it will disable caching for current element (themeing).As advanced solution need to add cache dependency (cache context) by destination
Comment #11
gvsoAny examples of how this solution would look like?
Comment #12
bradjones1It would look something like the enclosed patch. :-)
Comment #13
bradjones1I just noticed this patch also includes a cleanup of the handling of the destination parameter vis-a-vis the return to Drupal. If you are employing social auth as part of a chain-reaction of OAuth operations (e.g., OAuth Request is fulfilled after auth with a social provider) the query params in the destination string were kludged when generating a Url from the "base:" route.
I discovered this ticket via that fact pattern, and the cache issue effectively breaks destination handling for social auth, so I figure we can roll these together and have adjusted the ticket title as such.
Comment #14
adanielyan CreditAttribution: adanielyan commented#12 crashes the site on login. There are 3 errors in watchdog:
Failed to authenticate user. Exception: Cannot redirect to an empty URL.
LogicException: The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller? in Symfony\Component\HttpKernel\HttpKernel->handleRaw() (line 169 of /vendor/symfony/http-kernel/HttpKernel.php).
InvalidArgumentException: Cannot redirect to an empty URL. in Symfony\Component\HttpFoundation\RedirectResponse->setTargetUrl() (line 86 of /vendor/symfony/http-foundation/RedirectResponse.php).
Comment #15
bradjones1@adanielyan - Are you able to use xdebug to go in and see what might be causing this fact pattern? Alternatively, are you at DrupalCon this week and we could get together and look at it together?
Comment #16
gvsoComment #18
gvsoThanks, @bradjones1. I personally like avoiding a mix of markups with code as much as possible. I just added cache tags on the theme itself, so the cache gets invalidated after the destination parameter changes.
I liked the idea of just accepting paths. I think we shouldn't accept routes as possible destinations, though there were more changes needed to accomplish this fully.
Thanks, everyone!