Code Monkey home page Code Monkey logo

koa-x-hub's Introduction

koa-x-hub

NPM version build status node version

X-Hub-Signature Koa Middleware.

Install

NPM

Usage

Add the middleware to Koa. It needs to be after bodyParser().

const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const xHub = require('koa-x-hub');

const app = new Koa();
app.use(bodyParser());
app.use(xHub({algorithm: 'sha1', secret: XHUB_SECRET_HERE}));

Where XHUB_SECRET_HERE is your platform's (facebook, github, etc) secret.

This will add some special sauce to your ctx.request object:

isXHub boolean

Is the request X-Hub. Allows you to early reject any messages without XHub content.

if (!ctx.request.isXHub) { ctx.throw(403, 'No X-Hub Signature'); }

isXHubValid ctx.request.isXHubValid()

Returns a boolean value. Validates the request body against the X-Hub signature using your secret.

if (!ctx.request.isXhub || !ctx.request.isXHubValid()) { ctx.throw(403, 'Invalid X-Hub Request'); }

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

MIT

Acknowledgements

This project is inspired by express-x-hub.

koa-x-hub's People

Contributors

mudkipme avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

huijiwiki reasno

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.