You are here

public function SamlService::sls in SAML Authentication 8.2

Same name and namespace in other branches
  1. 8.3 src/SamlService.php \Drupal\samlauth\SamlService::sls()
  2. 4.x src/SamlService.php \Drupal\samlauth\SamlService::sls()

Does processing for the Single Logout Service.

Return value

null|string Usually returns nothing. May return a URL to redirect to.

File

src/SamlService.php, line 287

Class

SamlService
Governs communication between the SAML toolkit and the IDP / login behavior.

Namespace

Drupal\samlauth

Code

public function sls() {

  // This call can either set an error condition or throw a
  // \OneLogin_Saml2_Error exception, depending on whether or not we are
  // processing a POST request. Don't catch the exception.
  $url = $this
    ->getSamlAuth()
    ->processSLO(FALSE, NULL, FALSE, NULL, TRUE);

  // Now look if there were any errors and also throw.
  $errors = $this
    ->getSamlAuth()
    ->getErrors();
  if (!empty($errors)) {

    // We have one or multiple error types / short descriptions, and one
    // 'reason' for the last error.
    throw new RuntimeException('Error(s) encountered during processing of SLS response. Type(s): ' . implode(', ', array_unique($errors)) . '; reason given for last error: ' . $this
      ->getSamlAuth()
      ->getLastErrorReason());
  }

  // Usually we don't get any URL returned. The case in which we do, seems to
  // be something like IDP-initiated logout. Therefore we won't do further
  // processing.
  if (!$url) {

    // Delete private stored session information.
    foreach ([
      'session_index',
      'session_expiration',
    ] as $key) {
      $this->privateTempStore
        ->delete($key);
    }
    user_logout();
  }
  return $url;
}