nodejs中的passport-saml策略实现

Sun*_*arg 6 authentication node.js passport.js passport-saml

passport-saml用于身份验证。为此,我已安装

npm install passport passport-saml --save
Run Code Online (Sandbox Code Playgroud)

我已经使用这个博客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);
        }
    ));
Run Code Online (Sandbox Code Playgroud)

这是路线

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
);
Run Code Online (Sandbox Code Playgroud)

现在这工作正常,但我有一些问题

1)issuersaml策略是什么意思

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

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

小智 8

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

  1. “颁发者”似乎映射到 SAML 请求/响应断言中的 EntityID。
  2. GET /login 上的身份验证为您提供了 SP 启动的流功能。AuthNRequest 将被发送到 IdP。用户将进行身份验证(或已通过身份验证),然后 IdP 将回调到断言消费者服务端点。在您的情况下 POST /login/callback 进行身份验证。POST /login/callback 端点是 IdP 启动的 SAML 流。

为了了解如何与我们的应用程序集成,我们从 IdP 启动的流与 ACS 回调开始。我们整合的第一个客户是成功的。然而,他们问的第一个问题是,我们应该为 SP 启动的流使用什么 URL?:-) 我很快就能让 SP 启动的流程工作起来。

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

希望这可以帮助。