I am using Laravel inbuilt Bearer token for API authentication. https://laravel.com/docs/5.8/api-authentication#passing-tokens-in-requests
$response = $client->request('POST', '/api/user', [
'headers' => [
'Authorization' => 'Bearer '.$token,
'Accept' => 'application/json',
],
]);
I would like to change the Authorization
header to X-API-Authorization
since we already have a legacy authentication in place which use this header Authorization
, which I have no control over.
Does Laravel provide over-riding this inbuilt functionality?
The header key Authorization
seems to be hardcoded in laravel. Your best bet is, creating a new Authentication guard by extending the Laravel TokenGuard, and overriding the getTokenForRequest
method to use your custom header key.
See - https://laravel.com/docs/5.8/authentication#adding-custom-guards