护照-SAML如何避免在对外部 IdP 进行身份验证后调用 getSamlOptions?

问题描述

尝试在我的项目上设置 Passport-SAML。这是一个代码示例

export const samlFederationAuthentication = () => {
  const multiSamlStrategy: MultiSamlStrategy = new MultiSamlStrategy(
    {
      passReqToCallback: true,getSamlOptions: async (req: Express.Request,done: SamlOptionsCallback) => {
        const entityID: string = decodeURIComponent((req.query.entityID as string) || '');

        if (!entityID) {
          return done(
            CustomError(
              'Not supported','SAML AUTH',`EntityID is undefined`
            )
          );
        }

        const config = await samlFederation.getConfig(); // getting entrypoint and certificate

        if (!config[entityID]) {
          return done(
            CustomError(
              'Not supported',`EntityID is not supported by IDp`
            )
          );
        }

        return done(null,{
          ...config[entityID],callbackUrl: envConfig.samlFederation.callbackURL,issuer: envConfig.samlFederation.issuer,});
      },},async (req: Express.Request,profile,done) => {
      try {
        const profileUsername: string = samlFederation.getProfileUsername(profile || {});

        if (!profileUsername) {
          return done(
            CustomError(
              'Username and email are undefined',`Username or email should be defined in SAML profile`
            )
          );
        }

        const dbUser = await userService.getUserByUsername(profileUsername);

        if (!!dbUser) {
          return done(null,dbUser);
        }


        const createdUser: IUser = await userService.createuser(profile || {});

        return done(null,createdUser as Record<string,any>);
      } catch (err) {
        return done(err);
      }
    }
  );

  Passport.use('multi-saml',multiSamlStrategy);
};

和路线:

export const addSamlFederationRoutes = (app: Express.Application) => {
  app.get('/auth/saml',Passport.authenticate('multi-saml'));
  app.post(
    '/auth/saml/callback',Passport.authorize('multi-saml',{ failureRedirect: '/',failureFlash: true }),userHandler // some handler with user data
  );
};

现在我来描述我的问题。

  1. 用户转到联合表单并选择他们想要进行身份验证的一些特殊 IdP
  2. 联合表单使用 EntityID 向我们的服务器 GET /auth/saml 发送请求以查询外部 IdP。
  3. 我们的服务器在数据库中查找所需的配置参数并将用户重定向到 IdP 表单。

用户转到 IdP 并输入他们的凭据时,他们会使用 url auth/saml/callback 重定向到我们的服务器。这很棒,但我们将中间件 passport.authorize 称为导致调用 MultiSamlStrategy 中的函数 getSamlOptions。但是 IdP 不会在参数中向我发送 entityID,而且我的函数总是发送错误 Entity ID is undefined。所以,我的问题是如何在 IdP 上进行身份验证后避免调用 getSamlOptions

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...