2.0.2 • Published 6 years ago

hapi-github-webhooks v2.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

hapi-github-webhooks

Description

npm version Build Status Dependency Status

An authentication strategy plugin for hapi for validating webhook requests from GitHub. This strategy validates the payload with the hmac-sha1 signature sent with the request.

This strategy is compatible with application/json webhook payloads.

The 'githubwebhook' scheme takes the following options:

  • secret - (required) the token configured for the webhook (never share or commit this to your project!)

Compatibility

  • >= v17: Use 2.x
  • <= v16: Use 1.x

Version 1.0

Example

There is an example server located in example/server.js. You can run this server with npm run example.

Usage

var hapi = require("hapi");
var githubWebhooksPlugin = require("hapi-github-webhooks");
var token = "SomeUnsharedSecretToken";
var server = new hapi.Server();

server.connection({
  host: host,
  port: port
});

server.register(githubWebhooksPlugin, function(err) {
  // Register github webhook auth strategy
  server.auth.strategy("githubwebhook", "githubwebhook", { secret: token });
  // Apply the strategy to the route that handles webhooks
  server.route([
    {
      method: "POST",
      path: "/webhooks/github",
      config: {
        auth: {
          strategies: ["githubwebhook"],
          payload: "required"
        }
      },
      handler: function(request, reply) {
        // request.payload is the validated payload from GitHub
        reply();
      }
    }
  ]);
});
2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.3

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago