2012-11-17 21:13:44 +00:00
|
|
|
<?php
|
2012-11-21 11:10:57 +00:00
|
|
|
/**
|
|
|
|
* OAuth
|
|
|
|
*
|
|
|
|
* @package OAuth
|
|
|
|
* @author Andy Smith
|
|
|
|
* @author Gary Jones <gary@garyjones.co.uk>
|
|
|
|
* @license https://raw.github.com/GaryJones/OAuth/master/LICENSE MIT
|
|
|
|
* @link https://github.com/GaryJones/OAuth
|
|
|
|
*/
|
|
|
|
|
2012-11-17 21:13:44 +00:00
|
|
|
namespace GaryJones\OAuth;
|
|
|
|
|
|
|
|
/**
|
2012-11-21 11:10:57 +00:00
|
|
|
* The HMAC-SHA1 signature method.
|
|
|
|
*
|
|
|
|
* The HMAC-SHA1 signature method. uses the HMAC-SHA1 signature algorithm as defined in [RFC2104]
|
2012-11-17 21:13:44 +00:00
|
|
|
* where the Signature Base String is the text and the key is the concatenated values (each first
|
|
|
|
* encoded per Parameter Encoding) of the Consumer Secret and Token Secret, separated by an '&'
|
|
|
|
* character (ASCII code 38) even if empty.
|
|
|
|
* - Chapter 9.2 ("HMAC-SHA1")
|
2012-11-21 11:10:57 +00:00
|
|
|
*
|
|
|
|
* @package OAuth
|
|
|
|
* @author Andy Smith
|
2012-11-17 21:13:44 +00:00
|
|
|
*/
|
|
|
|
class HmacSha1 extends SignatureMethod
|
|
|
|
{
|
2012-11-21 11:10:57 +00:00
|
|
|
/**
|
|
|
|
* Return the name of the Signature Method.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-11-17 21:13:44 +00:00
|
|
|
public function getName()
|
|
|
|
{
|
2012-11-18 01:32:38 +00:00
|
|
|
return 'HMAC-SHA1';
|
2012-11-17 21:13:44 +00:00
|
|
|
}
|
|
|
|
|
2012-11-21 11:10:57 +00:00
|
|
|
/**
|
|
|
|
* Build up the signature.
|
|
|
|
*
|
|
|
|
* oauth_signature is set to the concatenated encoded values of the Client Secret and
|
|
|
|
* Token Secret, separated by a '&' character (ASCII code 38), even if either secret is
|
|
|
|
* empty. The result MUST be encoded again.
|
|
|
|
* - Chapter 9.4.1 ("Generating Signatures")
|
|
|
|
*
|
|
|
|
* Please note that the second encoding MUST NOT happen in the SignatureMethod, as
|
|
|
|
* OAuthRequest handles this!
|
|
|
|
*
|
|
|
|
* @param GaryJones\OAuth\Request $request
|
|
|
|
* @param GaryJones\OAuth\Client $client
|
|
|
|
* @param GaryJones\OAuth\Token $token
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-11-22 16:27:47 +00:00
|
|
|
public function buildSignature(Request $request, Client $client, Token $token = null)
|
2012-11-17 21:13:44 +00:00
|
|
|
{
|
|
|
|
$base_string = $request->getSignatureBaseString();
|
|
|
|
$request->base_string = $base_string;
|
|
|
|
|
|
|
|
$key_parts = array(
|
2012-11-18 02:33:29 +00:00
|
|
|
$client->getSecret(),
|
|
|
|
($token) ? $token->getSecret() : ''
|
2012-11-17 21:13:44 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$key_parts = Util::urlencodeRfc3986($key_parts);
|
|
|
|
$key = implode('&', $key_parts);
|
|
|
|
|
|
|
|
return base64_encode(hash_hmac('sha1', $base_string, $key, true));
|
|
|
|
}
|
|
|
|
}
|