You are here

function acquia_search_auth_cookie in Acquia Search 6.3

Same name and namespace in other branches
  1. 6 acquia_search.module \acquia_search_auth_cookie()

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

Parameters

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

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

$derived_key: Optional string to supply the derived key.

Return value

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_Service.php
Modify the url and add headers appropriate to authenticate to Acquia Search.

File

./acquia_search.module, line 293
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(acquia_search_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,
  );
}