- Cloudrail Tutorial
- Cloudrail - Home
- Cloudrail - Overview
- Cloudrail - Android
- Cloudrail - Java
- Cloudrail - Node.js
- Cloudrail - IOS
- Cloudrail - Social Login
- Cloudrail - Setup
- Cloudrail - Coding
- Cloudrail Useful Resources
- Cloudrail - Quick Guide
- Cloudrail - Useful Resources
- Cloudrail - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Cloudrail - Coding
Create a new file for your server code in the created folder and add the following to import and setup Express and CloudRail −
Now, we continue by writing a function that will instantiate the services we want to use for social login −
We need a way to keep track of user identities. This is normally done in a database but to keep this tutorial short, we will use an object that acts as a pseudo-database.
All its data is kept in memory and is thus lost when the server restarts −
After, we register the server endpoint that will handle the start of the social login flow −
The service we have started the social login with will redirect to our server and we need to handle this redirect.
After getting a unique identifier for the user, we check if we have seen this user before. If yes, then we greet him with his name. If not, we get the name from the social network and save a new user −
Finally, we have the server listen on port 12345 −
We can now start the application and test it in our local browser.
If you navigate to http://localhost:12345/auth/start/facebook you will start the Facebook login flow.
If you navigate to http://localhost:12345/auth/start/twitter you will start the Twitter login flow.
After logging in with the service and granting access, you will be seeing "Welcome greenhorn!" if you do it for the first time and "Welcome back [your name]" on consecutive visits.
To integrate it into an actual website, you would, for example, include the service provider's logos there and make the logos link to the respective URLs.
Besides, the pseudo-database should be replaced with a real one. And there you go, social login for up to 9 different providers!