Created
October 24, 2017 21:31
-
-
Save mindspank/b4376f1ec75a472ee1960fb73727b60f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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