I have created a new ASP.NET Web Application -> Web API 2 project with Windows Authentication. This works fine in IIS Express but to get hot reloading for my React front end I have tried to use webpack-dev-server and have it proxy my IIS Express. I have used this before both with cookie authentication and token (Bearer) authentication without a problem but with Windows Authentication (NTLM Authentication) it does not work.
Looking at the response from the server I get the expected 401 Unauthorized (401.2) response with the header www-authenticate: Negotiate, NTLM as expected but I don't think the client re-sends the request with Authorization: NTLM.
Browsers that I have tried with (Chrome, Firefox and IE) does not give me the normal prompt to enter correct credentials either.
https://blogs.msdn.microsoft.com/chiranth/2013/09/20/ntlm-want-to-know-how-it-works/
My settings in webpack.config.js looks like this:
var proxy = 'localhost:57263';
devServer: {
proxy: {
'*': {
target: 'http://' + proxy,
changeOrigin: true,
},
port: 8080,
host: '0.0.0.0',
hot: true,
},
}
After looking at the documentation for webpack-dev-server Proxy I saw that they use http-proxy-middleware.
https://webpack.github.io/docs/webpack-dev-server.html#proxy
This led me to this thread and answer:
https://github.com/chimurai/http-proxy-middleware/issues/39#issuecomment-330911943
Final solution:
Run:
npm install agentkeepalive --save
Working code:
var proxy = 'localhost:57263';
devServer: {
proxy: {
'*': {
target: 'http://' + proxy,
changeOrigin: true,
agent: new agent({
maxSockets: 100,
keepAlive: true,
maxFreeSockets: 10,
keepAliveMsecs: 100000,
timeout: 6000000,
keepAliveTimeout: 90000 // free socket keepalive for 90 seconds
}),
onProxyRes: (proxyRes) => {
var key = 'www-authenticate';
proxyRes.headers[key] = proxyRes.headers[key] && proxyRes.headers[key].split(',');
},
},
port: 8080,
host: '0.0.0.0',
hot: true,
},
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With