Linkedin Authentication for a MEAN stack application
So every other article about linkedin authentication in a nodejs application uses PASSPORTJS, which is a library that I never understood when it comes to authentication using social media.
So here’s an article that shows you how to authenticate your users using linkedin, from frontend to backend and without passportjs
Technologies I’m using
Angular 12 / node v14
HOW WILL THIS WORK?
This figure below represents a sequence diagram of how linkedin auth will be implemented
1- Create a Linkedin App in LinkedinDevelopers
Fill out all the information needed, and then in the auth section you’ll find your CLIENT_ID and CLIENT_SECRET.
In the products section, select sign in with linkedin in order to get OAUTH2.0 scopes
Last, don’t forget to specify the redirect url in OAUTH2.0 settings
Now that you’re all set, let’s move on to CODING.
2- Frontend Part
Clicking on the button will redirect you to this interface
After clicking on allow, the user will be redirected to the redirect url specified earlier.
In the ngOnInit of the page we are being redirected to, we will catch the authCode returned by the linkedin API and send it to our backend
3- Backend Part
For the communication between our server and Linkedin API, I decided to work with axios, however you can also work with https or request.
Conclusion
That’s all folks.
I hope I didn’t forget anything and if something is missing please let me know :D
If anything is unclear, don’t hesitate to leave a comment.
Here ‘s the linkedin documentation link for the authentication, however, it is not up to date.
Thank you very much !