I am trying to understand one of the open source implementations to achieve SAML based SSO and I am having trouble understanding the following express router method from this class:
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');
}
});
My question is :
where exactly the code is setting `isAuthenticated` flag to true or false?
When I launched /login for the first time, I see it being false but again when I get a redirect from my idp (identity provider) this flag is true and I am going inside the if condition.
This method does come from passport authentication system,
you can check the function itself 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;
};