【问题标题】:Passport callback not being called未调用护照回调
【发布时间】: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

【问题讨论】:

标签: node.js passport.js passport-saml


【解决方案1】:

问题根本不在于这段代码,而在于 saml 提供程序的启动。

我在Strategy({cert: function(callback)....}); 中有一个回调函数,它试图获取 saml 响应的签名证书。但是,由于 IDP 是测试服务器,因此无法从我的 SP 访问 IDP,因此从未调用过回调。

TL;DR;如果您在Strategy 定义中使用cert 键;并且所述键使用回调,检查是否调用了该回调!

【讨论】:

    猜你喜欢
    • 2020-09-21
    • 2016-12-14
    • 1970-01-01
    • 2017-10-05
    • 2018-03-15
    • 1970-01-01
    • 2018-11-06
    • 1970-01-01
    • 2015-12-13
    相关资源
    最近更新 更多