mirror of
https://github.com/hanzoai/passport-saml.git
synced 2026-09-24 17:01:45 +00:00
86f45b9d60c07fa6c25505e610dd0e22485a16e7
Passport-SAML
This is a SAML 2.0 authentication provider for Passport, the Node.js authentication library.
The code is based on Michael Bosworth's express-saml library.
Installation
$ npm install passport-saml
Usage
Configure strategy
This example utilizes the Feide OpenIdp identity provider. You need an account there to log in with this. You also need to register your site as a service provider.
The SAML identity provider will redirect you to the URL provided by the path configuration.
passport.use(new SamlStrategy(
{
path: '/login/callback',
entryPoint: 'https://openidp.feide.no/simplesaml/saml2/idp/SSOService.php',
issuer: 'passport-saml'
},
function(profile, done) {
findByEmail(profile.email, function(err, user) {
if (err) {
return done(err);
}
return done(null, user);
});
})
));
Provide the authentication callback
You need to provide a route corresponding to the path configuration parameter given to the strategy:
app.post('/login/callback',
passport.authenticate('saml', { failureRedirect: '/', failureFlash: true }),
function(req, res) {
res.redirect('/');
}
);
Authenticate requests
Use passport.authenticate(), specifying saml as the strategy:
app.get('/login',
passport.authenticate('saml', { failureRedirect: '/', failureFlash: true }),
function(req, res) {
res.redirect('/');
}
);
Languages
TypeScript
96.1%
JavaScript
3.9%