protected function AcquiaLiftAPI::prepareRequest in Acquia Lift Connector 7.2
Add necessary headers before sending it to our Acquia Service
Parameters
string $method: The method used for the request such as PUT, POST, ...
string $path: The full path of the request
array $headers: An array of headers that will be used to generate the authentication header.
string|array $payload: The full request payload that will be sent to the server. If it is an array, it will be encoded to json first
Throws
Exception Throws an Exception if it was unable to add the Authorization header.
4 calls to AcquiaLiftAPI::prepareRequest()
- AcquiaLiftAPI::makeDeleteRequest in includes/
AcquiaLiftAPI.inc - Makes an Acquia Authenticated DELETE request to an API endpoint.
- AcquiaLiftAPI::makeGetRequest in includes/
AcquiaLiftAPI.inc - Makes an Acquia Authenticated GET request to an API endpoint.
- AcquiaLiftAPI::makePostRequest in includes/
AcquiaLiftAPI.inc - Makes an Acquia Authenticated POST request to an API endpoint.
- AcquiaLiftAPI::makePutRequest in includes/
AcquiaLiftAPI.inc - Makes an Acquia Authenticated PUT request to an API endpoint.
File
- includes/
AcquiaLiftAPI.inc, line 705
Class
Code
protected function prepareRequest($method, &$url, &$headers, $payload = "", $nonce = "", $timestamp) {
// Add tracking information and our client information
$id = uniqid();
if (!stristr($url, '?')) {
$url .= "?";
}
else {
$url .= "&";
}
$url .= 'request_id=' . $id;
$url .= '&client_id=' . $this->api_public_key;
// Add current Lift Drupal version
$headers += array(
'User-Agent' => 'acquia_lift/' . $this->lift_version,
);
$headers += array(
'Content-Type' => 'application/json',
);
$headers += array(
'X-Authorization-Timestamp' => $timestamp,
);
// SHA256 of Payload, binary form
$payload_hash = "";
// Set it to the headers if we have payload information where acceptable.
if ($method != "GET" || $method != "HEAD") {
if (isset($payload) && !empty($payload)) {
$payload_hash = base64_encode(hash("sha256", $payload, TRUE));
$headers['X-Authorization-Content-SHA256'] = $payload_hash;
}
}
// Calculate the Authorization headers and set it if we succeed. Throw an
// Exception if it is not able to calculate a hash.
$auth_header = $this
->getAuthHeader($method, $url, $headers, $payload_hash, $nonce);
if (empty($auth_header)) {
throw new AcquiaLiftCredsException(t('Invalid authentication string - subscription keys expired or missing.'));
}
$headers += array(
'Authorization' => $auth_header,
);
}