You are here

public function LogoutController::getServerLogoutUrl in CAS 2.x

Same name and namespace in other branches
  1. 8 src/Controller/LogoutController.php \Drupal\cas\Controller\LogoutController::getServerLogoutUrl()

Return the logout URL for the CAS server.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The current request, to provide base url context.

Return value

string The fully constructed server logout URL.

1 call to LogoutController::getServerLogoutUrl()
LogoutController::logout in src/Controller/LogoutController.php
Logs a user out of Drupal, then redirects them to the CAS server logout.

File

src/Controller/LogoutController.php, line 105

Class

LogoutController
Class LogoutController.

Namespace

Drupal\cas\Controller

Code

public function getServerLogoutUrl(Request $request) {

  // @todo Allow cas server config to be altered.
  $casServerConfig = CasServerConfig::createFromModuleConfig($this->settings);
  $base_url = $casServerConfig
    ->getServerBaseUrl() . 'logout';

  // CAS servers can redirect a user to some other URL after they end
  // the user session. Check if we're configured to send along this
  // destination parameter and pass it along if so.
  if (!empty($this->settings
    ->get('logout.logout_destination'))) {
    $destination = $this->settings
      ->get('logout.logout_destination');
    if ($destination == '<front>') {

      // If we have '<front>', resolve the path.
      $return_url = $this->urlGenerator
        ->generate($destination, [], UrlGeneratorInterface::ABSOLUTE_URL);
    }
    elseif (UrlHelper::isExternal($destination)) {

      // If we have an absolute URL, use that.
      $return_url = $destination;
    }
    else {

      // This is a regular Drupal path.
      $return_url = $request
        ->getSchemeAndHttpHost() . '/' . ltrim($destination, '/');
    }

    // CAS 2.0 uses 'url' param, while newer versions use 'service'.
    if ($casServerConfig
      ->getProtocolVerison() == '2.0') {
      $params['url'] = $return_url;
    }
    else {
      $params['service'] = $return_url;
    }
    return $base_url . '?' . UrlHelper::buildQuery($params);
  }
  else {
    return $base_url;
  }
}