1
0
Fork 0

Single Sign-On module

This commit is contained in:
Ruben Meyer 2019-09-08 19:42:22 +02:00
parent ba044c9e6d
commit 5007d0a521
1 changed files with 65 additions and 0 deletions

65
bin/sso/module.js Normal file
View File

@ -0,0 +1,65 @@
/*
* This file is part of the authRxbn eco-system.
*
* (c) Ruben Meyer <contact@rxbn.de>
*
* 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;