SSO module rewrite
This commit is contained in:
parent
2b80061ee5
commit
4f0ea1f15b
@ -6,42 +6,38 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
var functions = {};
|
const methods = {};
|
||||||
var request = require('request');
|
const bent = require('bent');
|
||||||
var querystring = require('querystring');
|
const querystring = require('querystring');
|
||||||
|
|
||||||
|
const cfg = require(global['__dirname']+'/bin/config');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* authenticate user
|
* authenticate user
|
||||||
* @author Ruben Meyer
|
* @author Ruben Meyer
|
||||||
* @param {Object} obj obj (userId, userToken, appId, appSecret)
|
* @async
|
||||||
* @param {Function} callback obj (err, access => true, false)
|
* @param {Object} obj obj (userId, token, appId, appSecret)
|
||||||
|
* @return {Object} callback obj (err, access => {true, false})
|
||||||
*/
|
*/
|
||||||
functions.authenticateUser = (obj, callback) => {
|
methods.authenticateUser = async (obj, callback) => {
|
||||||
if(typeof callback !== 'function') callback = function() {};
|
let request = bent(cfg.sso.providerApi, 'POST', 'json', 200);
|
||||||
|
|
||||||
request({
|
try {
|
||||||
method: 'POST',
|
let post = await request('', {
|
||||||
uri: global['gds'].cfg.sso.provider,
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
applicationId: obj.appId,
|
applicationId: obj.appId,
|
||||||
applicationSecret: obj.appSecret,
|
applicationSecret: obj.appSecret,
|
||||||
userId: obj.userId,
|
userId: obj.userId,
|
||||||
token: obj.userToken
|
token: obj.token
|
||||||
})
|
});
|
||||||
}, (err, res, body) => {
|
|
||||||
console.log('error:', err); // Print the error if one occurred
|
if(post.status == 200 && post.message == "msg.auth.authentication.successful")
|
||||||
console.log('statusCode:', res && res.statusCode); // Print the response status code if a response was received
|
return true;
|
||||||
console.log('body:', body); // Print the HTML
|
} catch(err) {
|
||||||
try {
|
// something went wrong
|
||||||
if(typeof body !== "object") body = JSON.parse(body);
|
console.log(err);
|
||||||
return callback(err, body.access);
|
return false;
|
||||||
} catch(e) {
|
}
|
||||||
callback(new Error("Body is misformed"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,12 +47,12 @@ functions.authenticateUser = (obj, callback) => {
|
|||||||
* @param {Object} obj obj(url, appId)
|
* @param {Object} obj obj(url, appId)
|
||||||
* @param {Function} callback string(url)
|
* @param {Function} callback string(url)
|
||||||
*/
|
*/
|
||||||
functions.createAuthentication = (obj) => {
|
methods.createAuthentication = (obj) => {
|
||||||
let nUrl = {
|
let nUrl = {
|
||||||
redirectUrl: obj.url,
|
redirectUrl: obj.url,
|
||||||
appId: obj.appId
|
appId: obj.appId
|
||||||
};
|
};
|
||||||
return global['gds'].cfg.sso.provider+"?"+querystring.stringify(nUrl);
|
return cfg.sso.providerUI+"?"+querystring.stringify(nUrl);
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
x
Reference in New Issue
Block a user