You are here

function acquia_search_auth_cookie in Acquia Connector 7.3

Same name and namespace in other branches
  1. 7 acquia_search/acquia_search.module \acquia_search_auth_cookie()
  2. 7.2 acquia_search/acquia_search.module \acquia_search_auth_cookie()

Modify a solr base url and construct a hmac authenticator cookie.

Parameters

string $url: The solr url beng requested - passed by reference and may be altered.

string $string: A string - the data to be authenticated, or empty to just use the path and query from the url to build the authenticator.

string $derived_key: Optional string to supply the derived key.

Return value

array An array containing the string to be added as the content of the Cookie header to the request and the nonce.

1 call to acquia_search_auth_cookie()
AcquiaSearchService::prepareRequest in acquia_search/Acquia_Search_Service.php
Modify the url and add headers appropriate to authenticate Acquia Search.

File

acquia_search/acquia_search.module, line 728
Integration between Acquia Drupal and Acquia's hosted solr search service.

Code

function acquia_search_auth_cookie(&$url, $string = '', $derived_key = NULL, $env_id = NULL) {
  $uri = parse_url($url);

  // Add a scheme - should always be https if available.
  if (in_array('ssl', stream_get_transports(), TRUE) && !defined('ACQUIA_DEVELOPMENT_NOSSL')) {
    $scheme = 'https://';
    $port = '';
  }
  else {
    $scheme = 'http://';
    $port = isset($uri['port']) && $uri['port'] != 80 ? ':' . $uri['port'] : '';
  }
  $path = isset($uri['path']) ? $uri['path'] : '/';
  $query = isset($uri['query']) ? '?' . $uri['query'] : '';
  $url = $scheme . $uri['host'] . $port . $path . $query;

  // 32 character nonce.
  $nonce = base64_encode(drupal_random_bytes(24));
  if ($string) {
    $auth_header = acquia_search_authenticator($string, $nonce, $derived_key, $env_id);
  }
  else {
    $auth_header = acquia_search_authenticator($path . $query, $nonce, $derived_key, $env_id);
  }
  return array(
    $auth_header,
    $nonce,
  );
}