No route found after adding Laravel 5.3 "auth: api" middleware

I am trying to make an api call from one of my laravel projects to another using the new oauth2 function in laravel 5.3.

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

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

Without middleware, I can name it without problems, with middleware, it throws a 404 error not found.

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

$http = new GuzzleHttp\Client;

$response = $http->post('http://my-oauth-project.com/oauth/token', [
    '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://my-oauth-project.com/api/hello', [
    'headers' => [
        'Accept' => 'application/json',
        'Authorization' => 'Bearer '.$token,
    ],
]);
return $response->getBody();

Return Error:

[2016-10-14 09:46:14] local.ERROR: exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: `GET http://my-oauth-project.com/api/hello` resulted in a `404 Not Found` response:
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta name="robots" content="noindex,nofollow (truncated...)
+3
source share
1 answer

"auth: api" ( , , 404).

. , .

, $routeMiddleware app\Http\Kernel.php :

protected $routeMiddleware = [
    'client_credentials' => \Laravel\Passport\Http\Middleware\CheckClientCredentials::class,
];

:

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

, .

+3

Source: https://habr.com/ru/post/1660853/


All Articles