Try injecting AuthManager
in your bootstrap/app.php
file:
/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/
$app->register(App\Providers\AppServiceProvider::class);
$app->register(App\Providers\EventServiceProvider::class);
// Injecting goes here
$app->singleton(Illuminate\Auth\AuthManager::class, function ($app) {
return $app->make('auth');
});
Explanation
We know that Illuminate\Auth\AuthManager
will be resolved automatically if we run Illuminate\Auth\AuthServiceProvider
. See:
Illuminate\Auth\AuthServiceProvider@registerAuthenticator
So, we must run this service provider before we want to use AuthManager
. But Lumen is slightly different. I see that Illuminate\Auth\AuthManager
isn't registered yet in:
Laravel\Lumen\Application::$availableBindings
Which is it's a hack to make Lumen run faster when the container wants to resolved the resource, see:
Laravel\Lumen\Application@make
So, basically, if you want to resolve Illuminate\Auth\AuthManager
class and it's dependency, you may register it's class bindings first before you use it.
Update
We know that
Laravel\Lumen\Application::$availableBindings
property is in public
visibility, so this works too:
/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/
$app->register(App\Providers\AppServiceProvider::class);
$app->register(App\Providers\EventServiceProvider::class);
$app->availableBindings['Illuminate\Auth\AuthManager'] = 'registerAuthBindings';
$app->alias('auth', 'Illuminate\Auth\AuthManager');
Update 2
I understand that there's lot of problems if we want to implements JWT Authentication in Lumen with this library. So, I make a bootstrapped (clean start) Lumen Application that integrated well with this library. Please check out my repo. I'll add explanation about which one and why we should change the code later. Cheers.