https://github.com/manifoldco/node-signature
Verify signed HTTP requests from Manifold
https://github.com/manifoldco/node-signature
Last synced: 3 months ago
JSON representation
Verify signed HTTP requests from Manifold
- Host: GitHub
- URL: https://github.com/manifoldco/node-signature
- Owner: manifoldco
- License: bsd-3-clause
- Created: 2017-04-04T13:02:03.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-03-26T19:08:47.000Z (over 4 years ago)
- Last Synced: 2025-05-08T08:03:25.281Z (5 months ago)
- Language: JavaScript
- Homepage: https://www.manifold.co
- Size: 58.6 KB
- Stars: 1
- Watchers: 25
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# node-signature
Verify signed HTTP requests from Manifold
[Code of Conduct](./.github/CONDUCT.md) | [Contribution Guidelines](./.github/CONTRIBUTING.md)
[](https://github.com/manifoldco/node-signature/releases) [](https://travis-ci.org/manifoldco/node-signature) [](./LICENSE.md) [](https://npmjs.org/package/@manifoldco/signature)
## Install
```bash
$ npm install @manifoldco/signature
```## Usage
```js
var Verifier = require('@manifoldco/signature').Verifier;
var verifier = new Verifier();// Using the promise interface
verifier.test(req, req.rawBody).then(function() {
// Accept and handle request
}).catch(function(err) {
// Deny request on error
res.statusCode = err.statusCode || 500;
// Respond with JSON, including a message property
return res.json({ message: err.message });
});// Using the callback interface
verifier.test(req, req.rawBody, function(err) {
if (err) {
// Deny request on error
res.statusCode = err.statusCode || 500;
// Respond with JSON, including a message property
return res.json({ message: err.message });
}// Accept and handle request
});
```### Restify
```js
var Verifier = require('@manifoldco/signature').Verifier;
var verifier = new Verifier();// The verification library expects that the req.rawBody property
// exists so that the body does not have to be read twice, this can be
// done automatically with restify-plugins bodyParser
app.use(plugins.bodyParser({ mapParams: true }));// Applying the verifier middleware with default master key and options (recommended)
app.use(function(req, res, next) {
verifier.test(req).then(function() {
// Accept and handle request
next();
}).catch(function(err) {
// Deny request on error
res.statusCode = err.statusCode || 500;
// Respond with JSON, including a message property
return res.json({ message: err.message });
});
});
```### Express
```js
var verifier = require('@manifoldco/signature').express;// When using an existing body parser, we require you to add a verify step
// which will keep track of the original request body for the verifier
// middleware
app.use(bodyParser.json({ verify: verifier.appendRawBody }));// Applying the verifier middleware with default master key and options (recommended)
app.use(verifier.middleware());
```