在Node.js中实现Passport-SAML策略

6

我正在使用passport-saml进行身份验证。为此,我已经安装了

npm install passport passport-saml --save

我使用这篇博客Auth0创建了我的IDP。

初始化了passport并定义了SAML策略。

app.use(passport.initialize());

passport.use(new passportSaml.Strategy(
        {
            path: "/login/callback",
            entryPoint: "https://qpp1.auth0.com/samlp/bZVOM5KQmhyir5xEYhLHGRAQglks2AIp",
            issuer: "passport-saml",
            // Identity Provider's public key
            cert: fs.readFileSync("./src/cert/idp_cert.pem", "utf8"),
        },
        (profile, done) => {
            console.log("Profile : ",profile);
            let user = new Profile({ id: profile["nameID"], userName: profile["http://schemas.auth0.com/nickname"] });
            return done(null, user);
        }
    ));

这里是路由信息。
app.get("/login",
    passport.authenticate("saml", (err, profile) => {
        // control will not come here ????   
        console.log("Profile : ", profile);
    })
);
app.post("/login/callback",
         (req, res, next) => {
            passport.authenticate("saml", { session: false }, (err, user) => {
                req.user = user;
                next();
            })(req, res, next);
         },
         RouteHandler.sendResponse
);

现在这个工作良好,但我有一些问题:
1) 在SAML策略中,“发布者”是什么意思?
2) 为什么我需要在两个URL映射中使用passport.authenticate。我不明白为什么需要在/login/callback请求中使用它。即使控件也不会进入我已经传递给passport.authenticate方法的/login请求函数中?
这背后的逻辑是什么?在任何场景下都有用吗?
1个回答

8
我们正在完成一个多租户passport-saml实现。通过我们的研究、测试和开发周期,我们发现以下内容:
  1. “issuer”似乎映射到SAML请求/响应断言中的EntityID。
  2. 在GET /login上进行身份验证可以让您具备SP启动流程的能力。将向IdP发送AuthNRequest。用户将进行身份验证(或已经进行身份验证),然后IdP将回调到断言使用者服务端点。在您的情况下,POST /login/callback authenticate。POST /login/callback端点是IdP启动的SAML流程。
为了学习如何与我们的应用程序集成,我们从仅使用ACS回调的IdP启动流程开始。我们与第一个客户成功地集成了起来。然而,他们问的第一个问题是,我们应该使用什么URL来进行SP启动流程? :-) 我很快就能使SP启动流程工作。
我使用Salesforce开发人员和SSO Circle作为测试IdPs进行了测试。
希望这可以帮助到您。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接