1.0.0 • Published 3 years ago

passport-opinsys v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

passport-opinsys

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

$ npm install passport-opinsys

Usage

Configure Strategy

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})
        }
    }
));

Authenticate Requests

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('/');
  });

License

The MIT License

Copyright (c) 2021-2021 Roni Äikäs [http://raikas.xyz/](http://raikas.xyz/)