Closed GaikwadPratik closed 7 years ago
@GaikwadPratik I don't see rawBody
used anywhere in this module. Can you point me at the code you're looking at?
In the readme.md
it is mentioned to use as verifier(cert_url, signature, requestRawBody, callback)
. Hence I was asking about requestRawBody
.
I am working on an alexa app using express. I have consumed alexa-middleware
as below
"server.js"
this.expressApp.use(bodyParser.json({
verify: function getRawBody(req, res, buf) {//This needs to be done because rawbody is required
req['rawBody'] = buf.toString();
}
}));
In "route.js", this is called on a post route invoked by alexa
alexaVerifier(
req.headers.signaturecertchainurl,
req.headers.signature,
req['rawBody'],//TODO:: test with body or (<any>req).rawBody
function verificationCallBack(err) {
if (err)
res.status(401).json({ message: 'Verification Failure', error: err });
else
next();
}
);
But I am getting below error on Heroku server:
2017-07-21T19:35:47.829522+00:00 app[web.1]: at VerifyApplicationRequest (/app/ServerCode/Routes/Routes.js:34:37)
2017-07-21T19:35:47.829523+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2017-07-21T19:35:47.829523+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/route.js:137:13)
2017-07-21T19:35:47.829524+00:00 app[web.1]: at verificationCallBack (/app/ServerCode/Routes/Routes.js:22:17)
2017-07-21T19:35:47.829524+00:00 app[web.1]: at /app/node_modules/alexa-verifier/index.js:98:5
2017-07-21T19:35:47.829525+00:00 app[web.1]: at /app/node_modules/alexa-verifier/index.js:31:5
2017-07-21T19:35:47.829525+00:00 app[web.1]: at Request._callback (/app/node_modules/alexa-verifier/fetch-cert.js:22:7)
2017-07-21T19:35:47.829526+00:00 app[web.1]: at Request.self.callback (/app/node_modules/request/request.js:188:22)
2017-07-21T19:35:47.829526+00:00 app[web.1]: at emitTwo (events.js:106:13)
2017-07-21T19:35:47.829527+00:00 app[web.1]: at Request.emit (events.js:192:7)
2017-07-21T19:35:47.907860+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Can't set headers after they are sent.
2017-07-21T19:35:47.907960+00:00 app[web.1]: (node:4) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
2017-07-21T19:35:47.839209+00:00 heroku[router]: at=info method=POST path="/Notes/SaveNotes" host=alexaskillnotesapp.herokuapp.com request_id=4e73ea7f-5492-444a-89c5-4a4830ea8ab2 fwd="72.21.217.182" dyno=web.1 connect=1ms service=157ms status=404 bytes=255 protocol=https```
can you please help me in resolving it?
@GaikwadPratik have you tried https://www.npmjs.com/package/alexa-verifier-middleware
If you're using express this middleware works very well. And it uses alexa-verifier
(this module) under the hood, handling all the express plumbing for you.
@mreinstein This is not issue. But I wanted to know why are you processing rawBody from
express.request
. What would happen ifreq.body
is sent instead ofreq.rawBody?