Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating passport.js & Meteor

I am trying to implement passport.js in my Meteor project and I am kind of stuck sending user information via passport.

Firstup, I am building an authentication system that uses LDAP on the organization's side. The y have bought Shibboleth's Identity Provider, http://shibboleth.net/products/identity-provider.html and wants to use passport-saml as an authenticating framework residing the web app. I have followed this git tutorial, https://github.com/bergie/passport-saml , as well as the official passport.js tutorial and I have implemented the methods in passport.js in the server side of Meteor.

Meteor.startup(function () {
var require = Npm.require;
  passport = require('passport');
  var SamlStrategy = require('passport-saml').Strategy;

  passport.use(new SamlStrategy(
    {
      path: '/login/callback',
      entryPoint: 'https://openidp.feide.no/simplesaml/saml2/idp/SSOService.php',
      issuer: 'passport-saml'
    },
    function(profile, done) {
      findByEmail(profile.email, function(err, user) {
        if (err) {
          return done(err);
        }
        return done(null, user);
      });
    }
  ));

  Meteor.Router.add('/login/callback', 'POST', function(req, res){
    passport.authenticate('saml', { failureRedirect: '/', failureFlash: true });
    res.redirect('/');
  });

  Meteor.Router.add('/login', 'POST', function(req, res){
    passport.authenticate('saml', { failureRedirect: '/', failureFlash: true });
    res.redirect('/');
  });

  var app = __meteor_bootstrap__.app;
  app.use(passport.initialize());
  app.use(passport.session());

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

  passport.deserializeUser(function(id, done) {
    User.findById(id, function(err, user) {
      done(err, user);
    });
  });

});

My question now is how do i get passport to send the user information over. Is it done via passing a profile object via the function in passport.use?

Thanks so much and I am unsure of how much codes i should show, just drop me a comment and i will improve this post!

like image 524
Junhao Avatar asked Jun 14 '13 17:06

Junhao


1 Answers

This was asked before Meteor updated support for oAuth in 6.4 and I assume that the user has figured this out. For those of us searching for oAuth + Meteor now it's integrated better now.

No need to mess with passport.js

See the blog post here: https://www.meteor.com/blog/2013/06/10/meteor-064-new-oauth-packages-and-recommended-updates

Essentially you can now do this:

$ meteor add accounts-twitter
$ meteor add accounts-facebook

etc.

like image 82
Spencer Avatar answered Nov 29 '22 05:11

Spencer