vtex-apps / store-discussion

VTEX IO store builders' community
80 stars 5 forks source link

httpsAgent to add client certificate does not work properly. #627

Open kaitos90210 opened 3 years ago

kaitos90210 commented 3 years ago

Describe the bug

Currently the requests are proxied when calling external endpoints. When there is the need to add client certificates to the request using axis with httpsAgent does not work properly. The client certificate attached is lost.

To Reproduce Steps to reproduce the behavior:

javascript

const agent = new https.Agent({
    cert,
    key
    });

var response = await axios({
    method: 'post',
    url,
    data,
    httpsAgent : agent,
    headers: {
            'X-Vtex-Use-Https': true,
            'Proxy-Authorization': authToken
        }
  })
  return response

Expected behaviour Allow add in the request client certificates to establish secure connections.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop environment (please complete the following information, if applicable):

- Service:

Additional context Add any other context about the problem here.

Maik3345 commented 3 years ago

@kaitos90210 try with 'node-fetch' https://www.npmjs.com/package/node-fetch#simple-post

image

This work for me

kaitos90210 commented 3 years ago

@Maik3345 thanks for your help, but this is not related to a js framework. It did work with axios perfectly. but not in vtex-io the reason behind is that there is a proxy that takes the request in http and then to https, that's why you use the header X-VTEX-Use-Https. You can also check the message on console explaining this.

Does your server you validated. agains it, validates the https certificate?. Some example is Apple Pay.

Maik3345 commented 3 years ago

@kaitos90210 I understand the problem, if you get the solution you could comment it here to know how this can be implemented natively.