How to use the passport.session function in passport

To help you get started, we’ve selected a few passport 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 bradtraversy / nodeauthapp / app.js View on Github external
// Port Number
const port = 3000;

// CORS Middleware
app.use(cors());

// Set Static Folder
app.use(express.static(path.join(__dirname, 'public')));

// Body Parser Middleware
app.use(bodyParser.json());

// Passport Middleware
app.use(passport.initialize());
app.use(passport.session());

require('./config/passport')(passport);

app.use('/users', users);

// Index Route
app.get('/', (req, res) => {
  res.send('Invalid Endpoint');
});

// Start Server
app.listen(port, () => {
  console.log('Server started on port '+port);
});
github backstrokeapp / server / src / server.js View on Github external
// ----------------------------------------------------------------------------
// Passport stuff
// ----------------------------------------------------------------------------
import passport from 'passport';
import session from 'express-session';
import fileStore from 'session-file-store';
const FileStore = fileStore(session);
import strategy from './auth/strategy';
import serialize from './auth/serialize';
app.use(session({
  secret: process.env.SESSION_SECRET,
  saveUninitialized: true,
  resave: true,
}));
app.use(passport.initialize());
app.use(passport.session());
passport.use(strategy(User));
serialize(User, passport);

// ----------------------------------------------------------------------------
// User authentication flow routes
// ----------------------------------------------------------------------------
import bodyParser from 'body-parser';

// Authenticate a user
app.get('/setup/login', passport.authenticate('github', {
  successRedirect: '/',
  scope: ["repo", "write:repo_hook", "user:email"],
}));
app.get('/setup/login/public', passport.authenticate('github', {
  successRedirect: '/',
  scope: ["public_repo", "write:repo_hook", "user:email"],
github thegameofcode / passport-fitbit-oauth2 / examples / login / app.js View on Github external
var express = require('express');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var FitbitStrategy = require('./lib').FitbitOAuth2Strategy;
var passport = require('passport');
var app = express();

app.use(cookieParser());
app.use(bodyParser());

app.use(session({ secret: 'keyboard cat' }));

app.use(passport.initialize());
app.use(passport.session({
  resave: false,
  saveUninitialized: true
}));

const CLIENT_ID = '';
const CLIENT_SECRET = '';

app.use(passport.initialize());

var fitbitStrategy = new FitbitStrategy({
  clientID: CLIENT_ID,
  clientSecret: CLIENT_SECRET,
  scope: ['activity','heartrate','location','profile'],
  callbackURL: "http://localhost:3000/auth/fitbit/callback"
}, function(accessToken, refreshToken, profile, done) {
  // TODO: save accessToken here for later use
github DesignOpen / board / src / server.js View on Github external
app.use(session({
    secret: process.env.SESSION_SECRET,
    saveUninitialized: true,
    resave: true,
    store: new MongoStore({
        mongooseConnection: mongoose.connection
    })
}));
app.use(compression({
    // Compress everything over 10 bytes
    threshold: 10
}));

// Initialize passport
app.use(passport.initialize());
app.use(passport.session());

// Initialize routes. This must be done after models are registered
// for mongoose
var routes = require('./routes');
routes.initRoutes(app);

// Handle errors
var ValidationError = mongoose.Error.ValidationError;
app.use(function(err, req, res, next) {
    if (err instanceof ValidationError) {
        logger.error('Mongoose validation error. Errors:')
        logger.error(err.errors);
    }

    next(err);
});
github hibyguy / BTSwebsite / app.js View on Github external
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(express.static('public'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(expressValidator());
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

//session storage
app.use(expressSession({secret: 'max', saveUninitialized: false, resave: false}));

//Passport initialization
app.use(passport.initialize());
app.use(passport.session());
// Connect Flash
app.use(flash());

//Routes
app.use('/', routes);
app.use('/users', users);
app.use('/child', child);
app.use('/events', events);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});
github geneontology / noctua / login.js View on Github external
// 
// 

var app = express();

// app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(session({
    secret: 'keyboard cat',
    resave: true,
    saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());

app.set('port', '8899');

// 
// 
// 

app.use(cookieParser());
app.use(bodyParser());
app.use(session({
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());
github StephenGrider / AdvancedNodeStarter / index.js View on Github external
require('./services/passport');

mongoose.Promise = global.Promise;
mongoose.connect(keys.mongoURI, { useMongoClient: true });

const app = express();

app.use(bodyParser.json());
app.use(
  cookieSession({
    maxAge: 30 * 24 * 60 * 60 * 1000,
    keys: [keys.cookieKey]
  })
);
app.use(passport.initialize());
app.use(passport.session());

require('./routes/authRoutes')(app);
require('./routes/blogRoutes')(app);

if (['production'].includes(process.env.NODE_ENV)) {
  app.use(express.static('client/build'));

  const path = require('path');
  app.get('*', (req, res) => {
    res.sendFile(path.resolve('client', 'build', 'index.html'));
  });
}

const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
  console.log(`Listening on port`, PORT);
github JonathanWexler / get-programming-with-nodejs / unit_6 / lesson_29_capstone / start / confetti_cuisine / main.js View on Github external
router.use(cookieParser("secretCuisine123"));
router.use(
  expressSession({
    secret: "secretCuisine123",
    cookie: {
      maxAge: 4000000
    },
    resave: false,
    saveUninitialized: false
  })
);
router.use(connectFlash());

router.use(passport.initialize());
router.use(passport.session());
passport.use(User.createStrategy());
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());

router.use((req, res, next) => {
  res.locals.loggedIn = req.isAuthenticated();
  res.locals.currentUser = req.user;
  res.locals.flashMessages = req.flash();
  next();
});

router.get("/", homeController.index);

router.get("/users", usersController.index, usersController.indexView);
router.get("/users/new", usersController.new);
router.post(
github ebu / pi-list / apps / listwebserver / auth / index.js View on Github external
module.exports = (app) => {
    app.use(passport.initialize());
    app.use(passport.session());

    setupLocalAuth(app);

    app.get('/auth/logout', (req, res) => {
        websocket.instance().disconnectUser(req.session.passport.user.id);
        req.logout();
        res.redirect(program.webappDomain);
    });

    app.get('/auth/token', (req, res) => {
        const token = uuid().replace(/-/g, '');

        tokenManager.storeToken(token);

        logger('auth-token').info(`Set token ${token} for the session ${req.session.id}`);
        res.status(HTTP_STATUS_CODE.SUCCESS.OK).send({ t: token });
github stefanteixeira / fav-organizer / config / express.js View on Github external
app.set('views', './app/views');

  app.use(bodyParser.urlencoded({extended: true}));
  app.use(bodyParser.json());
  app.use(require('method-override')());

	app.use(cookieParser());
	app.use(session(
		{
			secret: 'fav-organizer',
			resave: true,
			saveUninitialized: true
		}
	));
	app.use(passport.initialize());
	app.use(passport.session());

	app.use(helmet.xframe());
	app.use(helmet.xssFilter());
	app.use(helmet.noSniff());
	app.disable('x-powered-by');

	load('models', {cwd: 'app'})
    .then('controllers')
    .then('routes')
    .into(app);

	app.get('*', function(req, res) {
		res.status(404).render('404');
	});

	return app;