Login with Linkedin in nodejs application
In this article, We will create a demo to log in with Linkedin in our Nodejs application. Since login with social is almost available at the maximum number of mobile or web application. Also, I have already covered the login with twitter, facebook and facebook over this platform earlier.
What is Passport?
Passport is a library that provides a mechanism for easily setting up an authentication/registration system with support for several frameworks and auth providers. In this tutorial, we’ll demonstrate in detail how to integrate this library into a Node.JS/Express 4 application to provide user authentication through LinkedIn using OAuth 2.0.
What is OAuth 2.0?
OAUTH 2.0 is the successor of the OAuth protocol (an open standard for authorization), which enables third-party applications, such as the one we’ll be building, access to an HTTP service without having to share secure credentials.
So let's proceed to create the app step by step.
Step 1: Create Client ID and Secret
Follow the link to create an app over Linkedin for getting a client id and secret Click here. Then login into your LinkedIn account. After login, you will see a menu at the right top named My Apps. Once on clicking on that menu a page will show like below
On the above page click on Create Application button, a form will open after clicking like below:
Fill all the fields and then click on the submit button, After successful submit of form a new page will open like below having newly generated client id and secret with the option to set redirect URL
Now Client ID and the secret has been generated. Click on update button after filling the redirect URL.
Step 2: Set passport and node side code
Node let's configure the task at node.js end. So let's see our server.js file, which is having all the major task at node.js end.
In the above file, At the top, we have included the needed node.js package with passport related packages. And below that, we have configured passport. And at the bottom, we have defined the routing and needed methods 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 LinkedIn in node.js 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