Answer the question
In order to leave comments, you need to log in
Passport SAML. How to skip getSamlOptions call after successful authentication?
I'm trying to screw SSO into my project. There is a federation that provides me with a list of IdPs through which I can authenticate. I use passport-saml for authentication .
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',
'SAML AUTH',
`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',
'SAML AUTH',
`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
);
};
GET /auth/saml/callback
entityID is undefined
. Please help with advice on how to bypass the getSamlOptions call after IdP authentication or how can I get the entityID in the callback.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question