[Google Login Plugin] How to Configure the Google Plus Login Plugin for Android

[Google Login Plugin] How to Configure the Google Plus Login Plugin for Android

  
Forge Component
(6)
Published on 6 Jul by OutSystems Labs
6 votes
Published on 6 Jul by OutSystems Labs

With the Google Plus Login, you can integrate a Google login plugin in your application, easing the login process, and making it unnecessary to create a new account.

Follow the steps below to configure the Google Plus login plugin.

1. Go to the Google API Manager console and log in using your Google credentials.

2. Create a new project.


3. Enter your app's name in the name input.

4. Select and enable the Google + API.


5. Click the Create credentials button.


6. Add credentials to your project.
    a. Select Google+ API in the kind of credentials you need.
    b. Select Web server (e.g. node js, Tomcat) as the setting you'll need to configure.
    c. Choose User data as the data you will be accessing.
    d. Click the What credentials do I need? button.


7. Add authorized redirect URIs.
    a. To authorize all the URLs from the server, add “/*” in Authorized redirect URIs.
    b. To authorize a specific app, add to the URL, the application name and in the end, add “/*” to authorize all application screens.


8. Add the product name that the users will see.


9. Save the Client ID. You will need it during the Android configuration.
Click Done.


The following steps are Android-specific.

1.  Go to Enable Google services for your Android app.

2. Choose the App Name (this should be the same name that you gave to the project), and enter the application identifier (the same as your iOS certificate).

3. Open the command line as Administrator, from the C:\Program Files\Java\<java folder name>\bin directory, and write the following command to generate a release Android certificate (if you want a build for debug mode follow this):

keytool -genkey -v -keystore {my-release-key}.keystore -alias {alias_name} -keyalg RSA -keysize 2048 -validity 10000

a. Replace {my-release-key} with your project name, and {alias_name} with your application name, for example.
b. Save these credentials, to later generate a native build in the Development Environment.
c. You will be asked for a password, your first and last name, your organizational unit, your organizational city, your state and your country. Then you will need to confirm the inserted data and to enter the password you previously defined.
d. The certificate will be created in the following directory: C:\Program Files\Java\<java folder name>\bin.

 

4. After the certificate is generated, you will need to extract the SHA1 to continue the Google Plus Android configuration. Write the following command line:

keytool -list -v -keystore {keystore_file_path}

a. Replace {keystore_file_path} with the path to the generated certificate.


5. Copy the SHA1 and return to the browser. Paste de SHA1 in the Android Signing Certificate SHA-1 field.


6. Click the Enable Google Sign-in button. The Android configuration is now available in the Dashboard.

7. Go to Service Studio, open the Native Builder for Android and fill in the fields:
    a. App identifier: Same as iOS.
    b. Keystore: Select the generated certificate.
    c. Enter the password that you defined when the certificate was generated.
    d. Enter the alias name defined.
    e. Enter the password again.
    f. Don’t generate the app yet.


8. Open the application module where you want to use Google Login Plugin and add the following JSON to the Extensibility Configuration. This field is mandatory.

9. Add the following Extensibility configuration:
"
{
    "plugin":
        {
            "url": "https://github.com/EddyVerbruggen/cordova-plugin-googleplus#5.0.3"
        }
}
"

10. Return to the browser, copy the Client ID from WebClient1. You will need it later.

11. Reference all actions from the GoogleLoginPlugin. Drag the GoogleLogin action to your client side login action.

12. Define the following parameters, only two are mandatory:

  • IsSilent: Check if the user is already signed in to the app and sign them in silently if they are. You should use the default: False. Change it to True, only if you are sure that the user is already logged in through Google Login.

  • Scopes: The default scopes requested are the profile and the email. To request other scopes, add them as a space-separated list. Refer to the Google Scopes documentation for info on valid scopes that can be requested. Default:
    "https://www.googleapis.com/auth/plus.login
    https://www.googleapis.com/auth/userinfo.email
    https://www.googleapis.com/auth/plus.me 
    https://www.googleapis.com/auth/userinfo.profile"

  • ClientId: It's the webClientId value from your Google account/project. It identifies the target account to log in to. This field is mandatory.

  • Offline: Optional, but requires the ClientId. If set to True the plugin will also return a serverAuthCode, which can be used to grant offline access to a non-Google server.

  • ForceApprovalPrompt: Forces the permission popup to appear in each login. Default value: False.

  • IsMapUsers: If True, it means that you want to map the user between the client and the server side. This field is mandatory.

  • OneToOneEmailMapping: Ensures that the given email only matches one user on the server database. Default value: False.

  • CreateGoogleUsers: Ensures that the plugin can create a server user to matches the given email if no user is found.

13. The GoogleLogin action validates the Google account, however, if you want a system login you should code that. Google Core provides you with an action to do that, and it’s explained above.

14. Reference Google Core actions and drag ValidateAndLoginGoogleUser action after the GoogleLogin action.
ValidateAndLoginGoogleUser has the following input parameters: 

  • IdToken: GoogleLogin action returns an IdToken when it’s successful.
  • UserId: GoogleLogin user ID.
  • IsPersistent: If True, the login will be persistent for 15 days.

16. After you call this action, your user is logged in using the OutSystems login, so you can GrantRoles and manage it as you want.

17. The Google Login Plugin is ready. Publish your app.