Please, how can i connect via ssl, https Node.js? Here's my code:
var Client = require('node-rest-client').Client;
client = new Client();
var headers = {
//"Accept": "application/json",
"Authorization": "Bearer "+sails.config.myGlobalVariables.access_token,
};
var args = {
headers: headers,
};
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
client.get("https://localhost:9443/oauth2/userinfo?schema=openid", args, function(data,response) {
// parsed response body as js object
//console.log(data.clienteCollection.cliente); //Prueba de listado de clientes recorrer JSON
// raw response
//console.log(response);
//console.log(data.name);
//req.session.nombreCompleto = data.name;
//console.log(data);
res.view('index',{
nombreCompleto: data.name,
});
});
I'm using the library node-rest-client and Sails.js. I do not want to place: process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; Thanks for your help.
Following node-rest-client and nodejs https.request documentation you could pass your CA in PEM format in options hash when creating a new client. You have to use a chained cert therefore. Otherwise you could use a cert signed by a well known "root" CA which is trusted by node.js.
new Client({
connection: {
ca: fs.readFileSync('ca.pem'),
}
});
As described in this issue node.js does not use the operation systems trust store but uses a statically compiled, manually updated, hardcoded list of certificate authorities.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.