【发布时间】:2019-10-11 13:50:21
【问题描述】:
在尝试实施与护照相同的身份验证方法时,我遇到了障碍。没有调用传递给passport.authenticated 函数的回调函数。
router.post("/saml/callback",
function (req, res, next) {
req.body.SAMLResponse = req.body.SAMLResponse.replace(/[\n\r]/g, "");
next();
},
function (req, res, next) {
console.log("Calling passport handler");
console.log(req.body);
try {
const response = passport.authenticate("saml",
{
failureRedirect: "/saml/error",
failureFlash: true
}, (error, user, info) => {
console.log(error, user, info);
next();
})(req, res, next);
console.log(response);
} catch(e) {
console.log(e);
}
console.log("Line after passport handler");
},
function (req, res) {
res.redirect("/saml/success");
}
);
我的 express 应用程序在输入此方法时挂起,但仅使用 1 个特定的 saml 提供程序(使用 https://samltest.id 作为测试提供程序确实可以使用完全相同的代码)。此身份验证方法似乎发生错误,但我无法找到此错误。
我如何在这个回调中得到错误。
日志输出:
调用护照处理程序
{SAMLResponse: 'base64encoded saml response'}
未定义
护照处理程序后的线路
错误:连接 ETIMEDOUT ip:443
【问题讨论】:
-
您不需要将
error或user传递给next()吗?见passportjs.org/docs/authenticate/#custom-callback -
@laggingreflex 没有任何区别,因为上面的行甚至没有被调用。
标签: node.js passport.js passport-saml