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 js.
For more information on PCF SSO visit: PCF Single Sign-On Overview
'use strict';
const Port = process.env.PORT || 8080;
const AUTH_CONDITION = process.env.ENABLE_AUTH || false;
const express = require('express');
const session = require('express-session');
const PcfSSOExpressMw = require('pcf-sso-express-middleware');
const app = express();
// See Note #1
app.use(
session({
name: 'server-session',
secret: 'genericSecret', // See Note #2
saveUninitialized: true,
resave: true
})
);
const auth = new PcfSSOExpressMw(app);
auth.initialize(AUTH_CONDITION);
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:
- Use an external store once in production, something like Express-Sessions
- Use a secret provided via environment variables once in procudtion