试图了解Node JS的路由代码

我想了解一个开放源代码实现来实现基于SAML的SSO,并且我无法理解这个类中的以下快速路由器方法:

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时,我发现它是错误的,但是当我从我的idp(身份提供者)得到一个redirect时,这个标志是真实的,我将进入if条件。

这个方法确实来自护照authentication系统,

你可以在这里检查函数本身:

 /** * 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; };