0
|
1 <?php
|
|
2 /**
|
|
3 * The MIT License
|
|
4 * Copyright (c) 2007 Andy Smith
|
|
5 */
|
|
6 namespace Abraham\TwitterOAuth;
|
|
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 HmacSha1 extends SignatureMethod
|
|
16 {
|
|
17 /**
|
|
18 * {@inheritDoc}
|
|
19 */
|
|
20 public function getName()
|
|
21 {
|
|
22 return "HMAC-SHA1";
|
|
23 }
|
|
24
|
|
25 /**
|
|
26 * {@inheritDoc}
|
|
27 */
|
|
28 public function buildSignature(Request $request, Consumer $consumer, Token $token = null)
|
|
29 {
|
|
30 $signatureBase = $request->getSignatureBaseString();
|
|
31
|
|
32 $parts = [$consumer->secret, null !== $token ? $token->secret : ""];
|
|
33
|
|
34 $parts = Util::urlencodeRfc3986($parts);
|
|
35 $key = implode('&', $parts);
|
|
36
|
|
37 return base64_encode(hash_hmac('sha1', $signatureBase, $key, true));
|
|
38 }
|
|
39 }
|