0
votes

I recently upgraded my Laravel app from 5.6 to 5.8 and my Passport api does not work anymore.

The 'oauth/token' call works perfectly and I get my access_token as before. Then after, when using the usual call:

$response = $http_client->request('GET', 'api/test', [
                'headers' => [
                    'Accept'        => 'application/json',
                    'Authorization' => 'Bearer ' . $access_token,
                ],
            ]);

to a very basic protected route:

Route::middleware('auth:api')->get('test', function () {
    return ['test' => 'test'];
});

I never get the expected response. Whatever I put inside the route function, I always get an empty 200 response.

This same route without the auth:api middleware works fine by the way:

Route::get('test', function () {
    return ['test' => 'test'];
});

It seems that the api:auth middleware does not work anymore and I really don't know why.

My API used to work perfectly before the upgrade. I really don't know what happened.

1
What about return response()->json(['test' => 'test']);?Tarasovych
By the way, can you remove/comment all other routes? Maybe there are some conflicts. You can't get 200 response from nowhere)Tarasovych
Thanks for trying to help. These 2 things do exactly the same so that is not the problem. And I already tried to check the conflicts between routes.thomaus
Can you upload your repo to git?Tarasovych

1 Answers

0
votes

You have mentioned in header that response should be in json format and you are returning a response with non-json format.

You should use

return response()->json(['test' => 'test']);

rather then

return ['test' => 'test'];