public function ClientManager::getRequestSignature in Acquia Content Hub 8
Extracts HMAC signature from the request.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The Request to evaluate signature.
string $secret_key: The Secret Key.
Return value
string A base64 encoded string signature.
Overrides ClientManagerInterface::getRequestSignature
File
- src/
Client/ ClientManager.php, line 244
Class
- ClientManager
- Provides a service for managing pending server tasks.
Namespace
Drupal\acquia_contenthub\ClientCode
public function getRequestSignature(Request $request, $secret_key = '') {
// Extract signature information from the request.
$headers = array_map('current', $request->headers
->all());
$http_verb = $request
->getMethod();
// Adding the Request Query string.
$path = $request
->getRequestUri();
$body = $request
->getContent();
// If the headers are not given, then the request is probably not coming
// from the Content Hub. Replace them for empty string to fail validation.
$content_type = isset($headers['content-type']) ? $headers['content-type'] : '';
$date = isset($headers['date']) ? $headers['date'] : '';
$message_array = [
$http_verb,
md5($body),
$content_type,
$date,
'',
$path,
];
$message = implode("\n", $message_array);
$s = hash_hmac('sha256', $message, $secret_key, TRUE);
$signature = base64_encode($s);
return $signature;
}