How to Make Google Sign-In Cordova?
Let’s start making Google sign in Cordova. I create this project on Visual Studio 2017 My system Cordova version 6.3.1, Cordova android version 5.2.1 (you can see on Config.xml (in code view eg: engine name="android" spec="5.2.1" ), cordova-plugin-googleplus (eg: plugin name="cordova-plugin-googleplus" spec="~5.3.0").
- Create a New Project.
- Create a project on google console (console.developers.google.com/apis/credentials)
- Set up your application’s Code.
- Install the Dependencies
- Get the Web Client ID from Google Console.
Let’s Create the New Project in Visual Studio 2017 if you don’t know how to Create the Project on Visual studio click on here. Create two Project on Google Console.
One For Web Application and Android.
Note: If you don't have a web application just put a link like I did.
Create Android Project.
Here we need a package name and SHA-1 signing-certificate fingerprint of our project. Let Get the Package Name from the Config.xml look on below picture.
“io.cordova.myappa80dc3” if you want to change this package name you can change like ”com.Cordovagooglelogin.app” .
Now get SHA-1 signing-certificate fingerprint key of your app. First, we need the keystore to store our app info. Keystore path looks like “C:\Users\your_Computer_name\.android\debug.keystore”. And Find keytool path on your Computer “C:\Program Files\Java\jdk1.8.0_172\bin” or “C:\ Program Files (x86)\Java\jdk1.8.0_172\bin” and type cmd on the address bar of the folder. Type
keytool -genkeypair -v -keystore C:\Users\your_Computer_name\.android\debug.keystore -alias yourappname -keyalg RSA -keysize 2048 -validity 10000
Enter it ask the Enter the password type “android” and it asks some question, give an answer at the end it asks the password for your app.
After doing this we are ready to get SHA-1 signing-certificate fingerprint of our app.
keytool -exportcert -alias yourappname -keystore C:\Users\your_Computer_name\.android\debug.keystore -list –v
After entering the cmd line it asks password again type “android” you can see your alias name.
Now go to the Google Console project Past this SH1 key in Android Project and Package name save it.
In our Cordova project Create or update build.json file like this on a picture.
Install the Cordova Plugin “cordova-plugin-googleplus” and we don’t need Reverse_Client_ID(only for ios application if you want put the reverse_client_id look like “com.googleusercontent.apps. 576723…..”.
After installing the cordova google plugin now write some code.
Now build the project and Run on Device my Device android version 5.1.1.
Note: Do not put Client Id of your android project put your Client Id of web application otherwise it gets “error 10 or something error” so please be careful.
Hope it helps you.