How to use passport

Comprehensive passport code examples:

How to use passport.session:

73
74
75
76
77
78
79
80
81
82
    mongooseConnection: mongoose.connection
  })
}),
express.static(__dirname+'/static'),
passport.initialize(),
passport.session(),
flash(),
function(req, res, next) {
  if (req.headers.accept != process.env.test_call) 
  res.locals.success_msg = req.flash('success_msg');

How to use passport.initialize:

72
73
74
75
76
77
78
79
80
81
  store: new MongoStore({
    mongooseConnection: mongoose.connection
  })
}),
express.static(__dirname+'/static'),
passport.initialize(),
passport.session(),
flash(),
function(req, res, next) {
  if (req.headers.accept != process.env.test_call) 

How to use passport.default:

98
99
100
101
102
103
104
105
106
107
 * Des       Delete a users review
 * Params    _id
 * Access    Private
 * Method    Delete
 */
Router.delete("/delete/:id", _passport.default.authenticate("jwt", {
  session: false
}), async (req, res) => {
  try {
    const {

How to use passport.deserializeUser:

87
88
89
90
91
92
93
94
95
96

passport.serializeUser(function (sessionInfo, cb) {
  cb(null, sessionInfo);
});

passport.deserializeUser(async function (sessionInfo, cb) {
  cb(null, sessionInfo);
});

// Prep the web server

How to use passport.serializeUser:

83
84
85
86
87
88
89
90
91
92
      }
    }
  )
);

passport.serializeUser(function (sessionInfo, cb) {
  cb(null, sessionInfo);
});

passport.deserializeUser(async function (sessionInfo, cb) {

How to use passport.use:

3
4
5
6
7
8
9
10
11
12
13
const AV = require('leanengine')
const randomstring = require('randomstring')
const config = require('../config')


module.exports = (router) => {
  passport.use(
    'xd-cas',
    new OAuth2Strategy(
      {
        authorizationURL: 'https://sso.security.xindong.com/cas/oauth2.0/authorize',

How to use passport.authenticate:

71
72
73
74
75
76
77
78
79
80
        .catch(done)
    }
  )
)
router.get('/auth/xd-cas', (req, ...args) =>
  passport.authenticate('xd-cas', { state: { referer: req.headers.referer } })(req, ...args)
)
router.get('/auth/xd-cas/callback', passport.authenticate('xd-cas'), function (req, res) {
  const state = req.authInfo.state
  // resume state...