shu*_*ria 2 node.js express jwt passport.js json-web-token
我正在使用Node Express构建后端服务器。另外,身份验证是我的应用程序使用Passport-SAML进行的操作。我正在使用JWT维护用户会话。所以流程是
回调POST端点也具有页面重定向。到目前为止,由于明显的原因,我知道的是res.status和res.redirect不能在同一端点中。我一直在尝试找到正确的方法,非常感谢您的帮助。
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');
}
);
Run Code Online (Sandbox Code Playgroud)
您这里有很多选择
曲奇饼
res.cookie('token', token, ...);
res.redirect(...);
Run Code Online (Sandbox Code Playgroud)
URL参数
res.redirect(`/some/url?token=${token}`);
Run Code Online (Sandbox Code Playgroud)
自定义标题
res.set('x-token', token);
res.redirect(...);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3416 次 |
| 最近记录: |