Browse Source

SSO module rewrite

master
Ruben Meyer 1 year ago
parent
commit
4f0ea1f15b
Signed by: rxbn_ GPG Key ID: BE3BF898BE352FE2
  1. 54
      bin/sso/module.js

54
bin/sso/module.js

@ -6,42 +6,38 @@
* 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');
const methods = {};
const bent = require('bent');
const querystring = require('querystring');
const cfg = require(global['__dirname']+'/bin/config');
/**
* authenticate user
* @author Ruben Meyer
* @param {Object} obj obj (userId, userToken, appId, appSecret)
* @param {Function} callback obj (err, access => true, false)
* @async
* @param {Object} obj obj (userId, token, appId, appSecret)
* @return {Object} callback obj (err, access => {true, false})
*/
functions.authenticateUser = (obj, callback) => {
if(typeof callback !== 'function') callback = function() {};
methods.authenticateUser = async (obj, callback) => {
let request = bent(cfg.sso.providerApi, 'POST', 'json', 200);
request({
method: 'POST',
uri: global['gds'].cfg.sso.provider,
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
try {
let post = await request('', {
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"));
}
});
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;
}
};
/**
@ -51,12 +47,12 @@ functions.authenticateUser = (obj, callback) => {
* @param {Object} obj obj(url, appId)
* @param {Function} callback string(url)
*/
functions.createAuthentication = (obj) => {
methods.createAuthentication = (obj) => {
let nUrl = {
redirectUrl: obj.url,
appId: obj.appId
};
return global['gds'].cfg.sso.provider+"?"+querystring.stringify(nUrl);
return cfg.sso.providerUI+"?"+querystring.stringify(nUrl);
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Loading…
Cancel
Save