You are here

function services_get_hash in Services 7

Same name and namespace in other branches
  1. 6.2 auth/services_keyauth/services_keyauth.module \services_get_hash()
2 calls to services_get_hash()
_services_keyauth_alter_browse_form_submit in auth/services_keyauth/services_keyauth.inc
_services_keyauth_authenticate_call in auth/services_keyauth/services_keyauth.inc

File

auth/services_keyauth/services_keyauth.module, line 95
@author Services Dev Team

Code

function services_get_hash($timestamp, $domain, $nonce, $method, $args) {
  $hash_parameters = array(
    $timestamp,
    $domain,
    $nonce,
    $method['#method'],
  );
  foreach ($method['#args'] as $key => $arg) {
    if ($arg['#signed'] == TRUE) {
      if (is_numeric($args[$key]) || !empty($args[$key])) {
        if (is_array($args[$key]) || is_object($args[$key])) {
          $hash_parameters[] = serialize($args[$key]);
        }
        else {
          $hash_parameters[] = $args[$key];
        }
      }
      else {
        $hash_parameters[] = '';
      }
    }
  }
  $api_key = db_query("SELECT kid FROM {services_keys} WHERE domain = :key", array(
    ':key' => $domain,
  ))
    ->fetchField('kid');
  return hash_hmac("sha256", implode(';', $hash_parameters), $api_key);
}