uweheldt's avatar

Lumen 5.4 - Auth guard driver [api] is not defined.

Hi there,

I have setup a standard Lumen installation and all works fine until I activate Authentication (uncommenting 2 parts in app.php) and try using it in my Controller ($this->middleware('auth', ['only' => [ 'index', 'getById' ]]);)

Now. Every time I call one of the secured resources, I get an error as follows:

InvalidArgumentException in AuthManager.php line 99: Auth guard driver [api] is not defined.

I have searched the web, but all suggestions are pretty much focused on previous versions of Lumen such as 5.2. Since I use Lumen 5.4 I need your help.

My auth.php is unmodified and as it comes with Lumen 5.4

Help is really appreciated since I'm stuck now.

Cheers, Uwe

0 likes
4 replies
am05mhz's avatar

the Authentication in lumen 5.4 is a little broken, in the documentation, it is written that we just use the Gate facade, while in reality, you have to create these following items:

  • config folder
  • auth.php inside the config folder

the structure of the folder and file is similar to laravel, so you can just copy the file and folder to your lumen app, and change a few things.

but then, the real problem shows up. the Gate facade uses Session while lumen 5.4 have removed that. and that makes it so broken.

update:

actually, in the auth.php in the config folder, you can set the guard method to token, by then you need to implement oauth2

update 2:

actually, if you use $this->app['auth']->viaRequest('api' ... in your AuthServiceProvider, then you won't encounter guard driver not defined. when you change the 'api' keyword, then you have to defined it in the auth.php config file.

gperez78's avatar

Please assure you are using requiring tymon/jwt-auth ^1.0@dev in compose.json

alnajjar47's avatar

read the documentation carefully, it says that you need to uncomment the line $app->routeMiddleware([ 'auth' => App\Http\Middleware\Authenticate::class, ]); that is in the bootstrap/app.php

and uncomment : $app->register(App\Providers\AuthServiceProvider::class);

3 likes

Please or to participate in this conversation.