]> git.mxchange.org Git - friendica.git/blob - src/Security/OAuth1/Signature/OAuthSignatureMethod_HMAC_SHA1.php
Fix notices
[friendica.git] / src / Security / OAuth1 / Signature / OAuthSignatureMethod_HMAC_SHA1.php
1 <?php
2
3 namespace Friendica\Security\OAuth1\Signature;
4
5 use Friendica\Security\OAuth1\OAuthRequest;
6 use Friendica\Security\OAuth1\OAuthUtil;
7
8 /**
9  * The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104]
10  * where the Signature Base String is the text and the key is the concatenated values (each first
11  * encoded per Parameter Encoding) of the Consumer Secret and Token Secret, separated by an '&'
12  * character (ASCII code 38) even if empty.
13  *   - Chapter 9.2 ("HMAC-SHA1")
14  */
15 class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod
16 {
17         function get_name()
18         {
19                 return "HMAC-SHA1";
20         }
21
22         /**
23          * @param OAuthRequest                             $request
24          * @param \Friendica\Security\OAuth1\OAuthConsumer $consumer
25          * @param \Friendica\Security\OAuth1\OAuthToken    $token
26          *
27          * @return string
28          */
29         public function build_signature(OAuthRequest $request, \Friendica\Security\OAuth1\OAuthConsumer $consumer, \Friendica\Security\OAuth1\OAuthToken $token = null)
30         {
31                 $base_string          = $request->get_signature_base_string();
32                 $request->base_string = $base_string;
33
34                 $key_parts = [
35                         $consumer->secret,
36                         ($token) ? $token->secret : "",
37                 ];
38
39                 $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
40                 $key       = implode('&', $key_parts);
41
42
43                 $r = base64_encode(hash_hmac('sha1', $base_string, $key, true));
44                 return $r;
45         }
46 }