Lumen:类Illuminate \ Cookie \ Middleware \ AddQueuedCookiesToResponse不存在

时间:2016-04-15 09:11:31

标签: php laravel oauth-2.0 middleware lumen

我是Lumen的新手,我正在尝试使用OAuth2和this tutorial设置身份验证 当我尝试访问任何路线时,我收到此错误:

ReflectionException in Container.php line 738:
Class Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse does not exist

in Container.php line 738
at ReflectionClass->__construct('Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse') in Container.php line 738
at Container->build('Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse', array()) in Container.php line 633
at Container->make('Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse', array()) in Application.php line 205
at Application->make('Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse') in Pipeline.php line 123
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request)) in OAuthExceptionHandlerMiddleware.php line 36
at OAuthExceptionHandlerMiddleware->handle(object(Request), object(Closure))
at call_user_func_array(array(object(OAuthExceptionHandlerMiddleware), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in RoutesRequests.php line 626
at Application->sendThroughPipeline(array('LucaDegasperi\OAuth2Server\Middleware\OAuthExceptionHandlerMiddleware', 'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse'), object(Closure)) in RoutesRequests.php line 382
at Application->dispatch(object(Request)) in RoutesRequests.php line 327
at Application->run(object(Request)) in index.php line 28

自举\ app.php

$app->middleware([
    'LucaDegasperi\OAuth2Server\Middleware\OAuthExceptionHandlerMiddleware',
    'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse'  // <--- added
]);

$app->routeMiddleware([
    'check-authorization-params' => 'Optimus\OAuth2Server\Middleware\CheckAuthCodeRequestMiddleware',
    'csrf' => 'Laravel\Lumen\Http\Middleware\VerifyCsrfToken',
    'oauth' => 'Optimus\OAuth2Server\Middleware\OAuthMiddleware',
    'oauth-owner' => 'Optimus\OAuth2Server\Middleware\OAuthOwnerMiddleware'
]);

$app->register(App\Providers\EventServiceProvider::class);
$app->register('LucaDegasperi\OAuth2Server\Storage\FluentStorageServiceProvider');
$app->register('Optimus\OAuth2Server\OAuth2ServerServiceProvider');

routes.php文件

$app->group(['prefix' => 'v1','namespace' => 'App\Http\Controllers'], function($app)
{
    $app->get('post','PostController@index');
}

1 个答案:

答案 0 :(得分:3)

跑步

  

composer require illuminate / cookie

然后在bootstrap / app.php

添加此代码
$app->singleton('cookie', function () use ($app) {
    return $app->loadComponent('session', 'Illuminate\Cookie\CookieServiceProvider', 'cookie');
});

$app->bind('Illuminate\Contracts\Cookie\QueueingFactory', 'cookie');

ref https://github.com/esbenp/lumen-api-oauth/issues/23