【问题标题】:Passport + SAML with metadata.xml file带有 metadata.xml 文件的 Passport + SAML
【发布时间】:2019-10-22 19:09:34
【问题描述】:

我正在使用 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);

在 app.js 中调用

// Login Oauth
router.get('/okta', passport.authenticate('oauth2'));

// Login SAML
router.get('/saml', passport.authenticate('saml'));

我希望该策略能被 oauth2 之类的护照识别,它与 saml 在同一个文件中定义。因为这两个文件都被导出并且在执行过程中没有显示错误(除了找不到策略),我希望至少它会调用 auth 并且我可以发现任何错误。

【问题讨论】:

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


    【解决方案1】:

    只需设置 passport.use(samlStrategy);passport.use('saml',samlStrategy);

    因为否则它不会识别策略...

    不好意思问了

    【讨论】:

    • 无需为跟进解决方案而道歉和竖起大拇指!
    • 我是这个领域的新手,你有一个完整的示例应用程序,或者你是否可以在删除任何机密信息后分享一些东西......我的意思是我不明白你有什么在上面的代码中指定“...”
    猜你喜欢
    • 1970-01-01
    • 2014-08-23
    • 2019-09-09
    • 1970-01-01
    • 2013-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-08
    相关资源
    最近更新 更多