node-fetch: request failed, reason: self signed certificate
Today, when I’m using node-fetch to request a facebook api end-point, I received “self signed certificate” error.
Error: request to https://graph.facebook.com/v2.3/<POST_ID>?fields=id,from,created_time,updated_time,picture&access_token=<FB_TOKEN> failed, reason: self signed certificate
at ClientRequest.<anonymous> (/home/<PROJECT_PATH>/node_modules/node-fetch/index.js:116:11)
at emitOne (events.js:77:13)
at ClientRequest.emit (events.js:166:7)
at TLSSocket.socketErrorListener (_http_client.js:254:9)
at emitOne (events.js:77:13)
at TLSSocket.emit (events.js:166:7)
at TLSSocket.<anonymous> (_tls_wrap.js:931:16)
at emitNone (events.js:67:13)
at TLSSocket.emit (events.js:163:7)
at TLSSocket._finishInit (_tls_wrap.js:506:8)'
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 20 (3 by maintainers)
I did it like this:
This is also an environment variable you can set in later versions of node.js to suppress the certificate authorization:
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";or
NODE_TLS_REJECT_UNAUTHORIZED="0" npm starthttps://stackoverflow.com/a/21961005
This
httpsmodule is huge: +250Kib (unzipped) to the bundle 😦 Anyone aware of a decently sized solution for Node, Browser and SSR?Hi I tried
in the same file where I make the request
in root/.env
All the above methods don’t work for me, and I am still getting the same error.
-kflag@johanhenrikssn worked for me fixing isomorphic-fetch and vue-apollo. Thanks.
For a safer option, you can also use
key,cert,caof https.Agent options.https://nodejs.org/api/https.html#https_https_request_options_callback
https.requestAPI has arejectUnauthorizedoption with boolean value, set to false if you don’t want to verify certificate . Hope node-fetch add this option.I added some code in
./lib/request.jsand it works as expected.You can’t even use the
httpsmode in browsers, so why would it matter that its large?@johanhenrikssn any idea of the security implications of that “fix”? 😃
agentis one of the available options: https://github.com/bitinn/node-fetch#optionsI believe so. As I need to try to avoid the same thing in Postman and cULR
I used this es6 syntax and it worked for me. No need to set node global options.