Ezrab_
1 week ago

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

Posted 1 week ago by Ezrab_

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!

Please sign in or create an account to participate in this conversation.