Skip to content

Instantly share code, notes, and snippets.

@mindspank
Last active October 23, 2017 09:15
Show Gist options
  • Save mindspank/c623e3f0bcf448093feb to your computer and use it in GitHub Desktop.
Save mindspank/c623e3f0bcf448093feb to your computer and use it in GitHub Desktop.
Very verbose example on how to connect qsocks to a server.
var qsocks = require('qsocks');
var fs = require('fs');
var request = require('request');
//Set our request defaults, ignore unauthorized cert warnings as default QS certs are self-signed.
var r = request.defaults({
rejectUnauthorized: false,
host: 'usrad-akl.qliktech.com',
pfx: fs.readFileSync("C:\\QlikTech\\Demo Team\\Node\\qsocks\\client.pfx")
})
//Authenticate whatever user you want
var b = JSON.stringify({
"UserDirectory": 'qtsel',
"UserId": 'akl',
"Attributes": []
});
//Get ticket for user
r.post({
uri: 'https://usrad-akl.qliktech.com:4243/qps/ticket?xrfkey=abcdefghijklmnop',
body: b,
headers: {
'x-qlik-xrfkey': 'abcdefghijklmnop',
'content-type': 'application/json'
}
},
function(err, res, body) {
//Consume ticket, set cookie response in our upgrade header against the proxy.
var ticket = JSON.parse(body)['Ticket'];
r.get('https://usrad-akl.qliktech.com/hub/?qlikTicket=' + ticket, function(error, response, body) {
var cookies = response.headers['set-cookie'];
//qsocks config, merges into standard https/http object headers.
//Set the session cookie correctly.
var config = {
host: 'usrad-akl.qliktech.com/app/',
isSecure: true,
origin: 'http://localhost',
rejectUnauthorized: false,
headers: {
"Content-Type": "application/json",
"Cookie": cookies[0]
}
}
//Connect to qsocks/qix engine
qsocks.Connect(config).then(function(global) {
//Get our global handle
global.createApp('This is a new app', 'First Script Tab').then(function(success) {
console.log(success)
});
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment