Documentation / Tutorials / Generic
How to do social login using google authentication in awesome
/ Generic / How to do social login using google 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 an user or somebody else can !. This is where social login authentication comes into action.
Here we are discussing google social authentication. First of all, we have to create a firebase project.
Go to https://console.firebase.google.com/ and create a new project
Once you have created the project go to the authentication menu and enable google login from sign-in methods.
Collect “Web Client ID” and “Web Client Secret”, we will need this later.
Go to the authorized domains section on the same screen and white list domain name there.
One more thing that we have to do, but it’s not here.
Go to https://console.developers.google.com and click on the credentials menu from the page.
Here we can see the list of OAuth credentials that we have created. Go inside of the one that we have created now. Here we have to do 2 things.
- Add the redirect URI Eg: https://www.getawesomestudio.com?social_auth=google
Now we are in good shape, let us write our awesome codes.
Go to our Awesome Core Settings and create two settings
Paste the Web Client ID and Web Client Secret that we have got from the previous step
- Add “google_service” into Awesome Core “services”
- Import “google_service”
Use this link and import the XML for creating the google_service
Important Note: While you are using google authentication on a website that is using PHP version 7.0 then you should explicitly pass version=”7.0″ in every google shortcodes contains in google_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 “handle-social-login”
- 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.