我开发了一个CakePHP 3插件,该插件必须处理没有CSRF令牌的POST请求。
在使用插件的应用程序中,我将中间件应用于根范围。
Router::scope('/', function (RouteBuilder $routes) {
$routes->registerMiddleware('csrf', new CsrfProtectionMiddleware([
'httpOnly' => true
]));
$routes->applyMiddleware('csrf');
...
如何禁用插件的中间件?
我尝试了$this->addPlugin(\My\Plugin::class, ['middleware' => false])
,但是没有用。
或者该插件负责禁用CSRF中间件吗?
您可以尝试以下代码:
// In Application::bootstrap()
use ContactManager\Plugin as ContactManagerPlugin;
// Use the disable/enable to configure hooks.
$plugin = new ContactManagerPlugin();
$plugin->disable('middleware');
$this->addPlugin($plugin);