Using connect middleware in Webapp.connectedHandlers

I’m trying to integrate passport.js which uses the node connect middleware. The connect library is what Webapp exposes in Webapp.connectedHandlers ( https://docs.meteor.com/packages/webapp.html ). Most passport examples use express, none with meteor.

The closest thing I could find is: http://stackoverflow.com/questions/11006318/using-passportjs-with-connect-for-nodejs-to-authenticate-facebook-users

From reading passport, using a unique token strategy should be simple. https://github.com/Lughino/passport-unique-token

const passport = require('passport')
const UniqueTokenStrategy = require('passport-unique-token').Strategy
const debug = require('debug')('wireline:passport')

WebApp.connectHandlers.use(passport.initialize())

passport.use(new UniqueTokenStrategy(
    function (token, done) {
      console.log('token', token) // no logs appearing
      if ( token ){
        return done(null, 'ok');

      } else {
        done('err', null)
      }
    }
));

// passport.authenticate generates the callback function 'connect' would need
callbackFunc =  passport.authenticate('token')

WebApp.connectHandlers.use('/passportTestRoute', callbackFunc)

It doesn’t throw any exception. On requesting the route, it doesn’t seem to run the function, since the consoe.log check isn’t printed. All I get is a bad request as the response in the browser, and no meaningful logs.

Any thoughts?

Hi @lpgeiger

I checked your example and it does work fine. Are you passing token parameter in url?

http://localhost:3100/passportTestRoute?token=12345

It did show me Bad request when I wan’t passing token.