Tim*_*imo 7 saml node.js passport.js passport-saml
我正在使用 express 和 ejs 设置 Web 应用程序,并且需要集成 SAML 身份验证。我有一个 metadata.xml、一个公共证书和一个私钥。现在我想设置此策略并将其用于身份验证。我尝试使用一个名为passport-saml-metadata的模块,但是每当我尝试对其进行身份验证时,它都会说:错误:未知的身份验证策略“saml”,尽管它与其他有效的策略在同一文件中定义和导出。
首先我尝试使用passport-saml模块手动配置SAML,但后来我注意到它们是一个passport-saml-metadata,它可以处理我的元数据文件并建立策略,所以我决定使用这个。我现在有一个“有效”(它在执行中的任何时候都不会抱怨),但是当我调用路由时没有找到策略。同一文件中的其他策略被识别并且可以轻松工作。
护照配置:
// Read the metadata
const reader = new MetadataReader(
fs.readFileSync(path.join(__dirname, './metadata.xml'), 'utf8')
);
const ipConfig = toPassportConfig(reader);
const spPublicCertificate = path.join(__dirname, './server.crt');
const spPrivateKey = path.join(__dirname, './private_key.pem');
const spConfig = {
callbackUrl: `http://localhost:3300/auth/saml/sso/callback`,
logoutCallbackUrl: `http://localhost:3300/auth/saml/slo/callback`,
issuer: '/shibboleth',
privateCert: spPrivateKey
};
const strategyConfig = {
...ipConfig,
...spConfig,
validateInResponseTo: false,
disableRequestedAuthnContext: true,
};
const verifyProfile = (profile, done) => {
return done(null, { ...profile, test: 'xxx' });
};
const samlStrategy = new saml.Strategy(strategyConfig, verifyProfile);
passport.use(samlStrategy);
Run Code Online (Sandbox Code Playgroud)
在 app.js 中调用
// Login Oauth
router.get('/okta', passport.authenticate('oauth2'));
// Login SAML
router.get('/saml', passport.authenticate('saml'));
Run Code Online (Sandbox Code Playgroud)
我希望该策略能够被像 oauth2 这样的通行证识别,它与 saml 定义在同一个文件中。因为两个文件都被导出并且在执行过程中没有显示错误(除了找不到策略之外),我希望至少它会调用 auth 并且我可以发现任何错误。
只需要设置
passport.use(samlStrategy);
为
passport.use('saml',samlStrategy);
因为否则它不会识别该策略......
抱歉问了
| 归档时间: |
|
| 查看次数: |
1848 次 |
| 最近记录: |