我正在使用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请求函数中?
这背后的逻辑是什么?在任何场景下都有用吗?