How to use the express-session.MemoryStore function in express-session

To help you get started, we’ve selected a few express-session examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github keycloak / keycloak-nodejs-connect / test / fixtures / node-console / index.js View on Github external
this.build = function (kcConfig, params) {
    app.set('view engine', 'html');
    app.set('views', require('path').join(__dirname, '/views'));
    app.engine('html', hogan);

    // Create a session-store to be used by both the express-session
    // middleware and the keycloak middleware.

    var memoryStore = new session.MemoryStore();

    app.use(session({
      secret: 'mySecret',
      resave: false,
      saveUninitialized: true,
      store: memoryStore
    }));

    // Provide the session store to the Keycloak so that sessions
    // can be invalidated from the Keycloak console callback.
    //
    // Additional configuration is read from keycloak.json file
    // installed from the Keycloak web console.
    params = params || { store: memoryStore };
    var keycloak = new Keycloak(params, kcConfig);
github paragi / sphp / example.js View on Github external
console.error("example.js requires modules installed. Use:"
    + "\n\n  npm install express express-session ws body-parser"
    + "\n\nError: ",err.message);
});

// Load modules
var express = require('express');
var expressSession = require('express-session');
var bodyParser = require('body-parser');
var _ws = require('ws');
var path = require('path');

process.removeAllListeners('uncaughtException');

// Initialize server
var sessionStore = new expressSession.MemoryStore();
var sphp = require('./sphp.js');
var app = express();
var server = app.listen(8080,'0.0.0.0','',function () {
  console.log('Server listening at://%s:%s'
    ,server.address().address
    ,server.address().port);
});
var ws = new _ws.Server({server: server});

// Set up session. store and name must be set, for sphp to catch it

var docRoot = module.filename.substring(0,module.filename.lastIndexOf(path.sep)) + '/example/';

var sessionOptions={
   store: sessionStore
  ,secret:'yes :c)'
github braziljs / power-polygon / run.js View on Github external
port: 8081,
    serverSecret: 'onlyMeAndGitHubUsersKnowIt! - Please,change this for your use'
}

/* DEFINITIONS */
var app = require('express')()
  , bodyParser = require('body-parser')
  , cookieParser = require('cookie-parser')
  , expressSession = require('express-session')
  , multipartParser = require('connect-multiparty')
  , compression = require('compression')
  , fs = require('fs')
  , io = null
  , _token= false
  , server = null
  , store  = new expressSession.MemoryStore
  , readline = require('readline')
  , sqlite3 = require('sqlite3').verbose()
  , db = null // ':memory:'
  , rl = readline.createInterface({
             input: process.stdin,
             output: process.stdout
         });

