Sign-Up with Facebook, Twitter and Google using Node.js and MongoDB

Last week, we created a simple login application, which has sign up and login facility after successfully registration.
Now we have added one more feature, i.e. Sign-up with Facebook, Twitter and Google. You can login with your facebook, twitter and google account.

We’ll be adding some more features in this application very soon such as birthday reminder functionality.

Screenshot from 2014-03-22 10:52:55

We have used Passport[authentication middleware for Node.js] strategy for authentication.
To use this application, Pull the code from You have to create Facebook, Twitter and Google App.

After that Go to /config/passport.js

Add API Key and Secret Key in below variables:-

// Facebook authentication
// For more details go to
var FacebookStrategy = require('passport-facebook').Strategy;
var FACEBOOK_APP_ID = "<Insert Your Key Here>"
var FACEBOOK_APP_SECRET = "<Insert Your Secret Key Here>";

// Twitter authentication
// For more details go to
var TwitterStrategy = require('passport-twitter').Strategy;
var TWITTER_CONSUMER_KEY = "<Insert Your Key Here>";
var TWITTER_CONSUMER_SECRET = "<Insert Your Secret Key Here>";

// Google authentication
// For more details go to
var GOOGLE_CONSUMER_KEY = "<Insert Your Key Here>";
var GOOGLE_CONSUMER_SECRET = "<Insert Your Secret Key Here>";
var GoogleStrategy   = require('passport-google-oauth').OAuth2Strategy

Now run below commands:-

npm install

node app

When you would login with your Facebook/Google, user’s data such as name and email would be stored in MongoDB. Since, Twitter doesn’t return user’s email address. So only user’s name would be store in MongoDB.

About Ayush Mishra

Ayush is the Sr. Software Consultant @ Knoldus Software LLP. In his 5 years of experience he has become developer with proven experience in architecting and developing web applications. Ayush has a Masters in Computer Application from U.P. Technical University, Ayush is a strong-willed and self-motivated professional who takes deep care in adhering to quality norms within projects. He is capable of managing challenging projects with remarkable deadline sensitivity without compromising code quality. .
This entry was posted in Agile, CSS, Java, JavaScript, MongoDB, Node.js, Web and tagged , , , , . Bookmark the permalink.

3 Responses to Sign-Up with Facebook, Twitter and Google using Node.js and MongoDB

  1. swapnilbhujbal says:

    Reblogged this on Next Edge Technologies.

  2. asasdasd says:

    We have used Password -> We have used Passport

  3. Janani says:

    Can anyone guide me to write unit test code for passport-google-oauth2 authentication.!!!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s