Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lalitesh's avatar

Oauth2 authentication issue in Laravel 11

I am using Laravel 11 new install with Passport package set up, I have created a client id and secret using client_credentials grant_type, when calling oauth/token, I get the access token and that access token works fine when I call this api in my application from third party application ( Postman )

Route::get('/api-testing', function (Request $request) {
    return ['message' => 'all good'];
})->middleware('client');

However, when I deliverately pass incorrect access token using using this code:

curl --location --request GET 'http://localhost/myapplication/public/api/api-testing' \
--header 'Authorization: Bearer incorrect token'

I get the following error:

Symfony\Component\Routing\Exception\RouteNotFoundException: Route [login] not defined. in file \vendor\laravel\framework\src\Illuminate\Routing\UrlGenerator.php on line 477

I don't have route login and don't want to have it, just want to return unauthenticated message if access token is incorrect.

What am I missing?

0 likes
2 replies
Sergiu17's avatar
Sergiu17
Best Answer
Level 60
curl --location --request GET 'http://localhost/myapplication/public/api/api-testing' \
--header "Accept: application/json" --header 'Authorization: Bearer incorrect token'

--header "Accept: application/json" I believe this will solve your issue

1 like
lalitesh's avatar

@Sergiu17 Oh my god, how could I miss it..

Thanks so much for saving my hours.

1 like

Please or to participate in this conversation.