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:-
// 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:-
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.