You are here

public function SamlService::getMetadata in SAML Authentication 8.3

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

Show metadata about the local sp. Use this to configure your saml2 IdP.

Parameters

int|null $validity: (Optional) 'validUntil' property of the metadata (which is a date, not an interval) will be this many seconds into the future. If left empty, the SAML PHP Toolkit will assign a value.

int|null $cache_duration: (Optional) number of seconds used for the 'cacheDuration' property of the metadata. If left empty, the SAML PHP Toolkit will assign a value.

Return value

mixed XML string representing metadata.

Throws

\OneLogin\Saml2\Error If the metatdad is invalid.

File

src/SamlService.php, line 222

Class

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

Namespace

Drupal\samlauth

Code

public function getMetadata($validity = NULL, $cache_duration = NULL) {

  // It's actually strange how we need to instantiate an Auth object when
  // we only need the Settings object. We may refactor that when refactoring
  // getSamlAuth().
  $settings = $this
    ->getSamlAuth('metadata')
    ->getSettings();
  $metadata = $settings
    ->getSPMetadata(FALSE, $validity, $cache_duration);
  $errors = $settings
    ->validateMetadata($metadata);
  if (empty($errors)) {
    return $metadata;
  }
  else {
    throw new SamlError('Invalid SP metadata: ' . implode(', ', $errors), SamlError::METADATA_SP_INVALID);
  }
}