OpenPass passport.js quickstart guide

This guide explains how to configure OpenPass as an authentication provider using the Passport.js SDK, known as a strategy, with Open ID connect.

This module simplifies integrating OpenID Connect authentication with your Node.js application that uses OpenPass. Follow these steps to use this option:

  1. Install the OpenPass strategy.
  2. Register your application with OpenPass.
  3. Configure the OpenPass strategy.
  4. Define login routes.

Install OpenPass strategy

Install the OpenPass strategy using a node package manager (NPM) by running the following command in your application.

$ npm install @openpass/passport-openpass

Register your application

To authenticate users in your application using OpenPass, first register your application with OpenPass. Then after registration, you will receive a client ID and secret. These credentials help OpenPass identify your app.

Configure the strategy

To authenticate users, implement a verification callback that receives user credentials and returns a user profile that can include the client ID, client secret, and callback URL.

var OpenPassStrategy = require('passport-openpass');

passport.use(new OpenPassStrategy({
    clientID: process.env['OPENPASS_CLIENT_ID'],
    clientSecret: process.env['OPENPASS_CLIENT_SECRET'],
    callbackURL: 'https://www.example.com/oauth2/redirect/openpass'
  },
  function verify(iss, profile, context, idToken, accessToken, refreshToken, done) {
    console.log(profile.id); 
    });
  }
));

Define routes

To enable users to log into their OpenPass accounts, configure two routes. The first route directs the user to OpenPass for authentication. Here's an example of the first route.

app.get('/login/openpass', passport.authenticate('openpass'));

The second route processes the authentication response and logs the user in after OpenPass redirects them to the app. Here's an example of the second route.

app.get('/callback',
  passport.authenticate('openpass', { failureRedirect: '/login', failureMessage: true }),
  function(req, res) {
    res.redirect('/');
  });

Handling the authentication response completes the installation process. To verify the OpenPass ID token, see Verify the ID token.

For an example of an OpenPass application using Passport.js, see the login example in GitHub.

Additional resources

For more information, see the following pages: