Lumen 5.3 Authentication

I installed Lumen and tried to authenticate.

I am using the Laravel Framework Lumen version (5.3.3) (Laravel 5.3. * Components).

In app.php, I uncommented the following.

$app->withFacades();

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

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

IN \app\Providers\AuthServiceProvider.php

public function boot() {
        $this->app['auth']->viaRequest('api', function ($request) {
            if ($request->input('api_token')) {
                return User::where('api_token', $request->input('api_token'))->first();
            }
        });
}

Here, when I am debugging, the method is viaRequestnot executed.

+1
source share
1 answer

You have defined your route as follows:

$app->get('endpoint', ['middleware' => 'auth', function () { /* some code */ }]);

Assign Auth middleware for the route.

+1
source

All Articles