0.1.8 • Published 5 years ago

express-sso-experimental v0.1.8

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

pcf-express-sso

A fork and straight port to TypeScript of pcf-sso-express-middleware.

The purpose of this module is to wrap the process of interfacing with the Single Sign-On service provided for Pivotal Cloud Foundry into a middleware for express.

For more information on PCF SSO visit: PCF Single Sign-On Overview

Basic Usage Example:

Install with NPM or Yarn: yarn add pcf-express-sso. If you are using TypeScript you will also need to add @types/express and @types/simple-oauth2.

import * as express from "express"
import * as session from "express-session"
import SSOClient from "pcf-express-sso"

const PORT = process.env.PORT || 8080
const AUTH_CONDITION = process.env.ENABLE_AUTH || false
const app = express()

app.use(
  session({
    name: "server-session",
    resave: true,
    saveUninitialized: true,
    secret: "genericSecret",
  }),
)

const ENABLE_AUTH = app.get("env") === "production"
const auth = new SSOClient(app)
auth.initialize(ENABLE_AUTH)

app.use(/\/(?!callback).*/, (req, res, next) => {
  auth.middleware(req, res, next)
})

app.get("/*", (req, res) => {
  res.send("Hello World!")
})

app.listen(PORT, () => {
  console.log(`Express server started on port ${PORT}`)
})

Notes:

  1. Use an external store once in production, like Redis.
  2. Use a secret provided via environment variables once in production

Testing:

Run yarn test.

TODO:

Backfill tests for SSOClient#initialize, etc.

Module Dependencies:

Prerequisites: