I've written this simple filter below:
Route::filter('token', function()
{
$headers = json_decode(json_encode(getallheaders()), true);
if(array_key_exists($headers['Authorization'], $headers)) {
echo 'test';
}
});
It uses the getallheaders()
function instead of Laravel's Request
class because the Request
class does not yet recognize custom HTTP headers.
When printing this array, it returns:
Array
(
[Host] => api.myapi.com
[Connection] => keep-alive
[Accept] => application/json, text/plain, */*
[Origin] => http://myorigin
[User-Agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36
[Authorization] => eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9hcGkuYmFjazlpbnMuY29tIiwiYXVkIjoiaHR0cDpcL1wvMTYyLjI0My4xMDEuMjAyXC9zbWFydDIiLCJpYXQiOjE0MTQ2ODE1NzgsIm5iZiI6MTQxNDY4MzM3OCwidXNlciI6ImI4YTAwNzIxLTQwZjEtNzgwMS1iNGI5LTUwY2UxNTJjZTJlYyJ9.VrcWRwupzuS_Y5PNiNfXCAMl3bVbifFIHptMO6
[Referer] => http://myorigin/myproject/
[Accept-Encoding] => gzip,deflate,sdch
[Accept-Language] => en-US,en;q=0.8
)
However, array_key_exists($headers['Authorization'], $headers)
continually evaluates to false. In this circumstance why would it evaluate to false? I am sending the Authorization token in the headers and when I print_r()
the array it's clearly recognizing the header and giivng the correct value upon request.
What could be the problem with this?