Passport strategy for authenticating with opinsys
This module lets you authenticate using opinsys SSO in your Node.js applications. By plugging into Passport, opinsys authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.
$ npm install passport-opinsys
The opinsys authentication strategy authenticates users using the opinsys SSO. The strategy requires a verify
callback, which accepts the user json (more info on opinsys API documentation) and calls done
providing a user.
passport.use(new OpinsysStrategy (
{
redirectURI: "http://localhost",
secret: "Opinsys JWT Secret Here!",
organization: "demo.opinsys.fi"
},
function(profile, done) {
if(profile.username !== "opiskelija.ritta") {
// User does not exists or other error
// done(error, user)
done("No user found", false)
} else {
// User exists.
done(null, {username: profile.username,id: profile.id})
}
}
));
Use passport.authenticate()
, specifying the 'opinsys'
strategy, to
authenticate requests.
For example, as route middleware in an Express application:
app.post('/login',
passport.authenticate('opinsys', { failureRedirect: '/login' }),
function(req, res) {
res.redirect('/');
});
Copyright (c) 2021-2021 Roni Äikäs <http://raikas.xyz/>