Go to app/Http/Kernel.php and add this new middleware to web:
\Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello i have a question i want to use password with password grant with laravel and only laravel not Vue.js so full PHP
i make a function for retrieve token getApiToken , then i want authorize my api access part only for user authenticate
$response = $this->http->request('GET', $request->url, [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer $accessToken,
],
]);
For example i have
public function getCategories
{
$categories = Category::all();
return json_encode(
$categories
);
}
in my routes api.php i put
Route::group(['middleware' => ['auth:api']], function () {
Route::get('/categories', 'apiController@getCategories');
});
but i don t understand what url i need to call for authenticate with a token
if i do
localhost/site/api/categories laravel redirect me to /login, and if i put
localhost/site/api/categories?token="eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjQ1MDAyOWRkYTM1OTlkOWQ1YjFmMDE4YzAwMTcwOTNkNDE3MzAyM2U1YTYyYTdlYTczNjUyY2ZhNTM4NTUyZGExZTE4ZmM4ZDIwZDZiYWI5In0.eyJhdWQiOiIzIiwianRpIjoiNDUwMDI5ZGRhMzU5ffffffCJpYXQiOjE0OTUwMDYyNTQsIm5iZiI6MTQ5NTAwNjI1NCwiZXhwIjoxNTI2NTQyMjU0LCJzdWIiOiI1Iiwic2NvcGVzIjpbXX0.UqRd89fWgRSEJf7bXenJy2iZf5dLEqtdR0i6GlamPTBwhs9Wct9__5oVVndAHTzB2BhHr-BDCgrf_kgVhTVpFI7lquEHOYeEKg4oCN-500WbgxP9xUOiOjqdTLSzlyTYs4ateQQYiPAuq6-GxQWud6WwjQgY0JZAB82H0I7vZ9a8Q9-gukEZhsfG9qgizG1cOB-tRRbPimuS6wwdNjOQhWDmrD4CmZkc3-_PtZydSecUy9jAzQiVUUC3YIakfwEhbGne1b0y5tLtC20lz2niipsbI4Wi5Ls075ZCHY95Wxr3Gb6YI7HQfEOPzCCDr-GtmGIeKg-Oc5Jk0JTPugmV2dPddsss02cOJqNpPeZ1uxaN-B1sXzJJDVBTjDrlxJUjWlhNnmm5KRqJ3O9CmEqeyjXzT87w61cgMtM9RrxJit0pbaQ85ravVfqD1cRy2w63ElKsZ0qLw9j_0lOhDz8iOZn54d0DXXcsPrtwqNxsssse1RgX8WbHO0vshovhyJ3KwdMQJKO1iwXtV3aQao2wjqO8XKPqeKHRqfK5_vfyNXEdbFoJppSVuecG_ksmvizf8OGCx_8C4VvqdoSKCmKeQ2hnaRvLsQSxdS3Itt6uzA5N3H3de4uk8PhX8uPADnnPnVWssO_3C2dHM8EJj2leJyUvf2aR4dDM"
Not work too so what is the good way ?
if i look in database oauth_refresh_token is not registed only is id same for oauth_acces_token it s normal ? I don t understand howcan be work if token is not register somewhere
Thanks for your help
Please or to participate in this conversation.