流明5.3身份验证

问题描述:

我已经安装了Lumen并尝试实现身份验证.

I have installed Lumen and trying to implement authentication.

我正在使用Laravel Framework版本Lumen(5.3.3)(Laravel组件5.3.*).

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

在app.php中,我未对以下内容发表评论.

In app.php I have uncommented the following.

$app->withFacades();

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

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

\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();
            }
        });
}

在调试时,viaRequest方法未执行.

Here when I debugged, viaRequest method is not getting executed.

您是否按照以下方式定义了路线:

Did you define your route as follow:

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

将Auth中间件分配给路由.

assigning the Auth middleware to a route.