Skip to content

Commit

Permalink
Support Authorization header passed as ENV var
Browse files Browse the repository at this point in the history
Some hosts (at this point I only know of Fortrabbit) require Authorization headers to be passed as an environment variable, which PHP will then shove into . See more: http://fortrabbit.com/docs/essentials/quirks-and-constraints\#authorization-header
  • Loading branch information
Phil Sturgeon committed May 13, 2014
1 parent 98be9ab commit 44f51bf
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/League/OAuth2/Server/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function isValid($headersOnly = false)

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

if ( ! $result) {
if (! $result) {
throw new Exception\InvalidAccessTokenException('Access token is not valid');
}

Expand Down Expand Up @@ -225,7 +225,7 @@ public function hasScope($scopes)
return false;
} elseif (is_array($scopes)) {
foreach ($scopes as $scope) {
if ( ! in_array($scope, $this->sessionScopes)) {
if (! in_array($scope, $this->sessionScopes)) {
return false;
}
}
Expand All @@ -244,7 +244,15 @@ public function hasScope($scopes)
*/
protected function determineAccessToken($headersOnly = false)
{
if ($header = $this->getRequest()->header('Authorization')) {
// Try to get it directly from a header
if (! $header = $this->getRequest()->header('Authorization')) {

// Failing that try getting it from a server variable
$header = $this->getRequest()->server('HTTP_AUTHORIZATION');
}

// One of them worked
if ($header) {
// Check for special case, because cURL sometimes does an
// internal second request and doubles the authorization header,
// which always resulted in an error.
Expand All @@ -269,5 +277,4 @@ protected function determineAccessToken($headersOnly = false)

return $accessToken;
}

}

3 comments on commit 44f51bf

@darkyen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this part missed in the complete re-write ? Apache 2 does the same. btw

@darkyen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey it turns out since it builds from superGlobals it does support it using server vars, though i prefer getallheaders() over server vars for headers if applicable, any reason of not doing so ?

@alexbilbie
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Library now uses Symfony Request object instead of it's own (but you can subclass and inject your own) - if it doesn't use getallheaders() then there's where to fix it

Please sign in to comment.