OneProfile Strategy for Passport

Installation

1. Intstall passprot and OneProfile strategy.

  > npm install passport passport-oneprofile --save

More detail please refer to Passport configuration page. Some key points are listed below:

  1. Add two middleware to Express project - passport.initialize() and passport.session()

     var passport = require('passport');
     app.configure(function() {
       // Some middleware ...
    
       app.use(passport.initialize());
       app.use(passport.session());
    
       // Other middleware ...
     });
    
  2. Serialize and deserialize user instances to and from the session.

The simplest implementation is as below:

    passport.serializeUser(function(user, done) {
      done(null, user);
    });

    passport.deserializeUser(function(user, done) {
      done(null, user);
    });

2. Add customized passport strategy.

Set one profile as an authentication strategy. Set ONES_KEY, ONES_SECRET and ONES_HOST in system environment variables or hard code to replace them.

    var oneProfileStrategy = require('passport-oneprofile');

    passport.use(new oneProfileStrategy({
        opId: process.env.ONES_KEY,
        opSecret: process.env.ONES_SECRET,
        opHost: process.env.ONES_HOST
    }, function(err, user, done) {
      // Do anything for the returned user, or just pass it to callback
        done(err, user);
      })
    );

SEARCH FOR STRATEGIES

0STRATEGIES