我是逆向工程一个SAML的implementations基于单点登录(SSO)试图了解开源的节点回调语法
当SSO成功我从我的IDP(身份提供者)一个POST和以下函数被调用:
router.post('/acs/:idp?', function (req, res, next) {
console.log('got a post from idp');
var _idp, _sp;
if (req.params.idp === 'onelogin') {
console.log('the idp is onelogin or vidm in this case');
_idp = oneLoginIdP;
_sp = olsp;
} else {
_idp = idp;
_sp = sp;
}
_sp.parseLoginResponse(_idp, 'post', req, function (parseResult) {
console.log('trying to parse assertion to see if it is valid');
console.log('name id'+parseResult.extract.nameid);
if (parseResult.extract.nameid) {
res.render('login', {
title: 'Processing',
isSSOLogin: true,
email: parseResult.extract.nameid
});
} else {
req.flash('info', 'Unexpected error');
res.redirect('/login');
}
});
});
现在,我们可以看到这个函数调用的serverivceprovider对象(_SP)对称为parseLoginResponse功能。 parseLoginResponse看起来像以下:
ServiceProvider.prototype.parseLoginResponse = function parseLoginResponse(idp, binding, req, parseCallback) {
return this.abstractBindingParser({
parserFormat:
[
{
localName: 'StatusCode',
attributes: ['Value']
},
{
localName: 'Conditions',
attributes: ['NotBefore', 'NotOnOrAfter']
},
'Audience',
'Issuer',
'NameID',
{
localName: 'Signature',
extractEntireBody: true
},
{
localName: {
tag: 'Attribute',
key: 'Name'
},
valueTag: 'AttributeValue'
}
],
checkSignature: this.entityMeta.isWantAssertionsSigned(),
from: idp,
supportBindings: ['post'],
parserType: 'SAMLResponse',
actionType: 'login'
}, binding, req, idp.entityMeta, parseCallback);
};
我的三个具体问题:
How is the callback working for parseCallback method.
I am new to javascript so I don't get at which exact line parseCallback is receiving it's argument i.e parseResult?
我可以打印我的parseCallback succefully以下行:
console.log('name id'+parseResult.extract.nameid);
但我无法找到一种方法来打印包含notbefore和notonora后的属性。 How can I print attributes section of parseResult or the commplete parseResult argument?
谢谢!的console.log(参数);是我所需要的。 – nitinsh99