chubbyphp / chubbyphp-csrf
此包已被放弃且不再维护。未建议替代包。
Chubbyphp Csrf
1.1.1
2018-04-22 14:37 UTC
Requires
- php: ~7.0
- chubbyphp/chubbyphp-error-handler: ~1.0
- chubbyphp/chubbyphp-session: ~1.0
- psr/log: ~1.0
Requires (Dev)
- phpunit/phpunit: ~6.0
- pimple/pimple: ~3.0
Suggests
- pimple/pimple: Is needed for the CsrfProvider
This package is auto-updated.
Last update: 2020-09-22 18:49:15 UTC
README
描述
基于 chubbyphp/chubbyphp-session 的简单csrf解决方案。
要求
- php: ~7.0
- chubbyphp/chubbyphp-error-handler: ~1.0
- chubbyphp/chubbyphp-session: ~1.0
- psr/log: ~1.0
建议
- pimple/pimple: ~3.0
安装
通过 Composer 以 chubbyphp/chubbyphp-csrf 的方式。
composer require chubbyphp/chubbyphp-csrf "~1.0"
使用方法
CsrfErrorResponseMiddleware
<?php use Chubbyphp\Csrf\CsrfErrorHandlerInterface; use Chubbyphp\Csrf\CsrfErrorResponseMiddleware; use Chubbyphp\Csrf\CsrfTokenGenerator; use Chubbyphp\Session\Session; $session = new Session(); $middleware = new CsrfErrorResponseMiddleware( new CsrfTokenGenerator(), $session, new class() implements CsrfErrorHandlerInterface { public function errorResponse( Request $request, Response $response, int $code, string $reasonPhrase ): Response { return $response->withStatus($code, $reasonPhrase); } } ); /** @var Slim\App $app */ $app->add($middleware);
CsrfMiddleware (已弃用)
<?php use Chubbyphp\Csrf\CsrfMiddleware; use Chubbyphp\Csrf\CsrfTokenGenerator; use Chubbyphp\Session\Session; $session = new Session(); $middleware = new CsrfMiddleware(new CsrfTokenGenerator(), $session); /** @var Slim\App $app */ $app->add($middleware);
CsrfProvider (Pimple)
<?php namespace Chubbyphp\Csrf\CsrfProvider; namespace Chubbyphp\Csrf\SessionProvider; namespace Pimple\Container; $container = new Container(); $container->register(new CsrfProvider()); $container->register(new SessionProvider()); /** @var Slim\App $app */ $app->add($container['csrf.middleware']);
CsrfTokenGenerator
<?php use Chubbyphp\Csrf\CsrfTokenGenerator; $generator = new CsrfTokenGenerator();
版权
Dominik Zogg 2016