pcf-express-sso
TypeScript icon, indicating that this package has built-in type declarations

0.1.7 • Public • Published

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:

Package Sidebar

Install

npm i pcf-express-sso

Weekly Downloads

1

Version

0.1.7

License

MIT

Unpacked Size

97.5 kB

Total Files

14

Last publish

Collaborators

  • haplesshero13
  • ochong
  • stevensouto