Search code examples
phplaraveloauthlaravel-passport

Laravel passport can't find ApproveAuthorizationController


I'm trying to setup a laravel application with oauth autorization by using the laravel passport functionality. I'm using the official tutorial (https://laravel.com/docs/master/passport). But now if I make a post request to '/oauth/authorize' the following error message occurs:

Class App\Http\Controllers\Laravel\Passport\Http\Controllers\ApproveAuthorizationController does not exist

I don't know what I've been doing wrong. I use the routes getting from 'Passport:routes' and no self defined routes.

I've already made a composer update, install and clear cache but nothing worked.

The problem get caused here:

/**
 * Register the routes needed for authorization.
 *
 * @return void
 */
public function forAuthorization()
{
    $this->router->group(['middleware' => ['web', 'auth']], function ($router) {
        $router->get('/authorize', [
            'uses' => 'AuthorizationController@authorize',
        ]);

        $router->post('/authorize', [
            'uses' => 'ApproveAuthorizationController@approve',
        ]);

        $router->delete('/authorize', [
            'uses' => 'DenyAuthorizationController@deny',
        ]);
    });
}

I've already tried it by importing the missing class with a use statement but it still wont work.

Can somebody help me?


Solution

  • It looks like you're missing a use statement at the top of a controller or service proivder. Somewhere you have a class being used with out properly importing it first. That's why you're seeing the concatenated string like:

    App\Http\Controllers\Laravel\Passport\Http\Controllers\ApproveAuthorizationController.
    

    I assume what you need is this:

    use Passport\Http\Controllers\ApproveAuthorizationController;
    

    or Passport in Passport::routes is not being imported, one of the two. In AppServiceProvider:

    use Laravel\Passport\Passport;