Added RequestInterface to make integration easier.

Since now only a RequestInterface is needed instead of a Request object,
it becomes easier to use the Server component with a different Request
object, such as the Symfony or Zend Framework Request objects.

This will now only need a small wrapper, instead of extending and
rewriting the existing Request object.
This commit is contained in:
Jacob Kiers
2013-02-08 10:57:53 +00:00
parent c471cd2b8d
commit be09ba0216
6 changed files with 199 additions and 27 deletions

View File

@@ -77,7 +77,7 @@ public function addSignatureMethod(SignatureMethod $signature_method)
*
* Returns the request token on success
*
* @param JacobKiers\OAuth\Request $request
* @param JacobKiers\OAuth\RequestInterface $request
*
* @return JacobKiers\OAuth\Token
*/
@@ -93,7 +93,7 @@ public function fetchRequestToken(Request &$request)
$this->checkSignature($request, $client, $token);
// Rev A change
$callback = $request->getParameter('oauth_callback');
$callback = $request->getOAuthCallback();
return $this->data_store->newRequestToken($client, $callback);
}
@@ -103,7 +103,7 @@ public function fetchRequestToken(Request &$request)
*
* Returns the access token on success.
*
* @param JacobKiers\OAuth\Request $request
* @param JacobKiers\OAuth\RequestInterface $request
*
* @return JacobKiers\OAuth\Token
*/
@@ -119,7 +119,7 @@ public function fetchAccessToken(Request &$request)
$this->checkSignature($request, $client, $token);
// Rev A change
$verifier = $request->getParameter('oauth_verifier');
$verifier = $request->getOAuthVerifier();
return $this->data_store->newAccessToken($token, $client, $verifier);
}
@@ -127,7 +127,7 @@ public function fetchAccessToken(Request &$request)
/**
* Verify an api call, checks all the parameters.
*
* @param JacobKiers\OAuth\Request $request
* @param JacobKiers\OAuth\RequestInterface $request
*
* @return array Client and Token
*/
@@ -145,7 +145,7 @@ public function verifyRequest(Request &$request)
/**
* Check that version is 1.0.
*
* @param JacobKiers\OAuth\Request $request
* @param JacobKiers\OAuth\RequestInterface $request
*
* @return string
*
@@ -153,7 +153,7 @@ public function verifyRequest(Request &$request)
*/
private function getVersion(Request &$request)
{
$version = $request->getParameter('oauth_version');
$version = $request->getOAuthVersion();
if (!$version) {
// Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present.
// Chapter 7.0 ("Accessing Protected Ressources")
@@ -168,15 +168,15 @@ private function getVersion(Request &$request)
/**
* Get the signature method name, and if it is supported.
*
* @param JacobKiers\OAuth\Request $request
* @param JacobKiers\OAuth\RequestInterface $request
*
* @return string Signature method name.
*
* @throws JacobKiers\OAuth\OAuthException
*/
private function getSignatureMethod(Request $request)
private function getSignatureMethod(RequestInterface $request)
{
$signature_method = $request instanceof Request ? $request->getParameter('oauth_signature_method') : null;
$signature_method = $request instanceof Request ? $request->getOAuthSignatureMethod() : null;
if (!$signature_method) {
// According to chapter 7 ("Accessing Protected Resources") the signature-method
@@ -196,15 +196,15 @@ private function getSignatureMethod(Request $request)
/**
* Try to find the client for the provided request's client key.
*
* @param JacobKiers\OAuth\Request $request
* @param JacobKiers\OAuth\RequestInterface $request
*
* @return JacobKiers\OAuth\Client
*
* @throws JacobKiers\OAuth\OAuthException
*/
private function getClient(Request $request)
private function getClient(RequestInterface $request)
{
$client_key = $request instanceof Request ? $request->getParameter('oauth_consumer_key') : null;
$client_key = $request instanceof Request ? $request->getOAuthConsumerKey() : null;
if (!$client_key) {
throw new OAuthException('Invalid client key');
@@ -221,7 +221,7 @@ private function getClient(Request $request)
/**
* Try to find the token for the provided request's token key.
*
* @param JacobKiers\OAuth\Request $request
* @param JacobKiers\OAuth\RequestInterface $request
* @param JacobKiers\OAuth\Client $client
* @param string $token_type
*
@@ -229,9 +229,9 @@ private function getClient(Request $request)
*
* @throws JacobKiers\OAuth\OAuthException
*/
private function getToken(Request $request, Client $client, $token_type = 'access')
private function getToken(RequestInterface $request, Client $client, $token_type = 'access')
{
$token_field = $request instanceof Request ? $request->getParameter('oauth_token') : null;
$token_field = $request instanceof Request ? $request->getOAuthToken() : null;
$token = $this->data_store->lookupToken($client, $token_type, $token_field);
if (!$token) {
@@ -245,24 +245,24 @@ private function getToken(Request $request, Client $client, $token_type = 'acces
*
* Should determine the signature method appropriately
*
* @param JacobKiers\OAuth\Request $request
* @param JacobKiers\OAuth\RequestInterface $request
* @param JacobKiers\OAuth\Client $client
* @param JacobKiers\OAuth\Token $token
*
* @throws JacobKiers\OAuth\OAuthException
*/
private function checkSignature(Request $request, Client $client, Token $token)
private function checkSignature(RequestInterface $request, Client $client, Token $token)
{
// this should probably be in a different method
$timestamp = $request instanceof Request ? $request->getParameter('oauth_timestamp') : null;
$nonce = $request instanceof Request ? $request->getParameter('oauth_nonce') : null;
$timestamp = $request instanceof Request ? $request->getOAuthTimestamp() : null;
$nonce = $request instanceof Request ? $request->getOAuthNonce() : null;
$this->checkTimestamp($timestamp);
$this->checkNonce($client, $token, $nonce, $timestamp);
$signature_method = $this->getSignatureMethod($request);
$signature = $request->getParameter('oauth_signature');
$signature = $request->getOAuthSignature();
$valid_sig = $signature_method->checkSignature($request, $client, $token, $signature);
if (!$valid_sig) {