Reputation: 1793
I've been working in this application for several years and while doing some updates my passport authentication broke. I update from passport 7.2 to 7.5 and it broke. I then updated to passport 8.5 and it still doesn't work.
I am getting the 401 {error: "Unauthenticated."}
error.
I am using
I am attempting to consume my own api and I've followed every solution I found on the internet, but no dice. I can access the routes using postman with an access token and if I move the route outside of the auth:api
middleware, but I want to access the routes within the auth:api
Here is my current config.
AuthServiceProvider.php
public function boot()
{
Passport::routes();
}
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
... other middleware
\Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
In auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
'hash' => false,
],
]
]
bootstrap.js
window.axios = require('axios');
window.axios.defaults.headers.common = {
'X-CSRF-TOKEN' : document.querySelector('meta[name="csrf-token"]').getAttribute('content'),
'X-Requested-With': 'XMLHttpRequest'
};
in a component.vue file
axios.get('/api/users?page=' + page).then((response) => {
//
})
I've cleared configs and ran php artisan optimize:clear
and about a dozen of other things that I can't thing of right now.
Any help would be appreciated.
Upvotes: 2
Views: 690
Reputation: 191
I've encountered exactly this problem with Laravel 7 and Passport starting around the time of this question posted (early September 2020). I couldn't pin-point the exact cause of the issue, but had to freeze my dependencies to avoid the problem. While debugging it seemed to me it wasn't a direct issue with Laravel or Passport, but rather a sub-dependency.
Just upgraded to Laravel 8 and Passport v10.0.1 and now everything is back to normal.
Upvotes: 1