Created
January 19, 2015 14:57
-
-
Save mindspank/4f93cac0c484cda3c500 to your computer and use it in GitHub Desktop.
This file contains 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
var request = require('request'); | |
var Promise = require("es6-promise").Promise | |
var fs = require('fs'); | |
var certs = require('./certs'); | |
module.exports = function() { | |
var r = request.defaults({ | |
rejectUnauthorized: false, | |
key: certs.key, | |
cert: certs.cert | |
}) | |
function getTicket(dir, user, attr) { | |
var attr = attr || []; | |
var b = JSON.stringify({ | |
"UserDirectory": dir, | |
"UserId": user, | |
"Attributes": attr | |
}); | |
return new Promise(function(resolve, reject) { | |
r.post({ | |
uri: 'https://usrad-akl.qliktech.com:4243/qps/demo/ticket?xrfkey=abcdefghijklmnop', | |
body: b, | |
headers: { | |
'header-demo': dir + '\\' + user, | |
'x-qlik-xrfkey': 'abcdefghijklmnop', | |
'content-type': 'application/json' | |
} | |
}, | |
function(err, res, b) { | |
if (err) { | |
return reject(err); | |
} else if (res.statusCode !== 201) { | |
err = new Error("Unexpected status code: " + res.statusCode); | |
err.res = res; | |
return reject(err); | |
} | |
resolve(JSON.parse(res.body)); | |
}) | |
}) | |
}; | |
function getSession(ticket) { | |
return new Promise(function(resolve, reject) { | |
r.get({ | |
uri: 'https://usrad-akl.qliktech.com/demo/app/?qlikTicket=' + ticket | |
}, function(err, res, body) { | |
if (err) { | |
reject(err) | |
}; | |
resolve(res) | |
}); | |
}); | |
}; | |
return { | |
getTicket: getTicket, | |
getSession: getSession | |
}; | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment