Documentation / Tutorials / Generic
How to do social login using facebook authentication in awesome
/ Generic / How to do social login using facebook authentication in awesome
We can authenticate our application users through our local authentication mechanisms such as traditional username, password, or OTP-based authentication but in this approach, we are the one who is checking the authenticity of the user. But what if someone is already verified the authenticity of a user or somebody else can !. This is where social login authentication comes into action.
Here we are discussing facebook social authentication. First of all, we have to create a facebook app.
Go to https://developers.facebook.com/ and create an app
Once you have created the app go to the basic settings and add the app domains. Also, add your site URL as well.
Collect “App ID” and “App Secret”, we will need this later.
Go to the advanced settings and white list your domain in the domain manager.
Now Go to the “Facebook Login settings” under the menu called “Products” and add your redirect URL inside “Valid OAuth Redirect URIs”
Now we are in good shape, let us write our awesome codes.
Go to our Awesome Core Settings and create two settings
Paste the App ID and App Secret that we have got from the previous step
- Add “facebook_service” into Awesome Core “services”
- Import “facebook_service”
Use this link and import the XML for creating the facebook_service
Go to your “Login” app or any app where you have to implement the social login.
- Add our login button snippet
Note: We are using <template> for setting the cookie, so please make sure that you have spa.js loaded
- Create a module inside your app called “facebook-handler”
- Process your user data and do the necessary changes to your code
Eg: Once you have the user data you can set the session
In the previous step we got out authenticated user data, but that’s not the end of the story. You will have to set the session for this user or you may respond with a bearer token or a JWT depends on what kind of application you are building.