I\'m building an API for Laravel and I want to send the api_token within the header instead of the form post. Is this something that is already built in or would I have to g
If you are consuming your API, you don't need to create an auth driver, you need to make requests to your API endpoints. Choose the method you prefer, and make requests, don't think as the same way when you use the auth driver at a webpage.
This is an example how send the $token through the headers. With cURL and Guzzle
$data = [
'value1' => 'value1',
'value2' => 'value2'
];
With CURL
$headers = [
'Authorization: Bearer '.$token
];
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, 'http://api.domain.com/endpoint');
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec ($ch2);
curl_close ($ch2);
With Guzzle
$headers = [
'Authorization' => 'Bearer '.$token
];
$client = new GuzzleHttp\Client();
$res = $client->request('POST', 'http://api.domain.com/endpoint',[
'form_params' => $data,
'headers' => $headers,
]);
I hope this helps!