I tested a core patch for a regression "[Regression] login link has no destination=drupalSettings.path, so dumps you on the profile"

This core issue is why my users are ending up on /user after CAS login because the login link doesn't have any destination.

Here is the core issue: https://www.drupal.org/project/drupal/issues/2582797

Here's my comment about how CAS interacts with the patch: https://www.drupal.org/project/drupal/issues/2582797#comment-12949727

I tested the patch in #106 and it did not play well with the cas module enabled

My use case: I have cas "forced login" turned on for all "/user/*" links on D8 client sites so that clicking on the login menu link actually redirects to /caslogin which in turn redirects to my SSO server then back to the client site.

Without the patch:
* I am redirected to my cas server for login and then dumped back to /user as this issue description notes

With the patch:
* I am redirected right back to my current page and never go to the cas server

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lolcode created an issue. See original summary.

bkosborne’s picture

Title: CAS conflict with core login destination patch » CAS automatic login should respect existing destination parameter
Version: 8.x-1.2 » 8.x-1.x-dev
Status: Active » Needs review
FileSize
1.12 KB

Ok, I verified this is a bug with the CAS module. I don't think it has anything to do with that core patch, only that the core patch surfaced the problem.

Here's the problem in more detail:

- You have your site configured to force users to login when visiting /user/*
- User visits /user/login?destination=/some/other/page
- CAS event subscriber detects that user should be forced to login, so it redirects them to the CAS server to login
- Drupal core has RedirectResponseSubscriber that runs on redirect requests and checks if the URL contains a "destination" parameter in it. If so, then it sends the user to the destination instead of to the original redirect location (the CAS server).

Can you please try out this patch and see if it works for you? Not sure if the tests will pass or not. But I can fix them if this addresses your problem.

bkosborne’s picture

Actually here's the correct patch.

bkosborne’s picture

Hmpf... actually this is quite tricky, due to core's RedirectResponseSubscriber.

Imagine this scenario:

1. CAS module configured to automatically log someone in when they visit page /node/1.
2. Someone visits page /node/1?destination=/node/2.
3. Ideally, CAS should authenticate the user, and return them to the exact page /node/1?destination=/node/2.

My current path will authenticate them and return them to /node/2, which is really not quite right. The destination parameter in Drupal is meant to be used for form submissions, so that once a form is submitted on /node/1, the user would be returned to /node/2. The CAS module should not perform that redirect to /node/2.

There seems to be no way to actually return them to /node/1?destination=/node/2, because after we authenticate the user with CAS, the CAS module returns a redirect response to the /node/1?destination=/node/2, but Drupal core's RedirectResponseSubscriber would intervene and actually return them to /node/2.

What I can do instead is just strip the destination parameter entirely so that this happens:

1. CAS module configured to automatically log someone in when they visit page /node/1.
2. Someone visits page /node/1?destination=/node/2.
3. CAS module authenticates user and returns them to /node/1. The destination param is stripped.

This would at the very least fix the issue that surfaced from patch in #2582797: [Regression] login link has no destination=drupalSettings.path, so dumps you on the profile. Basically if someone visited /user/login?destination=/node/1, and CAS was configured to auto login users that visit /user/*, then it would log them in, but it would return them to the page they were on and not /node/1. It's not ideal, but not sure we can get to ideal.

bkosborne’s picture

Okay, I actually found a way to make this work. I think it actually simplifies things a bit too.

Status: Needs review » Needs work

The last submitted patch, 5: cas-auto-login-respect-destination-param-3029612-5.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

lolcode’s picture

Thanks for your fast turnaround!

Patch #5 here plus patch #115 on the core issue works great for my use case with /user/* as forced login.

bkosborne’s picture

This may fix the tests

Status: Needs review » Needs work

The last submitted patch, 8: cas-auto-login-respect-destination-param-3029612-8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

bkosborne’s picture

Status: Needs work » Needs review
FileSize
5.89 KB

Let's try again

bkosborne’s picture

Status: Needs review » Fixed

Alright I ran thru this logic again and I think this is the way to go. This is a good bug to have fixed.

  • bkosborne committed d27bcb0 on 8.x-1.x
    Issue #3029612 by bkosborne: CAS automatic login should respect existing...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.