护照 + 带有 metadata.xml 文件的 SAML
Passport + SAML with metadata.xml file
我正在使用 express 和 ejs 设置 Web 应用程序,需要集成 SAML 身份验证。我有一个 metadata.xml、一个 public 证书和一个私钥。
现在我想设置这个策略并将其用于身份验证。
我尝试使用一个名为 passport-saml-metadata 的模块,但每当我尝试对其进行身份验证时,它都会显示:错误:未知身份验证策略 "saml"
尽管它是在与其他有效策略相同的文件中定义和导出的。
首先我尝试使用 passport-saml 模块手动配置 SAML,但后来我注意到它们是一个 passport-saml-metadata 可以处理我的元数据文件并建立策略,所以我决定使用它一。我现在有一个 'valid' (它在执行时不会在任何时候抱怨),但是当我调用路由时找不到策略。同一文件中的其他策略可以轻松识别并正常工作。
护照配置:
// 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);
来电app.js
// Login Oauth
router.get('/okta', passport.authenticate('oauth2'));
// Login SAML
router.get('/saml', passport.authenticate('saml'));
我希望该策略像 oauth2 一样被 passport 识别,它与 saml 在同一文件中定义。因为两个文件都被导出并且在执行过程中没有显示错误(除了找不到策略),我希望至少它会调用 auth 并且我可以发现任何错误。
只需设置
passport.use(samlStrategy);
到
passport.use('saml',samlStrategy);
因为否则它不会识别该策略...
抱歉提问
我正在使用 express 和 ejs 设置 Web 应用程序,需要集成 SAML 身份验证。我有一个 metadata.xml、一个 public 证书和一个私钥。 现在我想设置这个策略并将其用于身份验证。 我尝试使用一个名为 passport-saml-metadata 的模块,但每当我尝试对其进行身份验证时,它都会显示:错误:未知身份验证策略 "saml" 尽管它是在与其他有效策略相同的文件中定义和导出的。
首先我尝试使用 passport-saml 模块手动配置 SAML,但后来我注意到它们是一个 passport-saml-metadata 可以处理我的元数据文件并建立策略,所以我决定使用它一。我现在有一个 'valid' (它在执行时不会在任何时候抱怨),但是当我调用路由时找不到策略。同一文件中的其他策略可以轻松识别并正常工作。
护照配置:
// 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);
来电app.js
// Login Oauth
router.get('/okta', passport.authenticate('oauth2'));
// Login SAML
router.get('/saml', passport.authenticate('saml'));
我希望该策略像 oauth2 一样被 passport 识别,它与 saml 在同一文件中定义。因为两个文件都被导出并且在执行过程中没有显示错误(除了找不到策略),我希望至少它会调用 auth 并且我可以发现任何错误。
只需设置
passport.use(samlStrategy);
到
passport.use('saml',samlStrategy);
因为否则它不会识别该策略...
抱歉提问