node.js - Manually call passport for authentication -


i develop restful nodejs api protected oauth2 authentication using passport.

  var express = require('express');     var passport = require('passport');     var port = process.env.port || 8080;     var app = express();      app.use(passport.initialize());      // create our express router     var router = express.router();     var creaturecontroller = require('./controllers/creature');      router.route('/creature').get(passport.authenticate('accesstoken', {session: false}), creaturecontroller.getprofile); 

in case, route protected , requires send valid token in order access route.

i want find way authenticate "users" manually, calling function, take username , password of user want authenticate.

passport exposes req.login() function can used login user manually.

app.post('/login', function (req, res, next) {     var user = user.findorcreate(req.body);     // … authentication or whatever     req.login(user, function(err){         if(err) return next(err);         res.redirect('/home');     }); }); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -