hydra-express-plugin-signed-request
v0.0.3
Published
HydraExpressPlugin for signed inter-service requests
Downloads
8
Readme
hydra-express-plugin-signed-request
Summary
The hydra.plugins
entry in config.json for this plugin supports these properties:
externalApiUrl
- URL to API for external requests
sharedSecret
required - secret key shared between services
debug
optional - output debug logs, defaults to false
E.g.
{
"hydra": {
"plugins": {
"signed-request": {
"externalApiUrl": "https://api.flywheelsports.com",
"sharedSecret": "qK{v*9ch)7KBUJ<];)2_%*X37xEW",
"debug": true
}
}
}
}
Added Methods
hydraExpress.validateRequestSignature()
- Express middleware, ensures a request was properly signed.
hydra.makeSignedAPIRequest(message, sendOpts = { }, external = false)
- signed version of hydra.makeAPIRequest
Usage
const hydraExpress = require('hydra-express');
// in serviceA
const hydra = hydraExpress.getHydra();
hydra.makeSignedAPIRequest({
from: 'serviceA:/'
to: 'serviceB:[GET]/needsSignature'
});
// in serviceB
const SignedRequestPlugin = require('hydra-express-plugin-signed-request');
hydraExpress.use(new SignedRequestPlugin());
api.get('/needsSignature', hydraExpress.verifyRequestSignature(), (req, res) => {
console.log('Signature looks good!');
});