You are here

public function SamlService::getAttributeByConfig in SAML Authentication 4.x

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

Returns value from a SAML attribute whose name is configured in our module.

This method will return valid data after a response is processed (i.e. after samlAuth->processResponse() is called).

Parameters

string $config_key: A key in the module's configuration, containing the name of a SAML attribute.

Return value

mixed|null The SAML attribute value; NULL if the attribute value, or configuration key, was not found.

2 calls to SamlService::getAttributeByConfig()
SamlService::acs in src/SamlService.php
Processes a SAML response (Assertion Consumer Service).
SamlService::doLogin in src/SamlService.php
Logs a user in, creating / linking an account; synchronizes attributes.

File

src/SamlService.php, line 789

Class

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

Namespace

Drupal\samlauth

Code

public function getAttributeByConfig($config_key) {
  $attribute_name = $this->configFactory
    ->get('samlauth.authentication')
    ->get($config_key);
  if ($attribute_name) {
    $attribute = $this
      ->getSamlAuth('acs')
      ->getAttribute($attribute_name);
    if (!empty($attribute[0])) {
      return $attribute[0];
    }
    $friendly_attribute = $this
      ->getSamlAuth('acs')
      ->getAttributeWithFriendlyName($attribute_name);
    if (!empty($friendly_attribute[0])) {
      return $friendly_attribute[0];
    }
  }
}