CSRF 1.2.0
2021-11-22
828次浏览
Minor verison of CSRF package was tagged adding ability to specify your own failure handler:
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Yiisoft\Csrf\CsrfMiddleware;
/**
* @var Psr\Http\Message\ResponseFactoryInterface $responseFactory
* @var Yiisoft\Csrf\CsrfTokenInterface $csrfToken
*/
$failureHandler = new class ($responseFactory) implements RequestHandlerInterface {
private ResponseFactoryInterface $responseFactory;
public function __construct(ResponseFactoryInterface $responseFactory)
{
$this->responseFactory = $responseFactory;
}
public function handle(ServerRequestInterface $request): ResponseInterface
{
$response = $this->responseFactory->createResponse(400);
$response->getBody()->write('Bad request.');
return $response;
}
};
$middleware = new CsrfMiddleware($responseFactory, $csrfToken, $failureHandler);
新闻归档
热门标签
- yii3
- 扩展
- 发布
- yii2
- debug
- auth client
- view
- bootstrap
- release
- html
- redis
- apidoc
- Yii 2.0
- Yii 1.1
- mongodb
- mailer
- extensions
- twig
- gii
- queue
- runner
- http 客户端
- console
- validation
- cache
- sphinx
- widget
- hydrator
- translator
- symfonymailer
- db
- http
- log
- error handler
- config
- swiftmailer
- 图书
- imagine
- assets
- i18n
- IDE
- swagger
- elasticsearch
- router
- csrf
- smarty
- definitions
- logging
- fastroute
- user