Use meteor Http package with certificates


#1

Hi, could you please help me?

I try to make a http request. thing is i can’t really see what meteor is sending to the external server. I think i use the npmRequestOptions object incorrectly? where do I have to put the port? Is it better to use the npm http then? Which one is that? thank you so much!

The normal nodeJS code is like this

var options = {
    rejectUnauthorized: false,
    hostname: 'localhost',
    port: 4243,
    path: '/qps/test/user/QTSEL/akl?xrfkey=abcdefghijklmnop',
    method: 'DELETE',
    headers: {
        'x-qlik-xrfkey': 'abcdefghijklmnop',
        'X-Qlik-User': 'UserDirectory= Internal; UserId= sa_repository ',
        'Content-Type': 'application/json'
    },
    key: fs.readFileSync('client_key.pem'),
    cert: fs.readFileSync('client.pem')
};
 
https.get(options, function(res) {
    console.log("Got response: " + res.statusCode)
    
    res.on("data", function(chunk) {
        console.log("BODY: " + chunk);
    });
    
}).on('error', function(e) {
    console.log("Got error: " + e.message);
});

I try to make this code with meteor on a different host off course:

try {
        call.response = HTTP.call('DELETE' ,'http://' + senseConfig.host+':4243'+ '/qps/user/' + senseConfig.UDC + '/' + user.name + '?xrfkey=' + senseConfig.xrfkey,        
            {npmRequestOptions: certicate_communication_options}
        )
    } catch (err) {
        console.error(err);
        throw new Meteor.Error('Logout user failed', err.message);
    }
};

the certicate_communication_options object

<img src="/uploads/default/original/2X/6/6e22687d82b495437b1331ff636caeeb45d01e63.png" width="690" height="58">

#2

ok, it works now. the only thing what I would like to know.

  • what can we put in this npmRequestOptions field?
  • not the port? because I now added the port in the url and it works.
call.response = HTTP.call('DELETE', 'https://' + senseConfig.host + ':4243/qps/user/' + senseConfig.UDC + '/' + user.name
 + '?xrfkey=' + senseConfig.xrfkey, { 'npmRequestOptions': certicate_communication_options })

#3

From the HTTP section of the docs:

npmRequestOptions Object
On the server, HTTP.call is implemented by using the npm request module. Any options in this object will be passed directly to the request invocation.

All options are listed here: https://www.npmjs.com/package/request#requestoptions-callback


#4

Thank you Rob,

I got it to work, the key thing to learn here is: What is the difference between Meteor and NODE example code. The answer is that where you can put all stuff in node in 1 object. you have to split this in meteor? @robfallows Right? BTW, should I not use a HTTPS package here? It looks so strange now http.call (httpS

In my case I had to remove the port from the npmRequestOptions to the url string

call.response = HTTP.call('DELETE', 'https://' + senseConfig.host + ':4243/qps/user/' + senseConfig.UDC + '/' + user.name + '?xrfkey=' + 
                    senseConfig.xrfkey, { 'npmRequestOptions': certicate_communication_options })

For my info, can I only use https here? This is just a demo environment and I want to keep this as simple as possible. I always thought that there were 2 options with certificates
1: use it for authentication (Thats what I need, not really documented that broadly…)
2: use it to secure your communication (not needed here, but this is where all the community post talk about)

For other people, what really helped my was this
1: authentication using an SSL certificate is nothing more that just supplying 2 strings: 1 string called certificate and 1 string with the private string used to open this string. (you can see this as a zip file with a password on it)