我是逆向工程一個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