Skip to content

Commit

Permalink
Check apache_request_headers() as last resort, fixes tuupola#14
Browse files Browse the repository at this point in the history
  • Loading branch information
tuupola committed Mar 19, 2016
1 parent 418bfa3 commit 8a3539f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<filter>
<blacklist>
<directory suffix=".php">vendor/</directory>
<directory suffix=".php">tests/</directory>
</blacklist>
</filter>
</phpunit>
13 changes: 10 additions & 3 deletions src/JwtAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,18 @@ public function fetchToken(RequestInterface $request)
}

/* Nothing in environment, try header instead */
if ("" === $header) {
if (empty($header)) {
$message = "Using token from request header";
$header = $request->getHeader("Authorization");
$header = isset($header[0]) ? $header[0] : "";
$headers = $request->getHeader("Authorization");
$header = isset($headers[0]) ? $headers[0] : "";
}

/* Try apache_request_headers() as last resort */
if (empty($header) && function_exists("apache_request_headers")) {
$headers = apache_request_headers();
$header = isset($headers["Authorization"]) ? $headers["Authorization"] : "";
}

if (preg_match("/Bearer\s+(.*)$/i", $header, $matches)) {
$this->log(LogLevel::DEBUG, $message);
return $matches[1];
Expand Down
8 changes: 8 additions & 0 deletions tests/apache_request_headers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

if (!function_exists("apache_request_headers")) {
function apache_request_headers()
{
return [];
}
}
1 change: 1 addition & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?php

$loader = require dirname(__FILE__) . "/../vendor/autoload.php";
$loader = require dirname(__FILE__) . "/apache_request_headers.php";

0 comments on commit 8a3539f

Please sign in to comment.