swop/stack-github-webhook

此包已被废弃且不再维护。作者建议使用 swop/github-webhook-stackphp 包。

Stack 中间件,用于验证传入的 GitHub webhook 请求是否正确签名。

v1.1 2016-11-10 23:35 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:40:51 UTC


README

Build Status

Stack 中间件,用于限制应用程序通过签名负载访问 GitHub Event 机器人。

每个传入请求都会检查其 X-Hub-Signature 头部,以验证请求最初是由 GitHub 执行的。任何没有正确签名的请求都将导致返回 401 Unauthorized JSON 响应。

安装

推荐通过 Composer 安装此库。

composer require "swop/github-webhook-stackphp"

用法

Silex 示例

require __DIR__ . '/../vendor/autoload.php';

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

$app = new \Silex\Application();

$app->get('/', function(Request $request) {
    return new Response('Hello world!', 200);
});

$app = (new \Stack\Builder())
    ->push('Swop\GitHubWebHookStackPHP\GitHubWebHook', 'my_secret')
    ->resolve($app)
;

$request = Request::createFromGlobals();
$response = $app->handle($request)->send();

$app->terminate($request, $response);

Symfony 示例

# web/app_dev.php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
Debug::enable();

require_once __DIR__.'/../app/AppKernel.php';

$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();

$stack = (new Stack\Builder())
    ->push('Swop\GitHubWebHookStackPHP\GitHubWebHook', 'my_secret')
;

$kernel = $stack->resolve($kernel);

Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

贡献

CONTRIBUTING 文件。

原始贡献者

许可

此库在 MIT 许可下发布。请参阅附带 LICENSE 文件中的完整许可。