You are here

function SearchApiAcquiaSearchConnection::authCookie in Acquia Search for Search API 7.2

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.

See also

acquia_search_auth_cookie

1 call to SearchApiAcquiaSearchConnection::authCookie()
SearchApiAcquiaSearchConnection::prepareRequest in includes/v2/SearchApiAcquiaSearchConnection.php
Modify the url and add headers appropriate to authenticate to Acquia Search.

File

includes/v2/SearchApiAcquiaSearchConnection.php, line 227

Class

SearchApiAcquiaSearchConnection
Starting point for the Solr API. Represents a Solr server resource and has methods for pinging, adding, deleting, committing, optimizing and searching.

Code

function authCookie(&$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;

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