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

Ezrab_'s avatar

Laravel Passport POST oauth/token resulted in a '404 Not Found'

I'm using an apache virtualhost: 'gradez.loc', each time I try to access the /oauth/token route with cURL or Postman it returns a 404.

When I use php artisan serve and try to access to route via http://localhost:8000 there is no problem and I get back the access and refesh token.

What I have done already:

  • ran php artisan route:list I can see it returns all the passport routes correctly,
  • ran php artisan route:cache and php artisan route:clear
  • ran php artisan optimize

None of these seem to fix the problem unfortunately. I see a lot of people struggling with the same problem, but there's no good answer to this.

AuthServiceProvider

public function boot()
{
    $this->registerPolicies();

    Passport::routes();
}

requestAccessToken method:

$response = $http->post(url('/oauth/token'), [
    'form_params' => [
        'grant_type'    => 'password',
        'client_id'     => config('services.passport.client_id'),
        'client_secret' => config('services.passport.client_secret'),
        'username'      => $userData->username,
        'password'      => $userData->password,
    ],
]);

.env:

APP_URL=http://gradez.loc // <- oauth/token results in a 404

running php artisan serve

APP_URL=http://127.0.0.1:8000 // <- oauth/token works as expected!

0 likes
1 reply
bobbybouwmann's avatar
Level 88

That the URL doesn't work has nothing to do with Laravel itself. This is a local issue because the service you use to serve the site (Nginx, apache, vagrant) isn't configured correctly.

Normally if you have a site locally, you put the domain in the hosts file point to localhost so it resolves correctly. But that depends on your setup.

Please or to participate in this conversation.