You are here

public function ContentHubSubscription::setHmacAuthorization in Acquia Content Hub 8

Wraps a request using HMAC authentication.

If the current site is connected to Content Hub it wraps the request using HMAC algorithm. If not connected, it just returns the same request object.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The Request to wrap using HMAC authentication.

bool|true $use_shared_secret: Whether to use shared_secret or secret_key.

Return value

\Symfony\Component\HttpFoundation\Request The HMAC wrapped request.

File

src/ContentHubSubscription.php, line 446

Class

ContentHubSubscription
Handles operations on the Acquia Content Hub Subscription.

Namespace

Drupal\acquia_contenthub

Code

public function setHmacAuthorization(Request $request, $use_shared_secret = TRUE) {
  if ($this->clientManager
    ->isConnected()) {
    $request->headers
      ->set('Date', gmdate('D, d M Y H:i:s T'), TRUE);
    $secret = $use_shared_secret ? $this
      ->getSharedSecret() : $this->config
      ->get('secret_key');
    $signature = $this->clientManager
      ->getRequestSignature($request, $secret);
    $request->headers
      ->set('Authorization', 'Acquia ContentHub:' . $signature, TRUE);
  }
  return $request;
}