You are here

public function SamlSPDrupalLoginController::initiate in SAML Service Provider 3.x

Same name and namespace in other branches
  1. 8.3 modules/saml_sp_drupal_login/src/Controller/SamlSPDrupalLoginController.php \Drupal\saml_sp_drupal_login\Controller\SamlSPDrupalLoginController::initiate()
  2. 8.2 modules/saml_sp_drupal_login/src/Controller/SamlSPDrupalLoginController.php \Drupal\saml_sp_drupal_login\Controller\SamlSPDrupalLoginController::initiate()
  3. 4.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) {
  if ($this
    ->currentUser()
    ->isAuthenticated()) {
    $redirect_path = $this
      ->config('saml_sp_drupal_login.config')
      ->get('logged_in_redirect');
    dpm($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.
  $return = saml_sp_start($idp, 'saml_sp_drupal_login__saml_authenticate');
  if (!empty($return)) {

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