How to use the passport-local.Strategy.call function in passport-local

To help you get started, we’ve selected a few passport-local examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angular-app / angular-app / server / lib / mongo-strategy.js View on Github external
function MongoDBStrategy(dbUrl, apiKey, dbName, collection) {
  this.dbUrl = dbUrl;
  this.apiKey = apiKey;
  this.dbName = dbName;
  this.collection = collection;
  this.baseUrl = this.dbUrl + '/databases/' + this.dbName + '/collections/' + collection + '/';

  // Call the super constructor - passing in our user verification function
  // We use the email field for the username
  LocalStrategy.call(this, { usernameField: 'email' }, this.verifyUser.bind(this));

  // Serialize the user into a string (id) for storing in the session
  passport.serializeUser(function(user, done) {
    done(null, user._id.$oid); // Remember that MongoDB has this weird { _id: { $oid: 1234567 } } structure
  });

  // Deserialize the user from a string (id) into a user (via a cll to the DB)
  passport.deserializeUser(this.get.bind(this));

  // We want this strategy to have a nice name for use by passport, e.g. app.post('/login', passport.authenticate('mongo'));
  this.name = MongoDBStrategy.name;
}
github angular-app / angular-app / server / lib / mongo-strategy.js View on Github external
function MongoDBStrategy(dbUrl, apiKey, dbName, collection) {
  this.dbUrl = dbUrl;
  this.apiKey = apiKey;
  this.dbName = dbName;
  this.collection = collection;
  this.baseUrl = this.dbUrl + '/' + this.dbName + '/collections/' + collection + '/';

  // Call the super constructor - passing in our user verification function
  // We use the email field for the username
  LocalStrategy.call(this, { usernameField: 'email' }, this.verifyUser.bind(this));

  // Serialize the user into a string (id) for storing in the session
  passport.serializeUser(function(user, done) {
    done(null, user._id.$oid); // Remember that MongoDB has this weird { _id: { $oid: 1234567 } } structure
  });

  // Deserialize the user from a string (id) into a user (via a cll to the DB)
  passport.deserializeUser(this.get.bind(this));

  // We want this strategy to have a nice name for use by passport, e.g. app.post('/login', passport.authenticate('mongo'));
  this.name = "mongo";
}

passport-local

Local username and password authentication strategy for Passport.

MIT
Latest version published 10 years ago

Package Health Score

73 / 100
Full package analysis