Skip to content

Instantly share code, notes, and snippets.

@mindspank
Last active September 7, 2023 19:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mindspank/5ca06519b7c799570323 to your computer and use it in GitHub Desktop.
Save mindspank/5ca06519b7c799570323 to your computer and use it in GitHub Desktop.
const request = require('request');
const qsocks = require('qsocks');
const fs = require('fs');
// Qlik Sense App ids
const appIds = ['efdf4130-7b89-45f6-8639-179666f3e35c',
'87c2d436-b9b0-4414-8fa1-f5289627b34e',
'b0d3a00d-798b-4e34-8e7c-ab06caa54567',
'69a8c183-8bc7-4aa4-8ad1-192dbf4d60f8',
'1158e903-446f-4092-bed1-beb748a209b3',
'050eb8d6-3128-420e-aabd-b3550c0275bd'];
// HTTP request defaults.
var r = request.defaults({
rejectUnauthorized: false,
host: 'localhost',
cert: fs.readFileSync(__dirname + '/client.pem'),
key: fs.readFileSync(__dirname + '/client_key.pem'),
});
/**
* Fetching ticket for User
*/
r.post({
uri: 'https://localhost:4243/qps/ticket?xrfkey=abcdefghijklmnop',
body: JSON.stringify({
"UserDirectory": 'QTSEL',
"UserId": 'Test',
"Attributes": []
}),
headers: {
'x-qlik-xrfkey': 'abcdefghijklmnop',
'content-type': 'application/json'
}
}, function(err, res, body) {
/**
* Consume the ticket so the Proxy will issue a session cookie/id.
*/
r.get('https://localhost/hub/?qlikTicket=' + JSON.parse(body)['Ticket'], function(error, response, body) {
/**
* Proxy consumes ticket and is issuing a set-cookie header containing our session id.
*/
var cookie = response.headers['set-cookie'][0];
appIds.forEach(function(id) {
// wss://localhost/app/<id>/
qsocks.Connect({
host: 'localhost',
isSecure: true,
origin: 'http://localhost',
rejectUnauthorized: false,
appname: id,
headers: {
"Content-Type": "application/json",
"Cookie": cookie //Making sure we re-use the proxy session across connections
}
})
.then(function(global) {
return global.openDoc(id);
})
.then(function(app) {
console.log('Opened app', id)
})
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment