nxssc_SigMethod_HMAC_SHA1

The NextScripts: Social Networks Auto-Poster nxssc SigMethod HMAC SHA1 class.

Defined (1)

The class is defined in the following location(s).

/inc-cl/apis/scOAuth.php  
  1. class nxssc_SigMethod_HMAC_SHA1 extends nxssc_SignatureMethod { 
  2. public $name = 'HMAC-SHA1'; 
  3. public function signing_base($request, $consumer_secret, $token) { 
  4. $sig = array(rawurlencode($request['method']), rawurlencode($request['normalized_url']), rawurlencode($request['normalized_parameters'])); 
  5. $key = sprintf("%s&", rawurlencode($consumer_secret)); 
  6. if (isset($token)) $key .= rawurlencode($token->secret); 
  7. $raw = implode('&', $sig); 
  8. return array ($key, $raw); 
  9. public function sign($request, $consumer_secret, $token) { 
  10. $key_raw = $this->signing_base($request, $consumer_secret, $token);// prr($key_raw); 
  11. $basestring = base64_encode (hash_hmac('sha1', $key_raw[1], $key_raw[0], true)); //echo $basestring; 
  12. return rawurlencode($basestring); 
  13.  
  14. public static function urlencode_rfc3986($input) { 
  15. if (is_array($input)) { 
  16. return array_map(array('nxssc_SigMethod_HMAC_SHA1', 'urlencode_rfc3986'), $input); 
  17. } else if (is_scalar($input)) { 
  18. return str_replace( 
  19. '+',  
  20. ' ',  
  21. str_replace('%7E', '~', rawurlencode($input)) 
  22. ); 
  23. } else { 
  24. return ''; 
  25. public function get_normalized_http_url($url) { 
  26. $parts = parse_url($url); 
  27.  
  28. $port = @$parts['port']; 
  29. $scheme = $parts['scheme']; 
  30. $host = $parts['host']; 
  31. $path = @$parts['path']; 
  32.  
  33. $port or $port = ($scheme == 'https') ? '443' : '80'; 
  34.  
  35. if (($scheme == 'https' && $port != '443')|| ($scheme == 'http' && $port != '80')) { 
  36. $host = "$host:$port"; 
  37. return "$scheme://$host$path"; 
  38. public function get_signature_base_string($url, $params, $method = 'GET') { 
  39. $parts = array( $method, $this->get_normalized_http_url($url), $params); //prr($parts); 
  40. $parts = $this->urlencode_rfc3986($parts); 
  41. return implode('&', $parts); 
  42.  
  43. public function sign2($request, $consumer_secret, $token) { 
  44.  
  45. $base_string = $this->get_signature_base_string($request['normalized_url'], $request['normalized_parameters'], $request['method']); 
  46. //$request->base_string = $base_string; 
  47.  
  48. //$key_parts = array( $consumer_secret); if ($token) $key_parts[] = $token->secret; 
  49. $key_parts = array( $consumer_secret, ($token) ? $token : ""); 
  50.  
  51. //$key_parts = array( $consumer_secret, ""); 
  52.  
  53. $key_parts = $this->urlencode_rfc3986($key_parts); 
  54. $key = implode('&', $key_parts); //prr($key); prr($base_string); 
  55. return rawurlencode(base64_encode(hash_hmac('sha1', $base_string, $key, true))); 
  56.  
  57.  
  58. public function check($request, $consumer_secret, $token, $signature) { 
  59. $built = $this->sign($request, $consumer_secret, $token); 
  60. return $built == $signature;