Skip to content

Instantly share code, notes, and snippets.

@mindspank
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mindspank/b85cb1ecfeb80a4496ea to your computer and use it in GitHub Desktop.
Save mindspank/b85cb1ecfeb80a4496ea to your computer and use it in GitHub Desktop.
QES-qsocks-connect.js
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.
// Export the certificates from your Qlik Sense installation and refer to them
var r = request.defaults({
rejectUnauthorized: false,
host: 'usrad-akl',
key: fs.readFileSync(__dirname + '/client_key.pem'),
cert: fs.readFileSync(__dirname + '/client.pem')
});
// Authenticate whatever user you want
var b = JSON.stringify({
"UserDirectory": 'qtsel',
"UserId": 'akl',
"Attributes": []
});
// Get ticket for user - refer to the QPS API documentation for more information on different authentication methods.
r.post({
uri: 'https://usrad-akl:4243/qps/ticket?xrfkey=abcdefghijklmnop',
body: b,
headers: {
'x-qlik-xrfkey': 'abcdefghijklmnop',
'content-type': 'application/json'
}
},
function(err, res, body) {
//Get the ticket that was returned.
var t = JSON.parse(body)['Ticket'];
// qsocks config
// The origin specified needs an entry in the Whitelist for the virtual proxy to allow websocket communication.
var config = {
host: 'usrad-akl',
isSecure: true,
port: 443,
origin: 'https://usrad-akl',
rejectUnauthorized: false,
ticket: t
};
// Connect to qsocks/qix engine
// calls wss('wss://usrad-akl:443/app/%3Ftransient%3D?qlikTicket=<ticket>') with valid ticket appended.
qsocks.Connect(config).then(function(global) {
//We are now connected and can operate on the global class, handle -1
//Call method getDocList()
global.getDocList().then(function(doclist) {
//Iterate over available documents and log them.
doclist.forEach(function(d) {
console.log(d);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment