问题
I have installed Lumen and trying to implement authentication.
I am using Laravel Framework version Lumen (5.3.3) (Laravel Components 5.3.*).
In app.php I have 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 debugged, viaRequest
method is not getting executed.
回答1:
Did you define your route as follow:
$app->get('endpoint', ['middleware' => 'auth', function () { /* some code */ }]);
assigning the Auth middleware to a route.
来源:https://stackoverflow.com/questions/41697095/lumen-5-3-authentication