2c35c9760c81ea957efb56c95798afc7682b862a
[WP-Plugins/glm-member-db-registrations.git] /
1 <?php
2 namespace PayPal\Auth\Oauth;
3 /**
4  * The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104]
5  * where the Signature Base String is the text and the key is the concatenated values (each first
6  * encoded per Parameter Encoding) of the Consumer Secret and Token Secret, separated by an '&'
7  * character (ASCII code 38) even if empty.
8  *   - Chapter 9.2 ("HMAC-SHA1")
9  */
10 class OAuthSignatureMethodHmacSha1 extends OAuthSignatureMethod {
11         function get_name() {
12                 return "HMAC-SHA1";
13         }
14
15         public function build_signature($request, $consumer, $token) {
16                 $base_string = $request->get_signature_base_string();
17                 $base_string=preg_replace("/(%[A-Za-z0-9]{2})/e", "strtolower('\\0')", $base_string);//convert base string to lowercase
18                 $request->base_string = $base_string;
19
20                 $key_parts = array(
21                 $consumer->secret,
22                 ($token) ? $token->secret : ""
23                 );
24
25                 $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
26                 $key = implode('&', $key_parts);
27                 $key=preg_replace("/(%[A-Za-z0-9]{2})/e", "strtolower('\\0')", $key);//convert to lowercase
28                 return base64_encode(hash_hmac('sha1', $base_string, $key, true));
29         }
30 }