Login with Google in nodejs app
In this article, We will create a demo to login with google in our nodejs application. Since login with social is almost availalble at maximum number of mobile or web application. Also I have already covered the login with twitter and facebook over this patform earlier. So let's proceed to create the app step by step.
Step 1: Create client id and secret:
Follow the link to create a app over goole for getting client id and secret Click here. After clicking a page wll open with option to create a new app or to select the previously created app. So click on create button. See the image
And setup the basic information of your application which google will show what type of consent user gives your app to use information from google. Here in the demo I am going to use the basic info.
Fill the details of the application as shown over the image. Once you fill the basic informtion then need to generate the client id and secret. Here I will create it for web browser so need to choose this option while creating client id and secret.
In the above image we can see there is option to choose the option of platform we want to use the social login, the app name and callback url at the bottom. Make sure the path in the redirectURIs should be exact same as we will set in the passport. After submitting this form we will get the client id and secret.
Now our task of creating Client ID and secret is finished. Now move to next step.
Step 2: Set passport and all code related stuff.
Node let's configure the task at nodejs end. So lets see our server.js file, which is having all the major task at nodejs end.
In the above file, At top we have included the needed nodejs package with passport related packages. And below that we have configured passport. And at bottom we have defined the routing in our app.
Now lets come to the view part, have a look our ejs file. Let's have a look on index.ejs file.
In the above file we are managing log in button or profile data after login. Follow the steps provided in the read.me file and run the app with url http://localhost:3000.
That’s all for now. Thank you for reading and I hope this post will be very helpful for implementation of login with google in nodejs application.
Let me know your thoughts over the email email@example.com. I would love to hear them and If you like this article, share with your friends.
You can download complete code from here. Download Code