Using Passport.js for Bonita REST API


Hello Team,

I'm trying to develop a MEAN app interfacing with the bonita rest API. I'm using the passport.js that is included in the seed that I've built. I having some issues integrating passport.js with the bonita login rest api. Has anyone done this before? I have a node script that calls the login rest api, gets cookie, then calls a get process service. This works just fine. But when trying to integrate into existing application, I can't get it to work.

I see the local passport which calls the local strategy. I do see the old bunny process example, but I think this is a little out dated and would like to implement a full end to end strategy using MEAN.

Please help.

'use strict';

   var express = require('express');
   var passport = require('passport');
   var auth = require('../auth.service');

   var router = express.Router();'/', function(req, res, next) {
   passport.authenticate('local', function (err, user, info) {

var error = err || info;
if (error) return res.status(401).json(error);
if (!user) return res.status(404).json({message: 'Something went wrong, please try again.'});

var token = auth.signToken(user._id, user.role);
res.json({token: token});
 })(req, res, next)

module.exports = router;

var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;

exports.setup = function (User, config) {
  passport.use(new LocalStrategy({
      usernameField: 'email',
      passwordField: 'password' // this is the virtual field on the model
    function(email, password, done) {
        email: email.toLowerCase()
      }, function(err, user) {
        if (err) return done(err);

        if (!user) {
          return done(null, false, { message: 'This email is not registered.' });
        if (!user.authenticate(password)) {
          return done(null, false, { message: 'This password is not correct.' });
        return done(null, user);
No answers yet.