Blog

Create Google Registration and Login Example App with Code Generation

by on June 13, 2019

Register and Login with Google Code Generation App

Today we are going to walk you through the process of allowing users to register and log into your app using their Google account. The best way to showcase this is to walk through the Registration and Login example app available in the Code Generation section of your Backendless Console.

The first thing we’ll do is create an application with the name Registration_and_Login (you can choose any other name for the application, but then you will need to substitute it further everywhere).

Within Backendless

Go to the Code Generation section – select the category Android – Registration and Login.

Android Registration and Login Code Generation

In the window that appears, select only Google login – GENERATE.

Generate Google Registration and Login App

Copy the downloaded archive. Open the Archive in your favorite IDE; we will use IntelliJ IDEA.

Within Google API Console

Next, you need to click on this link and go to the Configure section of the Google API Console project. Click on the “CONFIGURE A PROJECT” button and enter the name of your project.

Configure Project in Google API Console

For this example, we chose the following name for the project: BackendlessRegistration. In the next step, we also use the name BackendlessRegistration.

Configure OAuth Client in Google API Console

In the next step, you need to select Android, enter the package name (which can be viewed in the manifest file of the downloaded project in src / main / AndroidManifest.xml). The creation of the SHA-1 signing certificate is described here. After entering all the necessary information, click CREATE.

Configure OAuth Client in Google API Console

Next, will be taken to the next screen, click on Download client configuration. The credentials.json file will be downloaded.

Download Client Credentials

The contents of the credentials.json file are as follows:

{"web":
	{
		"client_id":"<client_id>",
		"project_id":"<project_id>",
		"auth_uri":"https://accounts.google.com/o/oauth2/auth",
		"token_uri":"https://oauth2.googleapis.com/token",
		"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs"
		"client_secret":"<client_secret>"
	}
}

From this you need to take the values <client_id>, <project_id>, <client_secret> – open the google-services.json file in the downloaded project and replace its content with the following:

{
   "project_info":
      {
         "project_number": "1",
         "project_id": "<project_id>"
      },
   "client": [
   {
      "client_info":
   {
      "mobilesdk_app_id": "1:1:android:1556016075905",
      "android_client_info":
   {
      "package_name": "com.examples.registration_and_login.login"
   }
   },
      "oauth_client":
      [
         {
            "client_id": "<client_id>",
            "client_type": 1,
            "android_info": {
            "package_name": "com.examples.registration_and_login.login",
            "certificate_hash": "<client_secret>"
            }
         }
      ],
      "api_key": [
         {
            "current_key": "<client_secret>"
         }
      ]
   }
   ],
   "configuration_version": "1"
}

Then you need to go to values / strings.xml and replace two strings:

<string name = “gp_WebApp_ClientId”> </ string>
<string name = “gp_WebApp_ClientSecret”> </ string>

to:

<string name = “gp_WebApp_ClientId”> <client_id> </ string>
<string name = “gp_WebApp_ClientSecret”> <client_secret> </ string>

Test Google Login

Now you can bring down the project and run it.

Login with Google App

Before you click the Login button, log in to your Google account on your phone. After logging into your Google account on your phone, return to the application and press the Login button. After a successful login, you will see the following screen:

Completed Login with Google Screen

That’s all, now your application’s Android users can log in using their Google account. Enjoy using Backendless services!

Leave a Reply