How to use the use function from passport

Find comprehensive JavaScript passport.use code examples handpicked from public code repositorys.

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',
fork icon60
star icon277
watch icon27

+ 3 other calls in file

49
50
51
52
53
54
55
56
57
58
59
60
app.use(session(sessionConfig));
app.use(passport.initialize());
app.use(passport.session());




// passport.use(new LocalStrategy(User.authenticate()));
passport.use(User.createStrategy())
//how to serialize user - store user in a session
passport.serializeUser(User.serializeUser());
//unstore 
fork icon0
star icon1
watch icon0

1
2
3
4
5
6
7
8
9
10
11
const bcrypt = require('bcrypt');
const passport = require('passport');
const localStrategy = require('passport-local').Strategy;


module.exports = () => {
    passport.use(new localStrategy({
        usernameField: 'id',  //req.body.id
        passwordField: 'pwd', //req.body.pwd
        session: true,
        passReqToCallback: false
fork icon4
star icon0
watch icon1

51
52
53
54
55
56
57
58
59
app.use(passport.initialize());
app.use(passport.session());


// Setup passport
passport.use(new LocalStrategy(async function verify(username, password, cb) {

  let row = await MongoDatabase.db("Authentication").collection("Credentials").findOne({ username: username });
  if (!row) { return cb(null, false, { message: 'Incorrect username or password.' }); }
fork icon0
star icon0
watch icon1

+ 3 other calls in file

46
47
48
49
50
51
52
53
54
55
56
        return done(err);
      };
    })
);


// passport.use(
//   new LocalStrategy((username, password, done) => {
//     User.findOne({ username: username })
//       .then((user) => {
//         if (!user) {
fork icon0
star icon0
watch icon0

7
8
9
10
11
12
13
14
15
16
module.exports = app => {
  // 初始化 Passport 模組
  app.use(passport.initialize())
  app.use(passport.session())
  // 設定本地登入策略
  passport.use(new LocalStrategy({ 
    usernameField: 'email',
    passReqToCallback: true, // 設定為 true,讓 req 物件可傳入 callback 中
    failureFlash: true // 加上這行,當驗證失敗時會自動將錯誤訊息存入 session 
  }, (req, email, password, done) => {
fork icon0
star icon0
watch icon0

+ 3 other calls in file