/* MIDLEWARES */
app.use(compression());
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(multipartParser({ uploadDir: '/ppw/tmp/' }));
app.use(expressSession({
    secret: serverConf.serverSecret,
github jstty / hyper.io / examples / api / session-custom / app.js View on Github external
}
catch (err) {}
// --!

// Load config and routes
options.session = {
  secret:            'keyboard kat',
  resave:            false,            // depends on the session store, see https://github.com/expressjs/session#resave
  saveUninitialized: false, // depends on several cases, see https://github.com/expressjs/session#saveuninitialized
  cookie:            {
        // secure: true, // enable only if https
    path:     '/',
    httpOnly: true,
    maxAge:   1000 * 60 * 24 // 24 hours
  },
  storeInst: new session.MemoryStore()
};
var hyper = new Hyper(options);

var app = hyper
    .start({
      routes: [
        {
                // http://localhost:8000/login?username=joe
          api:    '/login',
          method: {
            get: function login ($done, $session, $input) {
              $session.username = $input.query.username;
              $done({
                hello: $session.username
              });
            }
github akshaylive / live.io / index.js View on Github external
module.exports = function(options){
    var options = options || {}
        , key = options.name || options.key || 'connect.sid'
        , store = options.store || new session.MemoryStore
        , liveCookieParser = options.cookieParser || cookieParser
        , sessionSecret = options.sessionSecret || ''
        , secure = options.secure;

    var exp = express();

    // Express MongoDB session storage
    exp.use(session({
        saveUninitialized: true,
        resave: true,
        secret: sessionSecret,
        store: store
    }));

    // use passport session
    exp.use(passport.initialize());
github aerogear / datasync / packages / voyager-keycloak / src / KeycloakSecurityService.ts View on Github external
public applyAuthMiddleware (expressRouter: Router, options?: ApplyAuthMiddlewareOptions) {

    if (!this.keycloakConfig) {
      return this.log.info('Keycloak authentication is not configured')
    }

    const apiPath = options && options.apiPath ? options.apiPath : '/graphql'
    const tokenEndpoint = options && options.tokenEndpoint ? options.tokenEndpoint : false

    this.log.info('Initializing Keycloak authentication')
    const memoryStore = new session.MemoryStore()

    expressRouter.use(session({
      secret: this.keycloakConfig.secret || 'secret',
      resave: false,
      saveUninitialized: true,
      store: memoryStore
    }) as any)

    if (!this.keycloak) {
      this.keycloak = new Keycloak({
        store: memoryStore
      }, this.keycloakConfig)
    }

    // Install general keycloak middleware
    expressRouter.use(this.keycloak.middleware({
github recruit-tech / redux-pluto / bin / start-server.js View on Github external
const clientConfig = require("../src/webpack/dev.client.config");
  const serverConfig = require("../src/webpack/dev.server.config");

  const multiCompiler = webpack([clientConfig, serverConfig]);
  const clientCompiler = multiCompiler.compilers[0];
  const { output: outputPublicPath } = clientConfig;
  const { publicPath } = outputPublicPath;
  const promises = [];

  app.use(webpackDevMiddleware(multiCompiler, { publicPath }));
  app.use(webpackHotMiddleware(clientCompiler));
  app.use(
    webpackHotServerMiddleware(multiCompiler, {
      serverRendererOptions: {
        server,
        sessionStore: new MemoryStore(),
        promises,
      },
    }),
  );

  debug("Compiling webpack...");
  const intervalId = setInterval(() => {
    debug("Compiling webpack...");
  }, 3000);

  return new Promise((resolve, reject) => {
    multiCompiler.hooks.done.tap("done", multiStats => {
      debug("Done compile");
      clearInterval(intervalId);
      resolve();
    });
github zubairq / pilot / src / electron.js View on Github external
var program         = require('commander');
var bodyParser      = require('body-parser');
var multer          = require('multer');
var cors            = require('cors')
var saveHelper      = require('./save_helpers')
var isDocker        = require('is-docker');

var sqlite3                     = require('sqlite3');


var os              = require('os')
var username                            = "Unknown user";

var Keycloak =      require('keycloak-connect');
var session =       require('express-session');
var memoryStore = new session.MemoryStore();

var kk = {
  "realm":              "yazz",
  "auth-server-url":    "http://127.0.0.1:8080/auth",
  "ssl-required":       "external",
  "resource":           "yazz",
  "public-client":       true,
  "confidential-port":   0
}

var sessObj     = session({
                      secret:               'some secret',
                      resave:                false,
                      saveUninitialized:     true,
                      store:                 memoryStore
                    })
github Sunbird-Ed / SunbirdEd-portal / src / app / helpers / trampolineServiceHelper.js View on Github external
Keycloak = require('keycloak-connect'),
  session = require('express-session'),
  uuidv1 = require('uuid/v1'),
  dateFormat = require('dateformat'),
  permissionsHelper = require('./permissionsHelper.js'),
  telemetryHelper = require('./telemetryHelper.js'),
  envHelper = require('./environmentVariablesHelper.js'),
  echoAPI = envHelper.PORTAL_ECHO_API_URL,
  createUserFlag = envHelper.PORTAL_AUTOCREATE_TRAMPOLINE_USER,
  learnerURL = envHelper.LEARNER_URL,
  trampoline_clientId = envHelper.PORTAL_TRAMPOLINE_CLIENT_ID,
  trampoline_server_url = envHelper.PORTAL_AUTH_SERVER_URL,
  trampoline_realm = envHelper.PORTAL_REALM,
  trampoline_secret = envHelper.PORTAL_TRAMPOLINE_SECRET;
  learner_authorization = envHelper.PORTAL_API_AUTH_TOKEN;
let memoryStore = new session.MemoryStore();
var keycloak = new Keycloak({ store: memoryStore }, {
  clientId: trampoline_clientId,
  bearerOnly: true,
  serverUrl: trampoline_server_url,
  realm: trampoline_realm,
  credentials: {
    secret: trampoline_secret
  }
});

module.exports = {
  handleRequest: function(req, res) {
    var self = this,
      payload,
      errorMsg = undefined;
    async.series({
github Sunbird-Ed / SunbirdEd-portal / src / app / helpers / keyCloakHelper.js View on Github external
const envHelper = require('./environmentVariablesHelper.js')
const cassandraUtils = require('./cassandraUtil.js')
const Keycloak = require('keycloak-connect')
const session = require('express-session')
const permissionsHelper = require('./permissionsHelper.js')
const async = require('async')
const telemetryHelper = require('./telemetryHelper.js')
const userHelper = require('./userHelper.js')
let memoryStore = null

if (envHelper.PORTAL_SESSION_STORE_TYPE === 'in-memory') {
  memoryStore = new session.MemoryStore()
} else {
  memoryStore = cassandraUtils.getCassandraStoreInstance()
}
const getKeyCloakClient = (config, store) => {
  const keycloak = new Keycloak({ store: store || memoryStore }, config);
  keycloak.authenticated = authenticated;
  keycloak.deauthenticated = deauthenticated;
  return keycloak
}
const deauthenticated = function (request) {
  delete request.session['roles']
  delete request.session['rootOrgId']
  delete request.session['rootOrghashTagId']
  delete request.session['rootOrg']

  if (request.session) {