You are here

public function Client::getSubscriptionCredentials in Acquia Connector 8

Same name and namespace in other branches
  1. 8.2 src/Client.php \Drupal\acquia_connector\Client::getSubscriptionCredentials()
  2. 3.x src/Client.php \Drupal\acquia_connector\Client::getSubscriptionCredentials()

Get account settings to use for creating request authorizations.

Parameters

string $email: Acquia account email.

string $password: Plain-text password for Acquia account. Will be hashed for communication.

Return value

array|false Credentials array or FALSE.

Throws

\Drupal\acquia_connector\ConnectorException

File

src/Client.php, line 108

Class

Client
Acquia connector client.

Namespace

Drupal\acquia_connector

Code

public function getSubscriptionCredentials($email, $password) {
  $body = [
    'email' => $email,
  ];
  $authenticator = $this
    ->buildAuthenticator($email, \Drupal::time()
    ->getRequestTime(), [
    'rpc_version' => ACQUIA_CONNECTOR_ACQUIA_SPI_DATA_VERSION,
  ]);
  $data = [
    'body' => $body,
    'authenticator' => $authenticator,
  ];

  // Don't use nspiCall() - key is not defined yet.
  $communication_setting = $this
    ->request('POST', '/agent-api/subscription/communication', $data);
  if ($communication_setting) {
    $crypt_pass = new CryptConnector($communication_setting['algorithm'], $password, $communication_setting['hash_setting'], $communication_setting['extra_md5']);
    $pass = $crypt_pass
      ->cryptPass();
    $body = [
      'email' => $email,
      'pass' => $pass,
      'rpc_version' => ACQUIA_CONNECTOR_ACQUIA_SPI_DATA_VERSION,
    ];
    $authenticator = $this
      ->buildAuthenticator($pass, \Drupal::time()
      ->getRequestTime(), [
      'rpc_version' => ACQUIA_CONNECTOR_ACQUIA_SPI_DATA_VERSION,
    ]);
    $data = [
      'body' => $body,
      'authenticator' => $authenticator,
    ];

    // Don't use nspiCall() - key is not defined yet.
    $response = $this
      ->request('POST', '/agent-api/subscription/credentials', $data);
    if ($response['body']) {
      return $response['body'];
    }
  }
  return FALSE;
}