anfly0/psr-15-github-auth
Composer 安装命令:
composer require anfly0/psr-15-github-auth
包简介
PSR-15 middleware for authenticating incoming webhooks from github
README 文档
README
Simple PSR-15 middleware for authenticating GitHub webhooks.
Installation
$ composer require anfly0/psr-15-github-auth
Example
Install dependencies for the following example:
composer require anfly0/psr-15-github-auth composer require slim/slim ^4.0.0-beta composer require slim/psr7 composer require monolog/monolog
<?php /** * Minimal example using slim 4.0.0-beta and monolog */ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Factory\AppFactory; use Slim\Psr7\Factory\StreamFactory; use Monolog\Logger; use Monolog\Handler\StreamHandler; use Anfly0\Middleware\GitHub\Auth; require './vendor/autoload.php'; // Logger setup $logger = new Logger('example'); $logger->pushHandler(new StreamHandler('./example.log', Logger::INFO)); // Slim setup $app = AppFactory::create(); // Middleware setup $auth = new Auth('test', $app->getResponseFactory(), new StreamFactory()); $auth->setLogger($logger); // If the request has no body, set the body to the contents of php://input. $body = function (Request $request, $handler) { if ($request->getBody()->getSize() === 0) { $streamFactory = new StreamFactory(); $request = $request->withBody($streamFactory->createStreamFromFile('php://input')); } return $handler->handle($request); }; // Setup route and add middleware $app->post('/', function (Request $request, Response $response, $args) { $response->getBody()->write('OK'); return $response; }) ->addMiddleware($auth) ->add($body); $app->run();
FAQ
-
Authentication fails when I expect it to succeed!?
- Make sure that the correct secret is passed to the constructor when the middleware object is instantiated.
- Make sure that $request->getBody() === file_get_content('php://input').
- i.e The ServerRequest object that is passed to the process method actually contains the request body.
-
How do I get the logging to work?
- Simply pass a PSR-3 compliant logger the setLogger method
License
- MIT license
- Copyright 2019 © Viktor Hellström
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-07-25