Are you including the
'Authorization' => 'Bearer '.$accessToken,
header in your ajax requests using passport?
https://laravel.com/docs/5.6/passport#passing-the-access-token
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi. As the headline already says I have a problem with my API. I use passport in laravel. Postman works fine. But when i consume my API in my backend with JavaScript I always get 401. I use axios. and X-Requested-With and X-CSRF-TOKEN are set. I use the middleware web (with \Laravel\Passport\Http\Middleware\CreateFreshApiToken) when calling the backend and the middleware '\Laravel\Passport\Http\Middleware\CheckClientCredentials' for the api calls. Does anybody have an idea... i sit here for the whole day and i wont work :( thx.
Finally after two weeks of testing i found the solution:
First I use Cartalyst Platform, which is a framework/cms based on laravel. It is from the makers of sentinel. That means they use sentinel. And the platform cms comes with a refactored autenticate middleware which use sentinel. So it is not enough to use auth:api middleware. The user there will always be null. You have to put web before. In my case i need an api for my cms backend and also one for an iphone app. So i have to build up two route groups. With this middlewares:
Middleware for iphone app: ['client'] Notice to define it in your kernel.php like this: 'client' => \Laravel\Passport\Http\Middleware\CheckClientCredentials::class,
Middleware for web users with sentinel. This was my main problem. I ever only used ['auth:api'] but YOU HAVE TO USE ['web','auth:api'] because web will load sentinel, which can only be used if you call web middleware.
Hope it helps.
Please or to participate in this conversation.