How to use the authenticate function from passport

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

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

+ 7 other calls in file

109
110
111
112
113
114
115
116
117
118
119


app.get(`/profile/:token`, (req, res) => {
  const token1 = req.params.token;
  console.log("token1");
  console.log(token1);
  passport.authenticate("google", {
    failureRedirect: "/login",
  });
  if (req.isAuthenticated()) {
    User.find(
fork icon56
star icon30
watch icon3

+ 2 other calls in file

367
368
369
370
371
372
373
374
375
376
377
    let conv = JSON.stringify(newArray, null, 4) + '\n';
    fs.writeFileSync('./bypassbans.json', conv);
    res.redirect('/admin/bypass')
});


app.get('/auth/discord', passport.authenticate('discord'));
app.get('/auth/discord/callback', passport.authenticate('discord', {failureRedirect: '/'}), async function(req, res) {
    req.session?.loginRef ? res.redirect(req.session.loginRef) : res.redirect('/');
    delete req.session?.loginRef
});
fork icon18
star icon40
watch icon1

127
128
129
130
131
132
133
134
135
136
137
  }
});


router.post(
  "/file/:key",
  passport.authenticate("young", { session: false, failWithError: true }),
  fileUpload({ limits: { fileSize: 10 * 1024 * 1024 }, useTempFiles: true, tempFileDir: "/tmp/" }),
  async (req, res) => {
    try {
      const rootKeys = [
fork icon4
star icon8
watch icon4

+ 37 other calls in file

235
236
237
238
239
240
241
242
243
244
245
246
app.get('/login', function(req, res) {
  res.sendFile('src/login.html', {root: __dirname})
});


//send users to discord to login when the /loginDiscord url is visited
app.get('/loginDiscord', passport.authenticate('discord', { scope: scopes }), function(req, res) {});


//get the auth code from discord (the code parameter) and use it to get a token
app.get('/callback',
  passport.authenticate('discord', { failureRedirect: '/login' }), function(req, res) { res.redirect('/') } // auth success
fork icon1
star icon3
watch icon6

+ 7 other calls in file

317
318
319
320
321
322
323
324
325
326
);

app.post(
  '/server/account/login',
  wrapForErrorProcessing((req, res, next) => {
    passport.authenticate('local', async function (err, accountInfo, info) {
      if (err || !accountInfo) {
        logger.warn(null, 'Authentication Failed', accountInfo, err, info);
        res.status(400).send();
        return;
fork icon1
star icon2
watch icon5

+ 4 other calls in file

44
45
46
47
48
49
50
51
52
53
54
55


app.get('/', (req, res) => {
    res.send('Default response');
});


//app.get('/movies', passport.authenticate('jwt', {session: false}), (req, res) => {
  //Movies.find().then(Movies => res.json(Movies))
  //});
app.get('/movies', (req, res) => {
  Movies.find().then(Movies => res.json(Movies))
fork icon1
star icon0
watch icon0

+ 7 other calls in file

126
127
128
129
130
131
132
133
134
135
136
137
app.get('/login_sign' , (req, res) => {
    res.render('login_sign.ejs');
}); 


// passport.authenticate : 응답해주기 전 local방식으로 ID,PW 인증. / 인증 실패시 /fail로 이동
app.post('/login_sign' , passport.authenticate('local' , {
    failureRedirect : 


    '/login_sign'     
}), function(req, res) {
fork icon1
star icon0
watch icon0

30
31
32
33
34
35
36
37
38
39
}
req.body.email = validator.normalizeEmail(req.body.email, {
  gmail_remove_dots: false,
});

passport.authenticate("local", (err, user, info) => { // passport.authenticate() is a middleware that authenticates the user
  if (err) {
    return next(err);
  }
  if (!user) { // if user is not found
fork icon0
star icon1
watch icon1

+ 4 other calls in file

866
867
868
869
870
871
872
873
874
875
876
// });


// rota para autenticação de login
app.post(
  "/login",
  passport.authenticate("local", {
    successRedirect: "/",
    failureRedirect: "/login",
    failureFlash: true,
  })
fork icon0
star icon1
watch icon1

9
10
11
12
13
14
15
16
17
18
19
20
21
    if(req.isAuthenticated()) { return res.redirect('/') }


    res.render('profile/login.ejs', { req, message: (req.session.flash && req.session.flash.error) })
});


router.post("/login", passport.authenticate('local', { failureRedirect: '/login', failureFlash: true, }), (req, res) => {
    const backURL = req.header('Referer') || '/'; res.redirect(backURL);
});


router.get("/register", (req, res) => {
fork icon0
star icon1
watch icon2

+ 3 other calls in file

54
55
56
57
58
59
60
61
62

if (!req.body.user.password) {
  return res.status(422).json({ errors: { password: "can't be blank" } });
}

passport.authenticate("local", { session: false }, function(err, user, info) {
  if (err) {
    return next(err);
  }
fork icon0
star icon1
watch icon0

+ 3 other calls in file

101
102
103
104
105
106
107
108
109
110
111
);*/


router.post('/login', ensureAuthenticatedLogin,
  function(req, res, next) {
    console.log (req.body)
    passport.authenticate('local-login', function(err, user, info) {
      if (err) {
        return next(err); // will generate a 500 error
      }

fork icon0
star icon0
watch icon1

+ 2 other calls in file

116
117
118
119
120
121
122
123
124
125
126
        }
    })
})


//маршрутизатор получения данных авторизованного пользователя через passport
router.route('/').get( passport.authenticate('jwt', {session: false}), (req,res) => 
{
    //собираем все полученные данные по авторизованному пользователю
    res.json(
    {
fork icon0
star icon0
watch icon1

+ 3 other calls in file

293
294
295
296
297
298
299
300
301
302
303
  }
});


router.get(
  '/google',
  passport.authenticate('google', {
    session: false,
    scope: ['profile', 'email'],
    accessType: 'offline',
    approvalPrompt: 'force'
fork icon0
star icon0
watch icon1

+ 15 other calls in file

365
366
367
368
369
370
371
372
373
374
        prompt: "select_account",
    })
);
app.get(
    "/auth/microsoft/welderstone",
    passport.authenticate("microsoft", { failureRedirect: "/login/false" }),
    function (req, res) {
        res.redirect("/");
    }
);
fork icon0
star icon0
watch icon1

+ 23 other calls in file

99
100
101
102
103
104
105
106
107

});

app.use(express.static(__dirname + '/public'));

app.post('/login/password', passport.authenticate('local', {
  successRedirect: '/',
  failureRedirect: '/login/login.html'
}));
fork icon0
star icon0
watch icon1

+ 3 other calls in file

24
25
26
27
28
29
30
31
32
33

Auth.app = app;
Auth.middleware = middleware;

// Apply wrapper around passport.authenticate to pass in keepSessionInfo option
const _authenticate = passport.authenticate;
passport.authenticate = (strategy, options, callback) => {
	if (!callback && typeof options === 'function') {
		return _authenticate.call(passport, strategy, options);
	}
fork icon0
star icon0
watch icon1

+ 4 other calls in file

75
76
77
78
79
80
81
82
83
84

passportLogin(req, res, next) {
  // This function is middleware which wraps the passport.authenticate middleware,
  // so we can send back our custom `{message: {text: "", type: ""}}` responses on failure,
  // and send a `{redir: ""}` response on success
  passport.authenticate('local', function (err, user, info) {
    if (err) {
      return next(err)
    }
    if (user) {
fork icon0
star icon0
watch icon202

305
306
307
308
309
310
311
312
313
314

req.login(user, function(err){
  if (err) {
    console.log(err);
  } else {
    passport.authenticate("local")(req, res, function(){
      res.redirect("/secrets");
    });
  }
});
fork icon0
star icon0
watch icon1

+ 2 other calls in file