Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wljin's avatar
Level 1

Laravel Authorization header is missing

I have implemented passport in my application and am using postman to test the api. However the Authorization header is missing among the headers. below is my

.htaccess file

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]


# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]


# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

When i try this

Route::get('/setup', function (Request $request){
var_dump($request->headers);
});

i get this

object(Symfony\Component\HttpFoundation\HeaderBag)#44 (2) {
  ["headers":protected]=>
  array(8) {
["host"]=>
array(1) {
  [0]=>
  string(14) "162.243.23.252"
}
["connection"]=>
array(1) {
  [0]=>
  string(10) "keep-alive"
}
["accept"]=>
array(1) {
  [0]=>
  string(16) "application/json"
}
["cache-control"]=>
array(1) {
  [0]=>
  string(8) "no-cache"
}
["user-agent"]=>
array(1) {
  [0]=>
  string(105) "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36"
}
["postman-token"]=>
array(1) {
  [0]=>
  string(36) "acac2f9b-9c71-fb9a-ebd5-62516eb4fd36"
}
["accept-encoding"]=>
array(1) {
  [0]=>
  string(19) "gzip, deflate, sdch"
}

 ["accept-language"]=>
array(1) {
  [0]=>
  string(14) "en-US,en;q=0.8"
}
  }

["cacheControl":protected]=>
  array(1) {
["no-cache"]=>
bool(true)
  }
}

Any solutions ?

0 likes
8 replies
wljin's avatar
Level 1

can someone please point me in the right direction

Lars-Janssen's avatar

Did you add:

 \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,

to $middlewareGroups array?

in kernel.php?

wljin's avatar
Level 1

yes i did add the createFreshapitoken to the kernel. On my local machine, am able to access authorization header, but on my server for some reason authorization header is missing header.

irfanALIAzhari's avatar

Hi, I'm also stuck with the same issue.

Note: 
1. Through Postman everything work fine.
2. Authorizarion header not exist after dispatch via my application.

Please have a look at my code below.

//API Calling..
{
$request = ApiReq::create('/api/'.$endPoint, $method);
$request->headers->set('Authorization','Bearer '.session()->get('auth_token'));

//Authorization header exist in such request
dd($request->header());
}
//API End point
Route::match(['get', 'post'], 'profile/{uid?}', function(Request $request){
    //Authorization header not exist in such request
    dd($request->header());
});

Do you have any idea to resolve the issue?

Val's avatar

This may happen because of 2 reasons:

  1. missing authorization rewrite rule and
  2. missing Apache virtual host directive to allow authorization headers.

For the 1st see the respective Laravel docs:

// your_project/public/.htaccess
// these 2 lines shoul be here
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

For the 2nd:

# In your web server's Apache virtual host config file
<VirtualHost>
    # ...
    SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=
    # ...
</VirtualHost>

On this see more details here. Hope that helps.

1 like

Please or to participate in this conversation.