Skip to content

Instantly share code, notes, and snippets.

@mindspank
Created September 16, 2016 15:15
Show Gist options
  • Save mindspank/c4ddc671acacfa63f8e5ec3a3a662407 to your computer and use it in GitHub Desktop.
Save mindspank/c4ddc671acacfa63f8e5ec3a3a662407 to your computer and use it in GitHub Desktop.
10 session apps
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: 'localhost',
pfx: fs.readFileSync(__dirname + '\\client.pfx')
})
// 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://localhost: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'];
console.log(ticket)
r.get('https://localhost/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.
// The origin specified needs an entry in the Whitelist for the virtual proxy to allow websocket communication.
var config = {
host: 'localhost',
isSecure: true,
origin: 'http://localhost',
rejectUnauthorized: false,
headers: {
"Content-Type": "application/json",
"Cookie": cookies[0]
}
}
for (var i = 1; i < 11; i++) {
qsocks.Connect({
host: 'localhost',
isSecure: true,
origin: 'http://localhost',
identity: i * Math.random() * Math.random(),
rejectUnauthorized: false,
headers: {
"Content-Type": "application/json",
"Cookie": cookies[0]
}
}).then((global) => {
global.createSessionApp().then(app => {
app.getAppProperties().then(props => console.log(props))
})
})
}
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment