简体   繁体   中英

Argument 2 passed to Arubacao\BasicAuth\BasicGuard::__construct() must be an instance of Illuminate\Contracts\Auth\UserProvider, null given

Been trying to use lumen for a simple & lightweight REST API interface, using lumen + arubacao/http-basic-auth-guard composer packages.

I got to a bottleneck issue which is: Argument 2 passed to Arubacao\\BasicAuth\\BasicGuard::__construct() must be an instance of Illuminate\\Contracts\\Auth\\UserProvider, null given, called in /Applications/MAMP/htdocs/app.mydomain.com/api/vendor/arubacao/http-basic-auth-guard/src/BasicGuardServiceProvider.php on line 38

Content of config/auth.php:

return [

    'defaults' => [
        'guard' => env('AUTH_GUARD', 'api'),
    ],

    'guards' => [
        'api' => [
            'driver' => 'basic',
            'provider' => 'users'
        ],

        // ...
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model'  => App\User::class
        ],
    ],

    'providers' => [
        //
    ],

    'passwords' => [
        //
    ],

];

Content of bootstrap/app.php

require_once __DIR__.'/../vendor/autoload.php';

try {
    (new Dotenv\Dotenv(__DIR__.'/../'))->load();
} catch (Dotenv\Exception\InvalidPathException $e) {
    //
}

$app = new Laravel\Lumen\Application(
    realpath(__DIR__.'/../')
);

$app->withFacades();

$app->withEloquent();

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

$app->singleton(
    Illuminate\Contracts\Console\Kernel::class,
    App\Console\Kernel::class
);

$app->routeMiddleware([
    'auth' => App\Http\Middleware\Authenticate::class,
]);

$app->register(App\Providers\AuthServiceProvider::class);
$app->register(Arubacao\BasicAuth\BasicGuardServiceProvider::class);

$app->router->group([
    'namespace' => 'App\Http\Controllers',
], function ($router) {
    require __DIR__.'/../routes/web.php';
});

return $app;

*the setup is the same as the one documented in arubacao/http-basic-auth-guard repo

Lumen version: 5.6.4

return [

    'defaults' => [
        'guard' => env('AUTH_GUARD', 'api'),
    ],

    'guards' => [
        'api' => [
            'driver' => 'basic',
            'provider' => 'users'
        ],

        // ...
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model'  => App\User::class
        ],
    ],
// This should be removed, it was leftover from the boiler template of lumen repo.
    'providers' => [
        //
    ],

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM