0

I trying to calling an Api with Authorization header. After dispatch the request, the authorization header does not exist.

Note: 
1. Through Postman everything work fine.
2. (The issue is) Authorizarion header missing after request dispatch via my application.

Please have a look at my code below.

Authorization Header Exist with 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());
}

Authorization header missing at Api Endpoint in such request

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??

1 Answers1

0

There can be missing authorization headers with Apache virtual host.

To solve this issue you have to add the line allowing Apache to pass authorization header to PHP in you virtual hosts configuration.

<VirtualHost>
    # ...
    SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
    # ...
</VirtualHost>

Do not forget to restart the Apache service to re-read the configuration: sudo systemctl restart apache2.

See more details here

Valentine Shi
  • 6,604
  • 4
  • 46
  • 46