public function CasHelper::handleReturnToParameter in CAS 8
Same name and namespace in other branches
- 2.x src/Service/CasHelper.php \Drupal\cas\Service\CasHelper::handleReturnToParameter()
Converts a "returnto" query param to a "destination" query param.
The original service URL for CAS server may contain a "returnto" query parameter that was placed there to redirect a user to specific page after logging in with CAS.
Drupal has a built in mechanism for doing this, by instead using a "destination" parameter in the URL. Anytime there's a RedirectResponse returned, RedirectResponseSubscriber looks for the destination param and will redirect a user there instead.
We cannot use this built in method when constructing the service URL, because when we redirect to the CAS server for login, Drupal would see our destination parameter in the URL and redirect there instead of CAS.
However, when we redirect the user after a login success/failure, we can then convert it back to a "destination" parameter and let Drupal do it's thing when redirecting.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The Symfony request object.
File
- src/
Service/ CasHelper.php, line 201
Class
- CasHelper
- Class CasHelper.
Namespace
Drupal\cas\ServiceCode
public function handleReturnToParameter(Request $request) {
if ($request->query
->has('returnto')) {
$this
->log(LogLevel::DEBUG, "Converting query parameter 'returnto' to 'destination'.");
$request->query
->set('destination', $request->query
->get('returnto'));
}
}