Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Passport routes missing in route:list - 404 error on oauth/token

I have followed the Laravel 5.5 documentation to require, install and configure Laravel Passport on our application. We are ONLY using the password grant functionality as we aren't intending to use this as a social login tool. However, after following all the instructions, I am getting a 404 error when attempting to POST the form data into the application using Postman.

I have run php artisan route:list and there is no mention in there of oauth at all. I'd share the output but it's quite long as we have a large application.

I have ensured that Passport::routes() is in the AuthServiceProvider as shown below:

<?php

namespace App\Providers;

use Laravel\Passport\Passport;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        'App\Model' => 'App\Policies\ModelPolicy',
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();
        Passport::routes();
        //
    }
}

The documentation on 5.5 does not say anything about adding a line to the config/app.php file as previous versions of Laravel do. After getting the 404 errors I decided to try adding that line just to see if it helps. It does not.

I did in fact run php artisan passport:install and then php artisan migrate which resulted in the creation of 2 clients: (ID = 1: Personal Access Client) and ID 2: Password Grant Client) and the various oauth tables being created in our database.

The resulting 404 error IS in fact coming from the site and not some generic message as it has our theme wrapped around it so I know it's hitting the application.

I have searched for references to the 404 error on oauth/token and Laravel Passport but have come up dry on solutions.

Any suggestions are greatly appreciated.

like image 584
Andrew Christensen Avatar asked Sep 15 '25 02:09

Andrew Christensen


1 Answers

bingo bango I found the problem....

So after digging around, as mentioned in my comment above, the AuthServiceProvider in my App\Providers folder was not referenced. I had commented out the Illuminate one and added my App\Providers one thinking that it would simply extend the Illuminate one. That caused the Auth class error. I re-enabled the Illuminate one and left my App\Providers\AuthServiceProvider enabled but below the Illuminate one and it all worked out. No more 404s... Hope this helps someone else.

like image 65
Andrew Christensen Avatar answered Sep 17 '25 18:09

Andrew Christensen