node.jssingle-sign-onpassport.jssamlpassport-saml

How to use dynamic passport SAML stratagey?


I am trying to implement SAML for google and okta for the different enterprises. Now, I have multiple entry points for that.

 passport.use(
    "saml",
    new SamlStrategy(
        {
            protocol: "https://",
            entryPoint: "entry url", // SSO URL (Step 2)
            issuer: "issuer link", // Entity ID (Step 4)
            path: "ACS URL parth", // ACS URL path (Step 4)
        },
        async function (profile, done) {
             {function body}
        }
    )
);

now, how can I set issuer URL dynamic every time as per user?


Solution

  • As you mentioned that you want you pass dynamic entry point or can say multiple. you can achieve by Configure strategy for multiple providers in passport-sml , there is one function called getSamlOptions here you can write your code to fetch dynamic data from database

    Ex:

    passport.use("dynmaic-sml", new MultiSamlStrategy(
        {
            passReqToCallback: true, // makes req available in callback
            getSamlOptions: async function (request, done) {
    
                // get sso config from db and pass 
    
                return done(null, config);
                
            }
        },
        function (req, profile, done) {
            // logic after response
        })
    );