You are here

function drupalauth4ssp_set_user_cookie in DrupalAuth for SimpleSAMLphp 8

Set auth cookie for the account.

@todo Move to class and depend on SSP config service?

Parameters

\Drupal\Core\Session\AccountInterface $account: User account.

See also

_drupalauth4ssp_get_simplesamlphp_config()

2 calls to drupalauth4ssp_set_user_cookie()
drupalauth4ssp_user_login in ./drupalauth4ssp.module
Implements hook_user_login().
DrupalAuthForSSPSubscriber::checkRedirection in src/EventSubscriber/DrupalAuthForSSPSubscriber.php
Kernel response event handler.

File

./drupalauth4ssp.module, line 35
DrupalAuth For simpleSAMLphp module.

Code

function drupalauth4ssp_set_user_cookie(AccountInterface $account) {

  // Get the configuration information from SimpleSAMLphp.
  $ssp_config = _drupalauth4ssp_get_simplesamlphp_config();

  // If we don't have configuration, exit without doing anything.
  if (!is_array($ssp_config)) {

    // The least we can do is write something to the watchdog so someone will
    // know what's happening.
    \Drupal::logger('drupalauth4ssp')
      ->warning('Could not use drupalauth for %name, could not get the SimpleSAMLphp configuration.', [
      '%name' => $account
        ->getAccountName(),
    ]);
    return;
  }

  // Store the authenticated user's uid in the cookie (create a validation hash
  // to ensure nobody tampers with the uid).
  // @todo Set via request
  $hash = Crypt::hmacBase64($account
    ->id(), $ssp_config['secretsalt'] . \Drupal::service('private_key')
    ->get());
  setcookie($ssp_config['cookie_name'], $hash . ':' . $account
    ->id(), 0, $ssp_config['baseurlpath']);
}