You are here

protected function NspiController::basicAuthenticator in Acquia Connector 8.2

Same name and namespace in other branches
  1. 8 tests/modules/src/Controller/NspiController.php \Drupal\acquia_connector_test\Controller\NspiController::basicAuthenticator()
  2. 3.x tests/modules/src/Controller/NspiController.php \Drupal\acquia_connector_test\Controller\NspiController::basicAuthenticator()

Basic authenticator.

Parameters

array $fields: Fields array.

array $data: Data array.

Return value

array Result array.

4 calls to NspiController::basicAuthenticator()
NspiController::getCommunicationSettings in tests/modules/src/Controller/NspiController.php
Test return communication settings for an account.
NspiController::getCredentials in tests/modules/src/Controller/NspiController.php
Test returns subscriptions for an email.
NspiController::nspiUpdate in tests/modules/src/Controller/NspiController.php
SPI API site update.
NspiController::validateAuthenticator in tests/modules/src/Controller/NspiController.php
Test validates an Acquia authenticator.

File

tests/modules/src/Controller/NspiController.php, line 377

Class

NspiController
Class NspiController.

Namespace

Drupal\acquia_connector_test\Controller

Code

protected function basicAuthenticator(array $fields, array $data) {
  $result = [];
  foreach ($fields as $field => $type) {
    if (empty($data['authenticator'][$field]) || !$type($data['authenticator'][$field])) {
      return $this
        ->errorResponse(self::ACQTEST_SUBSCRIPTION_MESSAGE_INVALID, $this
        ->t('Authenticator field @field is missing or invalid.', [
        '@field' => $field,
      ]));
    }
  }
  $now = \Drupal::time()
    ->getRequestTime();
  if ($data['authenticator']['time'] > $now + self::ACQTEST_SUBSCRIPTION_MESSAGE_LIFETIME) {
    return $this
      ->errorResponse(self::ACQTEST_SUBSCRIPTION_MESSAGE_FUTURE, $this
      ->t('Message time ahead of server time.'));
  }
  else {
    if ($data['authenticator']['time'] < $now - self::ACQTEST_SUBSCRIPTION_MESSAGE_LIFETIME) {
      return $this
        ->errorResponse(self::ACQTEST_SUBSCRIPTION_MESSAGE_EXPIRED, $this
        ->t('Message is too old.'));
    }
  }
  $result['error'] = FALSE;
  return $result;
}