There are some links, which contain "destination" parameter. It is not handled correctly, as result a user redirected to destination path, instead of login page on the cas server.

Steps to reproduce
0) Create content type with comments
1) Create a node
2) Open the node
3) Add a comment
4) Open the node
5) In the comment section click on the login link

So, all the links created with "destination" parameter will behave such way.
If I replace destination with returnto. It works as it should

Issue fork cas-3150047

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

LOBsTerr created an issue. See original summary.

lobsterr’s picture

Issue summary: View changes
lobsterr’s picture

Title: Paths with destination parameter redirected to destination instead of cas login page » Paths with destination parameter are redirected to destination instead of cas login page
lobsterr’s picture

I forgot to mention, that we replace the standard user.login path with cas.login path, but it doesn't change anything if we pass destination to cas.login it doesn't redirect us to login url.

if ($route = $collection->get('user.login')) {
      $route->setPath('/caslogin');
}
bkosborne’s picture

Yea this is a known issue, that's why I added support for "returnto" as an alternate way to redirect users after login. But that doesn't work when other systems in Drupal generate links with the destination param in them.

I think we can actually fix this and deprecate the "returnto" parameter. I did a little proof of concept and all we should need to do is remove the "destination" parameter from the request object before our controllers return the redirect to the CAS server. That way core's RedirectResponseSubscriber won't see it and redirect users there instead. Though, not sure why I didn't go with that approach initially. Maybe there's a reason...

lobsterr’s picture

@bkosborne, that what I am doing right. I redirect it first my controller, switch destination to returnto. Then I redirect it to cas module.
Yes, if it would be done on cas level. It will solve such cases

bkosborne’s picture

Title: Paths with destination parameter are redirected to destination instead of cas login page » Deprecate the special "returnto" parameter and add support for "destination" instead
Category: Bug report » Feature request

Changing this to a feature request

claudiu.cristea’s picture

@bkosborne, could you, please, share your PoC, mentioned in #5, as a MR so we can look into?

claudiu.cristea’s picture

Version: 8.x-1.6 » 2.x-dev
Status: Active » Needs work

Moving to 2.x

bkosborne’s picture

Title: Deprecate the special "returnto" parameter and add support for "destination" instead » 3150047-deprecate-returnto-param
Status: Needs work » Needs review

MR opened. It's really just a one line addition to the force login controller. This would allow users to create links like /cas?destination=/some/path. I removed an unused test in the MR as well as cleaned up some comments.

Adding the line didn't break any tests, but I think it may need some new ones.

claudiu.cristea’s picture

Thank you. I'll look into

Webbeh’s picture

Title: 3150047-deprecate-returnto-param » Deprecate the special "returnto" parameter and add support for "destination" instead
bkosborne’s picture

^ thanks, not sure how I did that!

claudiu.cristea’s picture

Assigned: Unassigned » claudiu.cristea

Assigning to work on it.

claudiu.cristea’s picture

Everything seems in place. However, I'm waiting for the cas_mock_server update to be merged.

pfrenssen’s picture

Upstream changes to cas_mock_server are merged! Thanks for working on this!

bkosborne’s picture

I'll give this a review today. Thank you

claudiu.cristea’s picture

Assigned: claudiu.cristea » Unassigned

I see there are coding standards failures. My proposal is fix & enforce coding standards in #3231319: Enforce coding standards.

bkosborne’s picture

Status: Needs review » Needs work

I re-based this against 2.x after merging #3231319: Enforce coding standards and resolved one minor conflict, though I quickly realized that doing so may not be a best practice, as you now cannot easily do a git pull on your local. You have to fetch and then reset --hard to the origin branch, sorry about that. Maybe you would have preferred I simply merged in 2.x.

Setting to needs work for my comment above about PHP 7.1, but other than that this looks good.

claudiu.cristea’s picture

Looks like it was introduced in PHP 7.1, and I think Drupal 8.x still supports down to PHP 7.0.8. Drupal 8 is unsupported in November though, and Drupal 9's minimum is PHP 7.3.

That's a good point. Either we postpone or we add 7.1 in CAS composer.json. With the later, sites still on 7.0 should pin 2.0.0-beta2.

But what if we remove the strict typing of the param instead of making it nullable? I think we don't break BC.

claudiu.cristea’s picture

The last commit is a tentative to support PHP 7.0.8

claudiu.cristea’s picture

Status: Needs work » Needs review
bkosborne’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. Good to merge in!

claudiu.cristea’s picture

Status: Reviewed & tested by the community » Fixed

Fixing credits. Thank you all.

Status: Fixed » Closed (fixed)

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

xem8vfdh’s picture

I am confused by this

I user to use "?returnto=/some/path" and it worked up until somehwat recently.

This module's documentation is confusing on the matter

Users can log in to your site with CAS a number of ways:

Visit /cas
Visit /caslogin (exact same behavior as above)
Visit /user/login and configure CAS to display a CAS login link on the page (See "General Settings" on the CAS settings form)

After a user logs in via CAS, they are returned to the homepage of your site by default. However, you can override this by setting a special "returnto" parameter in the login URL. For example: https://sample.com/caslogin?returnto=/some/other/page. Drupal's standard method for returning users to some other page via the "destination" query param does not currently work, but may after #3150047: Deprecate the special "returnto" parameter and add support for "destination" instead is addressed.

Was "returnto" the old way and now we should use "destination"? does the value of the param need to be a full uri or just a drupal path? url encoded?

bkosborne’s picture

Sorry about that, I've corrected the outdated documentation.

You should be using the "destination" param now, not "returnto". The value should be a Drupal path, and I believe should be encoded as any other query string parameter would be.

xem8vfdh’s picture

thanks!