5.0.1 • Published 3 years ago

ldapsso v5.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

LDAP Gameloft

This library use for authentication user base on Gameloft ldap

Install

npm install git+https://ldapsso:3BcebwDp4mmeDxdh_ixD@git.gameloft.org/sai_deployment/marketing/npm/ldap.git

Uninstall

npm uninstall ldapsso

Usage

var app = express();

const bodyParser = require("body-parser");
const LdapSSO = require("ldapsso");
const session = require("express-session");
const MySQLStore = require("express-mysql-session")(session);

// session setup
const options = {
  // Host name for database connection:
  host: `${host}`,
  // Port number for database connection:
  port: 3306,
  // Database user:
  user: `${user}`,
  // Password for the above database user:
  password: `${password}`,
  // Database name:
  database: `${database}`,
  // Whether or not to automatically check for and clear expired sessions:
  clearExpired: true,
  // How frequently expired sessions will be cleared; milliseconds:
  checkExpirationInterval: 900000,
  // The maximum age of a valid session; milliseconds:
  expiration: 86400000,
  // Whether or not to create the sessions database table, if one does not already exist:
  createDatabaseTable: true,
  // Number of connections when creating a connection pool:
  connectionLimit: 1,
  // Whether or not to end the database connection when the store is closed.
  // The default value of this option depends on whether or not a connection was passed to the constructor.
  // If a connection object is passed to the constructor, the default value for this option is false.
  endConnectionOnClose: true,
  charset: `${charset}`,
  schema: {
    tableName: "sessions",
    columnNames: {
      session_id: "session_id",
      expires: "expires",
      data: "data",
    },
  },
};
const sessionStore = new MySQLStore(options);
app.set("trust proxy", 1); // trust first proxy
const sess = {
  secret: `gangstarvegasbe-${environment}`,
  resave: false,
  saveUninitialized: false,
  store: sessionStore,
  cookie: {
    maxAge: 3600000 * 24 * 7 * 52,
    secure: "auto", // serve secure cookies
  },
};
app.use(session(sess));

// body parser setup
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

// sso setup
app.post("/authorize", LdapSSO.authorize);
app.post("/protectedEndPoint", LdapSSO.verify, (req, res, next) => {
  res.send("Successful Protected EndPoint Data Call");
});

// auth setup
LdapSSO.loginRouter = "/api/login";
app.get("/api/login", (req, res, next) => {
  if (LdapSSO.isLoggedIn(res)) {
    res.send("Logged in");
  } else {
    const loginMessage = LdapSSO.sessionSharing(res, "loginMessage") || "";
    LdapSSO.deleteSessionSharing(res, "loginMessage");
    res.render("login", { message: loginMessage });
  }
});
app.post("/api/login", LdapSSO.login);
app.get("/api/logout", LdapSSO.logout);
app.get("/ensureLoggedInEndPoint", LdapSSO.ensureLoggedIn, (req, res, next) => {
  res.send("Wellcome");
});