nodejs中的passport-saml策略实现

时间:2017-12-08 09:42:35

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

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

npm install passport passport-saml --save

我已使用此博客Auth0创建了我的IDP。

初始化护照和定义的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)issuer在saml策略中的含义

2)为什么我需要在两个URL映射中使用passport.authenticate。我不明白为什么在/login/callback请求中需要它。甚至控制也不会来/login请求我在passport.authenticate方法中传递的函数?

这背后的逻辑是什么?这在任何情况下都有用吗?

1 个答案:

答案 0 :(得分:3)

我们正在完成多租户的护照saml实施。通过我们的研究,测试和开发周期,我们发现了以下内容:

  1. “发出者”似乎映射到SAML中的EntityID 请求/响应断言。
  2. GET / login上的身份验证为您提供了SP启动的流程 能力。 AuthNRequest将被发送到IdP。用户将 认证(或已经认证),IdP将 回调到断言使用者服务端点。在 您的案例POST / login / callback进行身份验证。开机自检 / login / callback端点是由IdP启动的SAML流。

要了解如何与我们的应用程序集成,我们首先使用IdP启动的ACS回调流程。我们与之整合的第一个客户取得了成功。但是,他们提出的第一个问题是,对于SP发起的流程,我们应该使用哪个URL? :-)之后,我能够使SP启动的流程正常工作。

我已经使用Salesforce开发人员和SSO Circle作为测试IDP对其进行了测试。

希望这会有所帮助。

相关问题