Solving a Real-Life Challenge - How OMH Enabled Google Authentication for WordPress on Non-GMS Devices

Solving

November 2 2023

Introduction:

At Open Mobile Hub (OMH), we’re often asked how our platform can be applied to resolve real-world problems faced by application developers. One such issue involves the integration of Google Authentication in non-Google Mobile Services (GMS) devices. In this article, we’ll share a success story that showcases how OMH stepped in to tackle this challenge and support WordPress, a globally renowned content management system.

WordPress - The World’s Leading CMS:

Before delving into the solution, it’s essential to understand the significance of WordPress. As the most widely used content management system (CMS) worldwide, it powers millions of websites. However, WordPress was grappling with a significant issue – Google Authentication on non-GMS devices wasn’t functioning as expected. This hurdle posed a potential setback for countless users and site owners.

The Google Authentication Conundrum:

At the core of this challenge lay Google Authentication, a cornerstone for securely accessing WordPress accounts. While this service flawlessly operated on devices integrated with Google Mobile Services, the same couldn’t be said for non-GMS devices. This discrepancy results in frequent authentication failures, hindering smooth user experience.

OMH

OMH’s Solution for WordPress:

WordPress needed a reliable solution to ensure that Google Authentication worked seamlessly across all devices, regardless of whether they were GMS or non-GMS. The OMH team took the challenge head-on, and we’re excited to share the results.

Introducing the OMH GitHub Repository for WordPress:

For transparency and ease of implementation, we’ve made the solution available on our GitHub repository. Developers and stakeholders can explore the sample code, access documentation, and understand how OMH bridged the gap for WordPress. It is important to note that while this solution demonstrates a viable approach, it has not yet been incorporated into the official WordPress codebase. The WordPress team will need to review, test, and potentially modify the solution before it can be officially integrated and made available to the wider WordPress community.

https://github.com/openmobilehub/WordPress-Android

Steps to Resolve the Authentication Challenge:

In this article, we’ll guide you through the steps we took to address the Google Authentication limitations on non-GMS devices. Our primary aim was to demonstrate how straightforward it can be to adapt WordPress, ensuring its Google Authentication functionality remains consistent across diverse device ecosystems.

We believe that the WordPress case study is a testament to OMH’s practicality and its potential to address real-world challenges. By sharing this story, we hope to inspire developers and businesses to consider how OMH can empower their applications and provide a seamless user experience, regardless of the devices their users employ.

Code Deep Dive

Setting the Stage: Gradle Configuration

Before diving into the code, it’s crucial to set up your project to include the necessary dependencies for OMH. Add the following lines to your build.gradle file:

   android{
   // ... other configurations ...
     productFlavors{
        // Define your product flavors here
     }
   }
   dependencies {
        // ... other dependencies ...
        implementation 'com.openmobilehub.android:auth-api:1.0.1-beta'
   }

This configuration ensures that your project recognizes OMH and is ready to utilize its authentication capabilities.

Acquiring the OMH Client: Dependency Injection

To interact with OMH, you need an instance of OmhAuthClient. In a well-architected Android application, dependency injection is a preferred method to acquire such instances. Here’s how you can inject OmhAuthClient into your LoginActivity:

   public class LoginActivity extends AppCompatActivity {
   @Inject OmhAuthClient mOmhAuthClient;
   // ... rest of your code ...
   }

Ensure that your activity is part of your dependency injection setup, typically using Dagger or Hilt, to inject the OmhAuthClient instance.

The Authentication Journey

With OMH configured and the client injected, let’s delve into the authentication flow.

1. onCreate: Initializing the Activity

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super. onCreate(savedInstanceState);
      setContentView(R.layout.login_activity);

      if (mOmhAuthClient.getUser() != null) {
         navigateToLoggedIn();
      } else {
         checkSmartLockPasswordAndStartLogin();
      }
   }

In onCreate, the activity checks if the user is already authenticated via OMH. If authenticated, it navigates directly to the logged-in state. Otherwise, it proceeds to check for Smart Lock credentials or initiate the login process.

2. checkSmartLockPasswordAndStartLogin: Handling Smart Lock Credentials

   private void checkSmartLockPasswordAndStartLogin() {
      // Initialize Smart Lock and check for saved credentials
      // ...
      
      startLogin();
   }

This method attempts to streamline the login process by checking for saved credentials. If none are found or the user opts not to use them, it falls back to the standard login process.

3. startLogin: Initiating the Login Process

   private void startLogin() {
      if (getLoginEmailFragment() != null) {
         return; // Login already in progress
      }

      if (getLoginPrologueFragment() == null && getLoginPrologueRevampedFragment () == null) {
         showFragment(LoginEmailFragment.newInstance(mIsSignupFromLoginEnabled),
   LoginEmailFragment. TAG);
      } else {
         startOmhLogin();
      }    
   }

Here, the app decides between continuing with the standard login flow or initiating the OMH login process, based on the visibility of prologue fragments.

4. startOmhLogin: Integrating OMH for Non-GMS Devices

   private void startOmhLogin() {
      Intent loginIntent = mOmhAuthClient.getLoginIntent();
      mLoginLauncher.launch(loginIntent);
   }

This method is the crux of the OMH integration, allowing users on non-GMS devices to authenticate using their Google accounts.


Conclusion:

OMH’s proposed collaboration with WordPress underscores our dedication to delivering versatile and robust solutions. We have submitted code changes for integration, aiming to enhance the user experience by ensuring seamless Google Authentication on WordPress across both GMS and non-GMS devices, irrespective of the device’s ecosystem. These contributions are currently under review, and we are eagerly awaiting their potential incorporation into the WordPress platform.

Stay tuned for more stories on how OMH continues to make a difference in the world of mobile applications and services.

OMH

Fork our samples and try them yourself.

Thank you for reading this OMH SDK article! We hope that you are enjoying this series. We are open to any open-source contributors of this project, please contact us at contact@openmobilehub.com if you are interested in joining the unified mapping revolution now! For more insights into the philosophy behind OMH, visit our official website: https://developer.openmobilehub.com/

To get started, visit: https://github.com/openmobilehub/omh-auth

#openmobilehub #omh #wordpress