0.6.1 • Published 10 years ago

calamarble-xhub v0.6.1

Weekly downloads
8
License
MIT
Repository
github
Last release
10 years ago

X-Hub-Signature check

A function to check the integrity of a body payload against it's x-hub-signature header for a given shared secret. Used by Facebook Messenger Webhook POST requests

Usage

With express.js

import express from 'express';
import bodyParser from 'body-parser';
import { apiEndpoint } from 'calamarble-xhub';

const expressConfig = {
    port: 8088,
    postPath: '/fbwebhook',
    messages: {
        serverRunning: port => `Server running on port ${port}`
    }
};
const xHubConfig = {
    algo: 'sha1',
    secret: 'MY_APP_SECRET',
    messages: {
        wrongSignature: 'Content signature don\'t match'
    }
};
const app = express();
const postEndPoint = apiEndpoint(xHubConfig);
app.use(bodyParser.raw({ type: 'application/json' }));
app.post(expressConfig.postPath, postEndPoint);
app.listen(expressConfig.port, () => console.log(`Server running on port ${expressConfig.port}`));

With claudia-api-builder

import ApiBuilder from 'claudia-api-builder';
import { apiEndpoint as webhookPost} from 'calamarble-xhub';

const api = new ApiBuilder();
const xHubConfig = {
    algo: 'sha1',
    secret: 'MY_APP_SECRET',
    messages: {
        wrongSignature: 'Content signature don\'t match'
    }
}

api.post('/fbwebhook', webhookPost(xHubConfig));

export { api as default };

With claudia-api-builder and a callback

import ApiBuilder from 'claudia-api-builder';
import { apiEndpoint as webhookPost} from 'calamarble-xhub';

const api = new ApiBuilder();
const myCallback = (req, res) => {
    return { foo: 'bar' };
}
const xHubConfig = {
    algo: 'sha1',
    secret: 'MY_APP_SECRET',
    messages: {
        wrongSignature: 'Content signature don\'t match'
    },
    next: myCallback
}


api.post('/fbwebhook', webhookPost(xHubConfig));

export { api as default };
0.6.1

10 years ago

0.6.0

10 years ago

0.5.0

10 years ago

0.4.2

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.5

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.11

10 years ago

0.1.10

10 years ago

0.1.9

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago