index.js
function (soajs, data, cb) {
        let token = data.token;
        let openam;

        if (soajs.servicesConfig.urac && soajs.servicesConfig.urac.openam) {
            openam = soajs.servicesConfig.urac.openam;
        }
        else {
            return cb({"code": 712, "msg": soajs.config.errors[712]});
        }

        let openamAttributesURL = openam.attributesURL;
        let openamAttributesMap = openam.attributesMap;
        let openamTimeout = openam.timeout || 10000;

        request.post(openamAttributesURL, {
            form: {subjectid: token},
            timeout: openamTimeout
        }, function (error, response, body) {
            let userRecord;

            if (error) {
                soajs.log.error(error);
                return cb({"code": 710, "msg": soajs.config.errors[710]});
            }

            if (!response || response.statusCode !== 200) {
                soajs.log.error("OpenAM token invalid!");
                return cb({"code": 711, "msg": soajs.config.errors[711]});
            }

            try {
                userRecord = JSON.parse(body);
            } catch (err) {
                soajs.log.error("OpenAM response invalid!");
                return cb({"code": 712, "msg": soajs.config.errors[712]});
            }

            soajs.log.debug('Authenticated!');

            initBLModel(soajs, function (err) {
                if (err) {
                    return cb(err);
                }
                utilities.saveUser(soajs, driver.model, 'openam', {
                    userRecord: userRecord,
                    attributesMap: openamAttributesMap
                }, function (error, record) {
                    return cb(null, record);
                });
            });
        });
    }
function (soajs, data, cb) {
        let token = data.token;
        let openam;

        if (soajs.servicesConfig.urac && soajs.servicesConfig.urac.openam) {
            openam = soajs.servicesConfig.urac.openam;
        }
        else {
            return cb({"code": 712, "msg": soajs.config.errors[712]});
        }

        let openamAttributesURL = openam.attributesURL;
        let openamAttributesMap = openam.attributesMap;
        let openamTimeout = openam.timeout || 10000;

        request.post(openamAttributesURL, {
            form: {subjectid: token},
            timeout: openamTimeout
        }, function (error, response, body) {
            let userRecord;

            if (error) {
                soajs.log.error(error);
                return cb({"code": 710, "msg": soajs.config.errors[710]});
            }

            if (!response || response.statusCode !== 200) {
                soajs.log.error("OpenAM token invalid!");
                return cb({"code": 711, "msg": soajs.config.errors[711]});
            }

            try {
                userRecord = JSON.parse(body);
            } catch (err) {
                soajs.log.error("OpenAM response invalid!");
                return cb({"code": 712, "msg": soajs.config.errors[712]});
            }

            soajs.log.debug('Authenticated!');

            initBLModel(soajs, function (err) {
                if (err) {
                    return cb(err);
                }
                utilities.saveUser(soajs, driver.model, 'openam', {
                    userRecord: userRecord,
                    attributesMap: openamAttributesMap
                }, function (error, record) {
                    return cb(null, record);
                });
            });
        });
    }
function ( soajs , data , cb ) { let token = data . token ; let openam ; if ( soajs . servicesConfig . urac && soajs . servicesConfig . urac . openam ) { openam = soajs . servicesConfig . urac . openam ; } else { return cb ( { "code" : 712 , "msg" : soajs . config . errors [ 712 ] } ) ; } let openamAttributesURL = openam . attributesURL ; let openamAttributesMap = openam . attributesMap ; let openamTimeout = openam . timeout || 10000 ; request . post ( openamAttributesURL , { form : { subjectid : token } , timeout : openamTimeout } , function ( error , response , body ) { let userRecord ; if ( error ) { soajs . log . error ( error ) ; return cb ( { "code" : 710 , "msg" : soajs . config . errors [ 710 ] } ) ; } if ( ! response || response . statusCode !== 200 ) { soajs . log . error ( "OpenAM token invalid!" ) ; return cb ( { "code" : 711 , "msg" : soajs . config . errors [ 711 ] } ) ; } try { userRecord = JSON . parse ( body ) ; } catch ( err ) { soajs . log . error ( "OpenAM response invalid!" ) ; return cb ( { "code" : 712 , "msg" : soajs . config . errors [ 712 ] } ) ; } soajs . log . debug ( 'Authenticated!' ) ; initBLModel ( soajs , function ( err ) { if ( err ) { return cb ( err ) ; } utilities . saveUser ( soajs , driver . model , 'openam' , { userRecord : userRecord , attributesMap : openamAttributesMap } , function ( error , record ) { return cb ( null , record ) ; } ) ; } ) ; } ) ; }
Login through OpenAM

Expects to have openam configuration object under soajs.servicesConfig.urac.

Example openam configuration object:
{
attributesURL: "https://test.com/openam/identity/json/attributes",
attributesMap: [
{ field: 'sAMAccountName', mapTo: 'id' },
{ field: 'sAMAccountName', mapTo: 'username' },
{ field: 'mail', mapTo: 'email' },
{ field: 'givenname', mapTo: 'firstName' },
{ field: 'sn', mapTo: 'lastName' }
],
timeout: 5000
}
Login through OpenAM