You are here

function acquia_search_auth_cookie in Acquia Search 6

Same name and namespace in other branches
  1. 6.3 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.

3 calls to acquia_search_auth_cookie()
Acquia_Search_Service::makeServletRequest in ./Acquia_Search_Service.php
Make a request to a servlet (a path) that's not a standard path.
Acquia_Search_Service::_sendRawGet in ./Acquia_Search_Service.php
Central method for making a get operation against this Solr Server
Acquia_Search_Service::_sendRawPost in ./Acquia_Search_Service.php
Central method for making a post operation against this Solr Server

File

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

Code

function acquia_search_auth_cookie(&$url, $string = '', $derived_key = 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;
  $nonce = md5(acquia_agent_random_bytes(55));
  if ($string) {
    $auth_header = acquia_search_authenticator($string, $nonce, $derived_key);
  }
  else {
    $auth_header = acquia_search_authenticator($path . $query, $nonce, $derived_key);
  }
  return array(
    $auth_header,
    $nonce,
  );
}