Skip to content

Commit

Permalink
Merge pull request thephpleague#64 from alexmcroberts/develop
Browse files Browse the repository at this point in the history
Conditional isValid flag to check for Authorization header only. Fixes thephpleague#57
  • Loading branch information
alexbilbie committed Jun 2, 2013
2 parents a9ecca9 + a4a8f6e commit 7da9e1a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/League/OAuth2/Server/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,13 @@ public function getClientId()
/**
* 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
* @return bool
*/
public function isValid()
public function isValid($headersOnly = false)
{
$accessToken = $this->determineAccessToken();
$accessToken = $this->determineAccessToken($headersOnly);

$result = $this->storages['session']->validateAccessToken($accessToken);

Expand Down Expand Up @@ -237,10 +238,11 @@ public function hasScope($scopes)
/**
* 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
* @return string
*/
protected function determineAccessToken()
protected function determineAccessToken($headersOnly = false)
{
if ($header = $this->getRequest()->header('Authorization')) {
// Check for special case, because cURL sometimes does an
Expand All @@ -256,7 +258,7 @@ protected function determineAccessToken()
$accessToken = trim(preg_replace('/^(?:\s+)?Bearer\s/', '', $header));
}
$accessToken = ($accessToken === 'Bearer') ? '' : $accessToken;
} else {
} elseif ($headersOnly === false) {
$method = $this->getRequest()->server('REQUEST_METHOD');
$accessToken = $this->getRequest()->{$method}($this->tokenKey);
}
Expand Down

0 comments on commit 7da9e1a

Please sign in to comment.