You are here

function sign_hmac_sha1 in Dropbox Client 7.4

Same name and namespace in other branches
  1. 7 oauth.php \sign_hmac_sha1()
  2. 7.2 oauth.php \sign_hmac_sha1()
  3. 7.3 oauth.php \sign_hmac_sha1()

Signs an array of oauth parameters according to the 1.0 spec using the hmac-sha1 hasing algorithm

Parameters

string $method either GET or POST:

string $baseurl the baseurl we are authenticating againts:

string $secret the consumer secret key:

array $parameters all parameters that need to be signed (NOTE: the token secret key should be added here):

Return value

string the signature

1 call to sign_hmac_sha1()
build_auth_array in ./oauth.php
Assemble an associative array with oauth values

File

./oauth.php, line 49

Code

function sign_hmac_sha1($method, $baseurl, $secret, array $parameters) {
  $data = $method . '&';
  $data .= urlencode($baseurl) . '&';
  $oauth = '';
  ksort($parameters);

  //Put the token secret in if it does not exist. It

  //will be empty if it does not exist as per the spec.
  if (!array_key_exists('oauth_token_secret', $parameters)) {
    $parameters['oauth_token_secret'] = '';
  }
  foreach ($parameters as $key => $value) {

    //Don't include the token secret into the base string
    if (strtolower($key) != 'oauth_token_secret') {
      $oauth .= "&{$key}={$value}";
    }
  }
  $data .= urlencode(substr($oauth, 1));
  $secret .= '&' . $parameters['oauth_token_secret'];
  return base64_encode(hash_hmac('sha1', $data, $secret, true));
}