Refactor common code for getting the signature key.

This commit is contained in:
GaryJones 2012-11-23 12:30:38 +00:00
parent a5ba220ae1
commit 87a4b17394
3 changed files with 21 additions and 19 deletions

View File

@ -55,15 +55,7 @@ class HmacSha1 extends SignatureMethod
public function buildSignature(Request $request, Client $client, Token $token = null)
{
$base_string = $request->getSignatureBaseString();
$request->base_string = $base_string;
$key_parts = array(
$client->getSecret(),
($token) ? $token->getSecret() : ''
);
$key_parts = Util::urlencodeRfc3986($key_parts);
$key = implode('&', $key_parts);
$key = $this->getSignatureKey($client, $token);
return base64_encode(hash_hmac('sha1', $base_string, $key, true));
}

View File

@ -52,15 +52,6 @@ class PlainText extends SignatureMethod
*/
public function buildSignature(Request $request, Client $client, Token $token = null)
{
$key_parts = array(
$client->getSecret(),
($token) ? $token->getSecret() : ''
);
$key_parts = Util::urlencodeRfc3986($key_parts);
$key = implode('&', $key_parts);
$request->base_string = $key;
return $key;
return $this->getSignatureKey($client, $token);
}
}

View File

@ -44,6 +44,25 @@ abstract class SignatureMethod
*/
abstract public function buildSignature(Request $request, Client $client, Token $token = null);
/**
* Get the signature key, made up of client and optionally token shared secrets.
*
* @param GaryJones\OAuth\Client $client
* @param GaryJones\OAuth\Token $token
*
* @return string
*/
public function getSignatureKey(Client $client, Token $token = null)
{
$key_parts = array(
$client->getSecret(),
($token) ? $token->getSecret() : '',
);
$key_parts = Util::urlencodeRfc3986($key_parts);
return implode('&', $key_parts);
}
/**
* Verifies that a given signature is correct.
*