我试图理解one实现基于 SAML 的 SSO 的开源实现,我无法理解 this 中的以下快速路由器方法类:
router.get('/', function(req, res, next) {
console.log(arguments);
if(req.isAuthenticated()){
res.render('index', {
title: 'sp1 - My Application',
user: req.user
});
}else{
console.log('not authentcated sending to authenticate');
res.redirect('/login');
}
});
我的问题是:
where exactly the code is setting `isAuthenticated` flag to true or false?
当我第一次启动/login 时,我发现它是 false,但是当我从 idp(身份提供商)获得重定向时,此标志为 true,并且我将进入 if 条件。
最佳答案
这个方法确实来自passport认证系统,
您可以检查函数本身 here :
/**
* Test if request is authenticated.
*
* @return {Boolean}
* @api public
*/
req.isAuthenticated = function() {
var property = 'user';
if (this._passport && this._passport.instance._userProperty) {
property = this._passport.instance._userProperty;
}
return (this[property]) ? true : false;
};
关于node.js - 尝试理解 Node JS 路由代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43310427/