Lumen 5.3 Authentication

狂风中的少年 提交于 2019-12-11 07:26:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!