You are here

function saml_sp__logout in SAML Service Provider 4.x

Same name and namespace in other branches
  1. 8.3 saml_sp.pages.inc \saml_sp__logout()
  2. 8.2 saml_sp.pages.inc \saml_sp__logout()
  3. 7.8 saml_sp.pages.inc \saml_sp__logout()
  4. 7.2 saml_sp.pages.inc \saml_sp__logout()
  5. 7.3 saml_sp.pages.inc \saml_sp__logout()
  6. 3.x saml_sp.pages.inc \saml_sp__logout()

Page callback to initiate the SAML SLO process.

1 string reference to 'saml_sp__logout'
saml_sp_menu in ./saml_sp.module
Implements hook_menu().

File

./saml_sp.pages.inc, line 20
User pages for the SAML Service Provider module.

Code

function saml_sp__logout() {

  // Load the IdP to authenticate against.
  $idp = saml_sp_drupal_login__get_idp();

  // Settings is a \OneLogin\Saml2\Settings object.
  $settings = saml_sp__get_settings($idp);
  $auth = new Auth($settings);

  // Handle SAML Request / Response and process Single LogOut.
  $auth
    ->processSLO();
  $errors = $auth
    ->getErrors();
  if (empty($errors)) {
    \Drupal::logger('saml_sp')
      ->notice('Handled SLO Request/Response from SSO.');
  }
  else {
    \Drupal::logger('saml_sp')
      ->error('Errors in SLO process: %errors', [
      '%errors' => implode(', ', $errors),
    ]);
  }

  // Redirect user to path defined in RelayState after logout, or to front page
  // if it's empty.
  \Drupal::messenger()
    ->addMessage(t('You have successfully logged out from all SSO services.'));
  drupal_goto($_GET['RelayState']);
}