I am using Node Express to build my backend server. Additionally, authentication is my application happens with Passport-SAML. I am using JWT to maintain user sessions. So the flow is,
The callback POST endpoint also has a page redirect. And from so far what I have learned is res.status and res.redirect cannot be in the same endpoint for obvious reasons. I have been trying to find the right approach it, any help is greatly appreciated.
router.route('/login')
.get(
passport.authenticate(config.passport.strategy,
{
successRedirect: '/',
failureRedirect: '/login'
})
);
router.route(config.passport.saml.path)
.post(
passport.authenticate(config.passport.strategy,
{
failureRedirect: '/',
failureFlash: true
}),
function (req, res) {
res.redirect('/');
var token = Verify.getToken(req.user.saml);
return res.status(200).json({
status: 'Login successful!',
success: true,
token: token
});
console.log(token,'yes');
}
);
You've got an array of options here
Cookie
res.cookie('token', token, ...);
res.redirect(...);
URL parameter
res.redirect(`/some/url?token=${token}`);
Custom header
res.set('x-token', token);
res.redirect(...);