krz/vox-populi

A Tumblr web client.

clone: git clone https://gitbay.org/krz/vox-populi.git

main: vendor/eher/oauth/src/Eher/OAuth/HmacSha1.php · raw

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