OAuthSignatureMethod_HMAC_SHA1.php 940 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as
  4. * defined in [RFC2104] where the Signature Base String is the text and the
  5. * key is the concatenated values (each first encoded per Parameter Encoding)
  6. * of the Consumer Secret and Token Secret, separated by an '&' character
  7. * (ASCII code 38) even if empty.
  8. * - Chapter 9.2 ("HMAC-SHA1")
  9. */
  10. class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod {
  11. function get_name() {
  12. return "HMAC-SHA1";
  13. }
  14. public function build_signature($request, $consumer, $token) {
  15. $base_string = $request->get_signature_base_string();
  16. $request->base_string = $base_string;
  17. $key_parts = array(
  18. $consumer->secret,
  19. ($token) ? $token->secret : ""
  20. );
  21. $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
  22. $key = implode('&', $key_parts);
  23. return base64_encode(hash_hmac('sha1', $base_string, $key, true));
  24. }
  25. }