koa-x-hub
Install
Usage
Add the middleware to Koa. It needs to be after bodyParser()
.
const Koa = ;const bodyParser = ;const xHub = ; const app = ;app;app;
Where XHUB_SECRET_HERE
is your platform's (facebook, github, etc) secret.
This will add some special sauce to your ctx.request
object:
boolean
isXHub Is the request X-Hub. Allows you to early reject any messages without XHub content.
if !ctxrequestisXHub ctx;
ctx.request.isXHubValid()
isXHubValid Returns a boolean value. Validates the request body against the X-Hub signature using your secret.
if !ctxrequestisXhub || !ctxrequest ctx;
If it's valid, then the request has not been tampered with and you are safe to process it.
Options
- secret: X-Hub secret that is used to validate the request body against the signed X-HUB signature on the header. Required.
- algorithm: Encryption algorithm used to generate the signature. Default is
sha1
.
License
Acknowledgements
This project is inspired by express-x-hub.