diff --git a/src/OAuth2/AuthServer.php b/src/OAuth2/AuthServer.php index 4a360d01..2612c065 100644 --- a/src/OAuth2/AuthServer.php +++ b/src/OAuth2/AuthServer.php @@ -374,4 +374,24 @@ class AuthServer return self::$grantTypes[$grantType]; } + /** + * Get a parameter from passed input parameters or the Request class + * @param string|array $param Requried parameter + * @param string $method Get/put/post/delete + * @param array $inputParams Passed input parameters + * @return mixed 'Null' if parameter is missing + */ + public static function getParam($param = '', $method = 'get', $inputParams = array()) + { + if (is_string($param)) { + return (isset($inputParams[$param])) ? $inputParams['client_id'] : self::getRequest()->{$method}($param); + } else { + $response = array(); + foreach ($param as $p) { + $response[$p] = self::getParam($p, $method, $inputParams); + } + return $response; + } + } + } diff --git a/src/OAuth2/Grant/AuthCode.php b/src/OAuth2/Grant/AuthCode.php index b055d896..9760694e 100644 --- a/src/OAuth2/Grant/AuthCode.php +++ b/src/OAuth2/Grant/AuthCode.php @@ -25,31 +25,18 @@ class AuthCode implements GrantTypeInterface { return $this->responseType; } - public function completeFlow($inputParams = null, $authParams = array()) + public function completeFlow($inputParams = null) { - // Client ID - $authParams['client_id'] = (isset($inputParams['client_id'])) ? - $inputParams['client_id'] : - AuthServer::getRequest()->post('client_id'); + $authParams = AuthServer::getParam(array('client_id', 'client_secret', 'redirect_uri', 'code'), 'post', $inputParams); - if (is_null($authParams['client_id'])) { + if (is_null($authParams['client_id'])) { throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_id'), 0); } - // Client secret - $authParams['client_secret'] = (isset($inputParams['client_secret'])) ? - $inputParams['client_secret'] : - AuthServer::getRequest()->post('client_secret'); - if (is_null($authParams['client_secret'])) { throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_secret'), 0); } - // Redirect URI - $authParams['redirect_uri'] = (isset($inputParams['redirect_uri'])) ? - $inputParams['redirect_uri'] : - AuthServer::getRequest()->post('redirect_uri'); - if (is_null($authParams['redirect_uri'])) { throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'redirect_uri'), 0); } @@ -63,11 +50,7 @@ class AuthCode implements GrantTypeInterface { $authParams['client_details'] = $clientDetails; - // The authorization code - $authParams['code'] = (isset($inputParams['code'])) ? - $inputParams['code'] : - AuthServer::getRequest()->post('code'); - + // Validate the authorization code if (is_null($authParams['code'])) { throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'code'), 0); } diff --git a/src/OAuth2/Grant/GrantTypeInterface.php b/src/OAuth2/Grant/GrantTypeInterface.php index f64b3e9f..e9444537 100644 --- a/src/OAuth2/Grant/GrantTypeInterface.php +++ b/src/OAuth2/Grant/GrantTypeInterface.php @@ -42,5 +42,5 @@ interface GrantTypeInterface * @param array $authParams The authorisation paramaters that have been set so far in the request * @return array An array of parameters to be passed back to the client */ - public function completeFlow($inputParams = null, $authParams = array()); + public function completeFlow($inputParams = null); }