Merge pull request #64 from alexmcroberts/develop

Conditional isValid flag to check for Authorization header only. Fixes #57
This commit is contained in:
Alex Bilbie 2013-06-02 05:46:45 -07:00
commit 7da9e1a9d7

View File

@ -173,12 +173,13 @@ class Resource
/** /**
* Checks if the access token is valid or not. * Checks if the access token is valid or not.
* *
* @param $headersOnly Limit Access Token to Authorization header only
* @throws Exception\InvalidAccessTokenException Thrown if the presented access token is not valid * @throws Exception\InvalidAccessTokenException Thrown if the presented access token is not valid
* @return bool * @return bool
*/ */
public function isValid() public function isValid($headersOnly = false)
{ {
$accessToken = $this->determineAccessToken(); $accessToken = $this->determineAccessToken($headersOnly);
$result = $this->storages['session']->validateAccessToken($accessToken); $result = $this->storages['session']->validateAccessToken($accessToken);
@ -237,10 +238,11 @@ class Resource
/** /**
* Reads in the access token from the headers. * Reads in the access token from the headers.
* *
* @param $headersOnly Limit Access Token to Authorization header only
* @throws Exception\MissingAccessTokenException Thrown if there is no access token presented * @throws Exception\MissingAccessTokenException Thrown if there is no access token presented
* @return string * @return string
*/ */
protected function determineAccessToken() protected function determineAccessToken($headersOnly = false)
{ {
if ($header = $this->getRequest()->header('Authorization')) { if ($header = $this->getRequest()->header('Authorization')) {
// Check for special case, because cURL sometimes does an // Check for special case, because cURL sometimes does an
@ -256,7 +258,7 @@ class Resource
$accessToken = trim(preg_replace('/^(?:\s+)?Bearer\s/', '', $header)); $accessToken = trim(preg_replace('/^(?:\s+)?Bearer\s/', '', $header));
} }
$accessToken = ($accessToken === 'Bearer') ? '' : $accessToken; $accessToken = ($accessToken === 'Bearer') ? '' : $accessToken;
} else { } elseif ($headersOnly === false) {
$method = $this->getRequest()->server('REQUEST_METHOD'); $method = $this->getRequest()->server('REQUEST_METHOD');
$accessToken = $this->getRequest()->{$method}($this->tokenKey); $accessToken = $this->getRequest()->{$method}($this->tokenKey);
} }