[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/externals/twilio-php/Services/Twilio/ -> RequestValidator.php (source)

   1  <?php
   2  
   3  class Services_Twilio_RequestValidator
   4  {
   5  
   6      protected $AuthToken;
   7  
   8      function __construct($token)
   9      {
  10          $this->AuthToken = $token;
  11      }
  12      
  13      public function computeSignature($url, $data = array())
  14      {
  15          // sort the array by keys
  16          ksort($data);
  17  
  18          // append them to the data string in order
  19          // with no delimiters
  20          foreach($data as $key => $value)
  21              $url .= "$key$value";
  22              
  23          // This function calculates the HMAC hash of the data with the key
  24          // passed in
  25          // Note: hash_hmac requires PHP 5 >= 5.1.2 or PECL hash:1.1-1.5
  26          // Or http://pear.php.net/package/Crypt_HMAC/
  27          return base64_encode(hash_hmac("sha1", $url, $this->AuthToken, true));
  28      }
  29  
  30      public function validate($expectedSignature, $url, $data = array())
  31      {
  32          return $this->computeSignature($url, $data)
  33              == $expectedSignature;
  34      }
  35  
  36  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1