Sign and Encodes/Decodes HTTP requests.
Its a general purpose sign request manager. Encodes and decodes communications using a private key (a secret) between peers.
npm intall signed-req
Encodes outgoing data with
var SignedRequest = require'signed-req';var request = require'request';var dataToSend =user:name: "foo"email: "email@example.com";var encoded = SignedRequestencodeAndSigndataToSend "mysecret";requestpost"" form: encodedData: encodedif err throw err;if resbodystatusconsole.log"User has been created :)";elseconsole.error"User has not been created :(";;
And in the other side we can decode that incomming data with
var SignedRequest = require'signed-req';apppost'/user'//Assuming encodedData is an existing post param:var decoded = SignedRequestdecodeAndParsereqbodyencodedData "mysecret";if decodedcreateUserdecodedusername decodeduseremail;//for example.ressend"I trust in you. I can validate the incoming data and its integrity is assured";elseressend403 "You have no access. Your request is not valid";;
An alternative decoding request can be made through
var SignedRequest = require'signed-req';apppost'/user' SignedRequestsignedDecodeAndParse"request" "mysecret"//for example.createUserbodydecodedSignedRequestusernamebodydecodedSignedRequestuseremail;;
Where "request" is the name of param we expect contains signed request.
If middleware cant decode info inside the param, will have no access to app.post('/user')