You are here

protected function SamlService::getSamlAuth in SAML Authentication 8.3

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

Returns an initialized Auth class from the SAML Toolkit.

Parameters

string $purpose: (Optional) purpose for the config: 'metadata' / 'login' / 'acs' / 'logout' / 'sls-request' / 'sls-response'. Empty string means 'any', but likely shouldn't be used anywhere. (The way many callers hardcode this argument may seem strange, until you realize that _these callers_ only have one possible purpose too, in practice. This is almost sure to be refactored away in a future version.)

2 calls to SamlService::getSamlAuth()
SamlService::acs in src/SamlService.php
Processes a SAML response (Assertion Consumer Service).
SamlService::processLoginResponse in src/SamlService.php
Processes a SAML authentication response; throws an exception if invalid.

File

src/SamlService.php, line 815

Class

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

Namespace

Drupal\samlauth

Code

protected function getSamlAuth($purpose = '') {
  if (!isset($this->samlAuth[$purpose])) {
    $base_url = '';
    $config = $this->configFactory
      ->get('samlauth.authentication');
    if ($config
      ->get('use_base_url')) {
      $request = $this->requestStack
        ->getCurrentRequest();

      // The 'base url' for the SAML Toolkit is apparently 'all except the
      // last part of the endpoint URLs'. (Whoever wants a better explanation
      // can try to extract it from e.g. Utils::getSelfRoutedURLNoQuery().)
      $base_url = $request
        ->getSchemeAndHttpHost() . $request
        ->getBaseUrl() . '/saml';
    }
    $this->samlAuth[$purpose] = new Auth(static::reformatConfig($config, $base_url, $purpose, $this->keyRepository));
  }
  return $this->samlAuth[$purpose];
}