14

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

 3 years ago
source link: https://blog.knoldus.com/sign-up-with-facebook-twitter-and-google-using-node-js-and-mongodb/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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

Reading Time: < 1 minute

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.

We have used Passport[authentication middleware for Node.js] strategy for authentication.
To use this application, Pull the code from https://github.com/knoldus/Node.js_UserLogin_Template. 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:-

xxxxxxxxxx
// Facebook authentication
// For more details go to https://github.com/jaredhanson/passport-facebook
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 https://github.com/jaredhanson/passport-twitter
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 https://github.com/jaredhanson/passport-google-oauth
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:-

xxxxxxxxxx
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 Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK