npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

express-okta-saml

v1.0.6

Published

Okta Authentication via SAML for ExpressJS (NodeJS)

Readme

express-okta-saml

express-okta-saml is node.js library which creates routes for okta-saml authentication. It is very minimal and clean, using passport-saml and passport libraries to handle the process, gives you all access to passport-saml and passport configs/options.

Why another one?

There is a few other, not maintained libraries that provides middleware for OKTA authentication but all of them introduces configuration abstraction without leaving a way to pass configs/options directly for passport and passport-saml libraries. I simply needed full flexibility of passport-saml and passport-saml to be accessible .

How to use it?

Simple app setup example

const http = require('http');
const session = require('express-session');
const oktaAuth = require('okta-auth');
const expressOktaSaml = require('express-okta-saml');

const hour = 3600000;
const app = express();
app.use(cookieParser());
app.use(session({
  secret:  'my-secret',
  cookie: { maxAge:  hour  *  24 },
  resave:  true,
  saveUninitialized:  true,
  name:  'my-app',
}));

app.use(bodyParser.json()); // important to have bodyParser as OKTA will make POST redirect with body data
app.use(bodyParser.urlencoded({ extended:  false }));
app.get('/ping', (req, res) => { // unprotected healthcheck
  res.statusCode  =  200;
  res.send('pong');
});

const expressOktaSamlConfig = require('./oktaConfig.js'); // check bellow for config exmaple and tips
const okta = expressOktaSaml(app, expressOktaSamlConfig); // setups okta routes + passport
app.use('/', okta.secured); // from here all following requests will be checked for auth
app.get('/test', () => { res.send(''); }); // this will be not reachable if user is not logged in via OKTA

const server = http.createServer(app);
server.listen(3000, (err) => {
  if (err) {
    console.log('Failed to start server');
    console.log(err);
  }
  console.log(`Server has started on port: ${server.address().port}`);
});

oktaConfig.js example

const fs = require('fs');
const path = require('path');

const cert = fs.readFileSync(path.join(__dirname, 'okta.pem'), 'utf8');

module.exports = {
  SAML: {
    passportOptions: { // check full list of available options - https://github.com/bergie/passport-saml
      cert,
      issuer:  'http://www.okta.com/id-from-okta-saml-setup', // your okta issuer url (provided by okta duerning SAML setup)
      entryPoint:  'https://...../sso/saml', // entryPoint url (provided by okta duerning SAML setup)
      callbackUrl:  'http://localhost:3000/login', // your callback url 
    },
    propertiesToExtract: ['Email', 'FirstName', 'LastName'], // these properties will be saved on user session by passport access it by req.user
  },

  passport: {
    options: { //options to be passed to passport.authenticate(). check full list of available options - https://github.com/jaredhanson/passport/blob/master/lib/middleware/authenticate.js
      successRedirect:  '/',
      failureRedirect:  '/login',
      failureFlash:  true,
    },
  },

  appRoutes: { // express-okta-saml will create GET/POST routes on these endpoints to handle auth proccess
    loginPath:  '/login', // make sure this is same as path on SAML.passportOptions.callbackUrl and passport.options.failureRedirect
    logoutPath:  '/logout',
    accessDeniedPath:  '/access-denied',
  },
}

Tips on OKTA

SAML.passportOptions.callbackUrl

OKTA after successful auth will redirect user to this url. It is important that callbackUrl is whitelisted in OKTA SAML setup. If passed callbackUrl URL is not whitelisted, OKTA will ignore it and redirect to the whitelisted one. Check image to see how to whitelist multiple domains/urls for okta auth.

privateCert instead of cert

You can pass private certificate to passport-saml.

Remove SAML.passportOptions.cert and add SAML.passportOptions.privateCert.

Credits

Originally Inspired by wojtekk/okta-auth