I'm using node js as a proxy for rest services which use NTLM authentication.
I use httpntlm
module to bypass NTLM authentication. This module makes additional request and returns a response.
How can I write NTLM response data to original response?
var httpntlm = require('httpntlm');
var request = require('request');
app.use(function (req, res, next) {
httpntlm.post({
url: url,
username: username,
password: password,
workstation: '',
domain: domain,
json: req.body
}, function (err, ntlmRes) {
// console.log(ntlmRes.statusCode);
// console.log(ntlmRes.body);
res.body = ntlmRes.body;
res.status = ntlmRes.statusCode;
next();
// req.pipe(res);
});
});
In the example code you provided the Express.js middleware is used but calling simply next()
hand overs to next middleware and does not output anything. Instead of that we have to send the response back to client.
var httpntlm = require('httpntlm');
app.use(function (req, res, next) {
httpntlm.post({
url: url,
username: username,
password: password,
workstation: '',
domain: domain,
json: req.body
}, function (err, ntlmRes) {
// Also handle the error call
if (err) {
return res.status(500).send("Problem with request call" + err.message);
}
res.status(ntlmRes.statusCode) // Status code first
.send(ntmlRes.body); // Body data
});
});