编程语言
首页 > 编程语言> > php-流明:jwt-auth不存在方法句柄,已完成中间件

php-流明:jwt-auth不存在方法句柄,已完成中间件

作者:互联网

嘿,所以我刚更新到Lumen 5.2并遇到了jwt-auth问题.我已遵循所有说明并更新了我的app.php文件,包括所有中间件.我还要求作曲家照亮/路由和照亮/验证.
但是我得到了错误:

Macroable.php第81行中的BadMethodCallException:
方法句柄不存在.在Responseable-> __ call(‘handle’,array(object(Request),object(Closure)))的Macroable.php第81行中

我似乎对这个错误一无所知?

这是我的boostrap / app.php供参考:

<?php

require_once __DIR__.'/../vendor/autoload.php';

try {
    (new Dotenv\Dotenv(__DIR__.'/../'))->load();
} catch (Dotenv\Exception\InvalidPathException $e) {
    //
}

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/

//$app = new Laravel\Lumen\Application(
//    realpath(__DIR__.'/../')
//);

// For nested route groups to work
$app = new Fremail\NestedRouteGroups\Application(
    realpath(__DIR__.'/../')
);

 $app->withFacades();

$app->configure('jwt');
$app->configure('auth');

class_alias(Tymon\JWTAuth\Facades\JWTAuth::class, 'JWTAuth');
class_alias(Tymon\JWTAuth\Facades\JWTFactory::class, 'JWTFactory');


 $app->withEloquent();

/*
|--------------------------------------------------------------------------
| Register Container Bindings
|--------------------------------------------------------------------------
|
| Now we will register a few bindings in the service container. We will
| register the exception handler and the console kernel. You may add
| your own bindings here if you like or you can make another file.
|
*/

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

$app->singleton(
    Illuminate\Contracts\Console\Kernel::class,
    App\Console\Kernel::class
);

$app->singleton(
    Illuminate\Cache\CacheManager::class,
    function ($app) {
        return $app->make('cache');
    }
);

$app->singleton(
    Illuminate\Auth\AuthManager::class,
    function ($app) {
        return $app->make('auth');
    }
);

$app->singleton(
    Illuminate\Contracts\Routing\ResponseFactory::class,
    Illuminate\Routing\ResponseFactory::class
);


/*
|--------------------------------------------------------------------------
| Register Middleware
|--------------------------------------------------------------------------
|
| Next, we will register the middleware with the application. These can
| be global middleware that run before and after each request into a
| route or middleware that'll be assigned to some specific routes.
|
*/

$app->middleware([
    Illuminate\Contracts\Routing\ResponseFactory::class,
//     // Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
//     // Illuminate\Session\Middleware\StartSession::class,
//     // Illuminate\View\Middleware\ShareErrorsFromSession::class,
//    Laravel\Lumen\Http\Middleware\VerifyCsrfToken::class,
 ]);

// Middleware for authentication for the API
$app->routeMiddleware([
    'auth'        => App\Http\Middleware\Authenticate::class,
    'jwt.auth'    => Tymon\JWTAuth\Middleware\GetUserFromToken::class,
    'jwt.refresh' => Tymon\JWTAuth\Middleware\RefreshToken::class,
]);

/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/

$app->register(App\Providers\GuardServiceProvider::class);
$app->register(Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class);

/*
|--------------------------------------------------------------------------
| Load The Application Routes
|--------------------------------------------------------------------------
|
| Next we will include the routes file so that they can all be added to
| the application. This will provide all of the URLs the application
| can respond to, as well as the controllers that may handle them.
|
*/

$app->group(['namespace' => 'App\Http\Controllers'], function ($app) {
    require __DIR__.'/../app/Http/routes.php';
});

return $app;

谢谢你的帮助

解决方法:

我的答案肯定晚了,但对于未来的Google员工,这是我的解决方法(流明5.3):

我在bootstrap / app.php中设置了身份验证中间件:

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

标签:lumen,laravel,jwt,php
来源: https://codeday.me/bug/20191027/1941068.html