/* * This file is part of the authRxbn eco-system. * * (c) Ruben Meyer * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ var functions = {}; var request = require('request'); var querystring = require('querystring'); /** * authenticate user * @author Ruben Meyer * @param {Object} obj obj (userId, userToken, appId, appSecret) * @param {Function} callback obj (err, access => true, false) */ functions.authenticateUser = (obj, callback) => { if(typeof callback !== 'function') callback = function() {}; request({ method: 'POST', uri: global['gds'].cfg.sso.authenticator, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ applicationId: obj.appId, applicationSecret: obj.appSecret, userId: obj.userId, token: obj.userToken }) }, (err, res, body) => { console.log('error:', err); // Print the error if one occurred console.log('statusCode:', res && res.statusCode); // Print the response status code if a response was received console.log('body:', body); // Print the HTML try { if(typeof body !== "object") body = JSON.parse(body); return callback(err, body.access); } catch(e) {} callback(new Error("Body is misformed")); }); }; /** * * Create Authentication * @author Ruben Meyer * @param {Object} obj obj(url, appId) * @param {Function} callback string(url) */ functions.createAuthentication = (obj) => { let nUrl = { redirectUrl: obj.url, appId: obj.appId }; return global['gds'].cfg.sso.redirectUser+"?"+querystring.stringify(nUrl); }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////// module.exports = functions;