Skip to content

omh-pl/omh-core

 
 

Repository files navigation

Discord Apache-2.0

Android CI

OMH (Open Mobile Hub) - Core

Overview

OMH is an Android SDK, available as open-source, that simplifies the process of swapping services such as Maps & Location, Sign-in, Storage, and more, for both Android GMS and Non-GMS devices.

It aims at creating low coupled, extensible SDK reducing the code boilerplate of switching between GMS, Non-GMS, or any other service, and also provides a custom full open source alternative services switching automatically according to your configuration in the Gradle plugin giving the right outputs without overloading your APK with unnecessary libraries.

OMH - Core

The OMH Core is a Gradle plugin that allows developers to configure, enable and set-up the OMH SDK in their projects.This plugin automatically implements the necessary dependencies and enable the custom-build variants to allow you compile the different builds to use the defined providers.

Installation

Go to your app build.gradle file and add the following:

plugins {
    ...
    id 'omh-core'
}

...

omhConfig {
    bundle('worldwide') {
        it.auth {
            addGmsService 'com.omh.android:auth-api-gms:1.0-SNAPSHOT'
            addNonGmsService 'com.omh.android:auth-api-non-gms:1.0-SNAPSHOT'
        }
    }

    bundle('gmsStore') {
        it.auth {
            addGmsService 'com.omh.android:auth-api-gms:1.0-SNAPSHOT'
        }
    }

    bundle('nonGmsStore') {
        it.auth {
            addNonGmsService 'com.omh.android:auth-api-non-gms:1.0-SNAPSHOT'
        }
    }
}

You can also see this video:

plugin_installation.mp4

Usage

Step 1: Create an instance of OmhAuthClient

private val omhAuthProvider = OmhAuthProvider.Builder()
    .addGmsPath(BuildConfig.AUTH_GMS_PATH)
    .addNonGmsPath(BuildConfig.AUTH_NON_GMS_PATH)
    .build()        
private val omhAuthClient = omhAuthProvider.provideAuthClient(
    scopes = listOf("openid", "email", "profile"),
    clientId = "YOUR_CLIENT_ID",
    context = applicationContext
)

Step 2: Start using some functions

In you sample app, perform the authentication

private fun startLogin() {
    val loginIntent = omhAuthClient.getLoginIntent()
    loginLauncher.launch(loginIntent)
}

If the authentication is successful, then navigate to your desired screen

private val loginLauncher: ActivityResultLauncher<Intent> =
    registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
        try {
            omhAuthClient.getAccountFromIntent(result.data)
            navigateToLogIn()
        }  catch (exception: OmhAuthException) {
            val errorMessage = OmhAuthStatusCodes.getStatusCodeString(404)
        }
    }

You can also see the video:

plugin_usage.mp4

Documentation

See example and check the full documentation at our Wiki.

Contributing

We'd be glad if you decide to contribute to this project.

All pull requests are welcome, just make sure that every work is linked to an issue on this repository so everyone can track it.

Common issue: There is an certain error when using gradle 8.0

  • Add this code
packagingOptions {
    exclude("META-INF/DEPENDENCIES")
}

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 97.9%
  • Shell 2.1%