You are here

function _saml_sp__extract_inbound_id in SAML Service Provider 4.x

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

Extract the unique ID in an inbound request.

Parameters

string $assertion: UUEncoded SAML assertion from the IdP (i.e. the POST request).

Return value

string|false The unique ID of the inbound request, if it can be decoded. This will be AuthRequest::ID_PREFIX, followed by a SHA1 hash.

1 call to _saml_sp__extract_inbound_id()
SamlSPController::consume in src/Controller/SamlSPController.php
Receive data back from the IdP.

File

./saml_sp.module, line 396
SAML Service Provider.

Code

function _saml_sp__extract_inbound_id($assertion) {

  // Decode the request.
  $xml = base64_decode($assertion);

  // Load the XML.
  $document = new DOMDocument();
  if ($document
    ->loadXML($xml)) {
    try {
      $id = @$document->firstChild->attributes
        ->getNamedItem('InResponseTo')->value;
      \Drupal::logger('saml_sp')
        ->notice('SAML login attempt with inbound ID: %id', [
        '%id' => $id,
      ]);
      return $id;
    } catch (Exception $e) {
      \Drupal::logger('saml_sp')
        ->error('Could not extract inbound ID. %exception', [
        '%exception' => $e,
      ]);
      return FALSE;
    }
  }
  \Drupal::logger('saml_sp')
    ->error('Cannot parse XM response:<br/> <pre>@response</pre>', [
    '@response' => $xml,
  ]);
  return FALSE;
}