1
0
Fork 0
SSObaseApp_nodeJS/bin/sso/module.js

63 lines
1.5 KiB
JavaScript

/*
* 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.
*/
const methods = {};
const bent = require('bent');
const querystring = require('querystring');
const cfg = require(global['__dirname']+'/bin/config');
/**
* authenticate user
* @author Ruben Meyer
* @async
* @param {Object} obj obj (userId, token, appId, appSecret)
* @return {Object} callback obj (err, access => {true, false})
*/
methods.authenticateUser = async (obj, callback) => {
let request = bent(cfg.sso.providerApi, 'POST', 'json', 200);
try {
let post = await request('', {
applicationId: obj.appId,
applicationSecret: obj.appSecret,
userId: obj.userId,
token: obj.token
});
if(post.status == 200 && post.message == "msg.auth.authentication.successful")
return true;
} catch(err) {
// something went wrong
console.log(err);
return false;
}
};
/**
*
* Create Authentication
* @author Ruben Meyer
* @param {Object} obj obj(url, appId)
* @param {Function} callback string(url)
*/
methods.createAuthentication = (obj) => {
let nUrl = {
redirectUrl: obj.url,
appId: obj.appId
};
return cfg.sso.providerUI+"?"+querystring.stringify(nUrl);
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
module.exports = methods;