Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using passport.js to connect a local strategy to another (Facebook, Twitter, Google, etc)

I have a node.js application which uses passport (with a modified passport-local for the login strategy) for authentication management. I would like to allow users to connect their social network accounts using passport strategies, but from what I can see the existing authentication (on the request object) gets overwritten when a new one is made.

How should I approach this?

like image 783
9point6 Avatar asked Jan 29 '13 13:01

9point6


People also ask

What is Passport js used for?

Passport is a popular, modular authentication middleware for Node. js applications. With it, authentication can be easily integrated into any Node- and Express-based app. The Passport library provides more than 500 authentication mechanisms, including OAuth, JWT, and simple username and password based authentication.


2 Answers

I was using passport.authenticate when I should have been using passport.authorize!

docs here: http://passportjs.org/guide/authorize/

like image 85
9point6 Avatar answered Nov 15 '22 00:11

9point6


I've created a sample for that see https://github.com/fpp/drywall

It allows to associate one or more social accounts with a local strategy user, create local strategy users from social accounts, plus add/remove social accounts from these users.

Currently twitter & github are implemented - just add other passport versions and adjust the code sample for more services.

The sample uses Node.js 0.8x, express 3.x and backbone.js - includes some basic user management from the http://jedireza.github.com/drywall/ sample project.

P.S. I could not get a second route (for the same social service) / authorize vs authenticate with passport working as described in the passport documentation. Use

passReqToCallback: true

in the strategy instead and work on the user (see example for more).

like image 37
fpp Avatar answered Nov 14 '22 23:11

fpp