Open neerajshah179 opened 4 years ago
I also have this problem
I've got the same problem, but I found a solution that not documented:
Library http-proxy
required target
to be a string, but actually, you can pass an object to it. It does check it if target
is a string, and transform it using url.parse
:
https://github.com/http-party/node-http-proxy/blob/master/lib/http-proxy/index.js#L63-L66
finally, some properties on target
will be passed to https.request
.
https://github.com/http-party/node-http-proxy/blob/master/lib/http-proxy/common.js#L33-L40
So, we can just pass a parsed URL to the target
, including necessary options:
target: {
protocol: 'https:', // this is required
host: 'test.example.com',
hostname: 'test.example.com', // this.is optional
path: '/',
cert: fs.readFileSync('/path/to/cert.pem', 'utf8'),
key: fs.readFileSync('/path/to/key.pem', 'utf8'),
}
This works for me to configure proxy of webpack-dev-server.
I am using the http-proxy-middleware (https://www.npmjs.com/package/http-proxy-middleware) to implement a proxy to another REST API that has client-side certificate based authentication enabled (requestCert: true, rejectUnauthorized: true).
Client calls to the Proxy API ( https://localhost:3000/auth ) where http-proxy-middleware is configured and is supposed to proxy it to another REST API ( https://localhost:3002/auth ) that has client-side certificate based authentication enabled (requestCert: true, rejectUnauthorized: true).
I don't want any specific authentication to happen at the proxy. When I invoke the proxy with a path that will route to this target end-point with client-side certs based authentication, it is failing with error message:
Error received in proxy server:
Error received in client side:
I don't need the proxy to validate/act on client-side certs coming with the incoming request in any way (I have set secure: false for this), but rather just forward it to the target end point. We are seeing the the certs received from the client are not being passed/proxied/forwarded to the target end-point and hence cert based auth fails on the target end-point.
The client request when sent to the target end-point directly is working, but NOT when sent via http-proxy-middleware proxy.
My test server, client code is given below for reference.
Is there some way to configure the http-proxy-middleware so that it forwards/proxies the client-side certs received from the client to the target end-point so that the client-side certs sent by the client are available for cert based validation on the target REST end-point?
Could you please guide me on how to do this with http-proxy-middleware package or any other suitable way? Thanks in advance.
Steps to reproduce
Server code
Client Code
Expected behavior
Is there some way to configure the http-proxy-middleware so that it forwards/proxies the client-side certs received from the client to the target end-point so that the client-side certs sent by the client are available for cert based validation on the target REST end-point?
Could you please guide me on how to do this with http-proxy-middleware package or any other suitable way? Thanks in advance.
Actual behavior
I don't need the proxy to validate/act on client-side certs coming with the incoming request in any way (I have set secure: false for this), but rather just forward it to the target end point. We are seeing the the certs received from the client are not being passed/proxied/forwarded to the target end-point and hence cert based auth fails on the target end-point.
The client request when sent to the target end-point directly is working, but NOT when sent via http-proxy-middleware proxy.
Setup