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 🙏

© 2024 – Pkg Stats / Ryan Hefner

okta-auth

v0.1.4

Published

Okta Authentication for ExpressJS (NodeJS)

Downloads

71

Readme

Okta-auth

Okta Authentication for ExpressJS (NodeJS).

Example

Example application

You can find the example application in the GitHub repository: wojtekk/okta-test-auth

Simple usage

Install packages:

npm install cookie-parser --save
npm install body-parser --save
npm install okta-auth --save
npm install express-session --save
// if you want to keep sessions in Redis:
npm install redis --save
npm install connect-redis --save
npm install session-file-store --save-dev

Configure an app:

const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const oktaAuth = require('okta-auth');

const session = require('express-session');

// ===== BEGIN: if you want to keep sessions in Redis:
const redis = require('redis');
const RedisStore = require('connect-redis')(session);
// ===== END: if you want to keep sessions in Redis.


app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: false }));

var sessionOptions = {
  secret: process.env.SESSION_SECRET,
  resave: true,
  cookie: { maxAge: 1*process.env.SESSION_MAX_AGE},
  rolling: true,
  name: 'my-app-name'
};

// ===== BEGIN: if you want to keep sessions in Redis:
// Use Redis store only on production and stage env
if (process.env.REDIS_URL) {
  const redisClient = redis.createClient({url: process.env.REDIS_URL});
  sessionOptions.store = new RedisStore({
    client: redisClient,
    ttl: sessionOptions.cookie.maxAge
  });
} else { // Use file store on local environment
  try {
    var FileStore = require('session-file-store')(session);
    sessionOptions.store = new FileStore({
      path: '/tmp/sessions',
      ttl: sessionOptions.cookie.maxAge
    });
  } catch (e) {
    console.error(e);
  }
}
// ===== END: if you want to keep sessions in Redis.

app.use(session(sessionOptions));

oktaAuth.initialize(app, {
  oktaIssuer: process.env.OKTA_ISSUER,          // required
  oktaEntryPoint: process.env.OKTA_ENTRY_POINT, // required
  oktaCert: process.env.OKTA_CERT               // required
});

app.get('/my-secured-url', oktaAuth.secured, (req, res) => {
  res.render('index');
});

You can create own page for not logged users:

// ...

oktaAuth.initialize(app, {
  // ...
  accessDeniedUrl: accessDeniedUrl, // default: /access-denied
  defaultAccessDeniedPage: false    // default: true
});

app.get(accessDeniedUrl, (req, res) => {
  res.render('access-denied');
});

// ...

You can configure Okta to pass some information about users. You have access to it in req.session.passport.user

// ...

oktaAuth.initialize(app, {
    // ...
    oktaFields: ['email', 'position', 'department']; // default: ['email', 'firstName', 'lastName']
));

app.get('/my-secured-url', oktaAuth.secured, (req, res) => {
  res.render('index', {user: req.session.passport.user});
});

// ...