Skip to content

Instantly share code, notes, and snippets.

@mindspank
Created October 24, 2017 21:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mindspank/b4376f1ec75a472ee1960fb73727b60f to your computer and use it in GitHub Desktop.
Save mindspank/b4376f1ec75a472ee1960fb73727b60f to your computer and use it in GitHub Desktop.
const jwt = require('jsonwebtoken')
const fs = require('fs')
const path = require('path')
const request = require('request-promise') //Peer-dep to request
const QLIK_HOST = 'usrad-aklprobook'
const QLIK_VIRTUAL_PROXY_PREFIX = 'stratsys'
/**
* In this case we re-use the private cert from Qlik to sign our token
*/
const certificates = {
key: fs.readFileSync('client_key.pem')
}
let token = jwt.sign({
'userId': 'myuser',
'userDirectory': 'somedirectory'
}, certificates.key, {
'algorithm': 'RS256'
})
// Request a Qlik resource
request({
url: `https://${QLIK_HOST}/${QLIK_VIRTUAL_PROXY_PREFIX}/hub`,
headers: {
Authorization: 'Bearer ' + token
},
resolveWithFullResponse: true, // For request-promise to return the full response
rejectUnauthorized: false // Dont reject self-signed certs
})
.then(response => {
// The request returned a set-cookie http header
console.log(response.headers['set-cookie'])
// We can now use the session cookie to establish any other request into Qlik.
// Such as establishing a websocket against the engine.
// A good idea would be to cache the session cookie to avoid establishing too many sessions for the user thus consuming tokens.
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment