You are here

public function SamlSPDrupalLoginController::initiate in SAML Service Provider 8.3

Same name and namespace in other branches
  1. 8.2 modules/saml_sp_drupal_login/src/Controller/SamlSPDrupalLoginController.php \Drupal\saml_sp_drupal_login\Controller\SamlSPDrupalLoginController::initiate()
  2. 4.x modules/saml_sp_drupal_login/src/Controller/SamlSPDrupalLoginController.php \Drupal\saml_sp_drupal_login\Controller\SamlSPDrupalLoginController::initiate()
  3. 3.x modules/saml_sp_drupal_login/src/Controller/SamlSPDrupalLoginController.php \Drupal\saml_sp_drupal_login\Controller\SamlSPDrupalLoginController::initiate()

Initiate a SAML login for the given IdP.

1 string reference to 'SamlSPDrupalLoginController::initiate'
saml_sp_drupal_login.routing.yml in modules/saml_sp_drupal_login/saml_sp_drupal_login.routing.yml
modules/saml_sp_drupal_login/saml_sp_drupal_login.routing.yml

File

modules/saml_sp_drupal_login/src/Controller/SamlSPDrupalLoginController.php, line 21

Class

SamlSPDrupalLoginController
Provides route responses for the SAML SP module.

Namespace

Drupal\saml_sp_drupal_login\Controller

Code

public function initiate(Idp $idp) {
  $config = $this
    ->config('saml_sp_drupal_login.config');
  if ($this
    ->currentUser()
    ->isAuthenticated()) {
    $redirect_path = $config
      ->get('logged_in_redirect');
    if ($this
      ->config('saml_sp.settings')
      ->get('debug')) {
      _saml_sp__debug('$redirect_path', $redirect_path);
    }
    if (strpos($redirect_path, '/') === 0) {
      $url = URL::fromUserInput($redirect_path);
    }
    else {
      $url = URL::fromRoute($redirect_path);
    }

    // the user is already logged in, redirect
    return new RedirectResponse($url
      ->toString());
  }

  // Start the authentication process; invoke
  // saml_sp_drupal_login__saml_authenticate() when done.
  $callback = 'saml_sp_drupal_login__saml_authenticate';
  $forceAuthn = $config
    ->get('force_authentication') ?? FALSE;
  $return = saml_sp_start($idp, $callback, $forceAuthn);
  if (!empty($return)) {

    // Something was returned, echo it to the screen.
    return $return;
  }
}