I have an app which uses nodejs but I don't serve my pages via ExpressJS. It is a simple http nodejs app which I will migrate to nodejs at some stage.
However, I am playing around with Passportjs and currently I am getting 'passport.intitalize() middleware not in use' errors which from the documentation mention 'connect' and 'Express' usage.
Can I use passportjs without Expressjs?
Passport Strategies expect inputs on certain channels (e.g. 'Local' looks for username
and password
fields on <OBJ>.body
), but if you provide for these Strategy requirements directly you can use Passport just fine without Express/Connect.
Take a look directly at comments lifted from the relevant Passport code:
https://github.com/jaredhanson/passport/blob/master/lib/authenticator.js#L146
passport.authenticate('local', function(err, user) {
if (!user) { return res.redirect('/login'); }
res.end('Authenticated!');
})(req, res);
If you provide req
and res
as your own objects (paying attention to the requirements of the Strategy you're using and whatever you're using of req/res in authenticate), you have total control.
(Or just write a simple custom framework wrapper).
Short version: No, express is required for regular passport usage.
Long version: You could technically use a large portion of passport's code in a non-express application, but that could create all sorts of edge cases you don't want in your auth code. It'd also probably be easier just to convert your application to express.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With