vendredi 14 octobre 2016

Route not found after adding 'auth:api' middleware Laravel 5.3

I'm trying to do an api call from one of my laravel projects to another using the new oauth2 feature in laravel 5.3.

I have this route in the api.php route file of my new laravel project that I want to call from the old one:

Route::get('/hello', function() {
    return 'hello';
})->middleware('auth:api');

Without the middleware I can call it without a problem, with the middleware, it throws a 404 not found error.

Here is the code that retrieves the access token and then makes the api call:

$http = new GuzzleHttp\Client;

$response = $http->post('http://ift.tt/2e2LJBU', [
    'form_params' => [
        'grant_type' => 'client_credentials',
        'client_id' => 'client_id',
        'client_secret' => 'client_secret',
    ],
]);
$token = json_decode($response->getBody(), true)['access_token'];

$response = $http->get('http://ift.tt/2dB5Vaj', [
    'headers' => [
        'Accept' => 'application/json',
        'Authorization' => 'Bearer '.$token,
    ],
]);
return $response->getBody();

The error that is returned:

[2016-10-14 09:46:14] local.ERROR: exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: `GET http://ift.tt/2dB5Vaj` resulted in a `404 Not Found` response:
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta name="robots" content="noindex,nofollow (truncated...)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire