1️⃣ Getting started
In this short guide, you will learn how to integrate the Keyless SDK in your Android or iOS mobile application, and enroll and authenticate users through the Keyless platform.
Before jumping into your code editor, make sure that you're familiar with the various components of the authentication system, and common biometic authentication flows.
Prerequisites
Make sure you have both required API keys, and the list of productions hosts from your Keyless contact:
YOUR_CLOUDSMITH_TOKENto download the SDK from cloudsmith repositoryKEYLESS_API_KEYto configure the mobile SDKKEYLESS_HOSTSa list of node URLs. Urls inKEYLESS_HOSTSmust NOT contain any trailing slashes/.
Review the Keyless SDK requirements:
The Keyless SDK uses
Android 6.0 (API level 23) and above
Installation
To allow Keyless to handle the result of registerForActivityResult, you must call Keyless from an Activity implementing ActivityResultCaller.
Extend any androidX activity that implements the interface for you, for example let your Activity extend the generic ComponentActivity or the more widespread AppCompatActivity.
If you use Proguard, add the following rules to your Proguard configuration file:
# Keyless Proguard -keep class io.keyless.sdk.** {*;} -keepclassmembers class io.keyless.sdk.** {*;}In the the
repositoriessection of thesettings.gradlefile of your Android application, add the following snippet, replacingYOUR_CLOUDSMITH_TOKENwith the CloudSmith token provided to you by Keyless.dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() maven { url "https://dl.cloudsmith.io/YOUR_CLOUDSMITH_TOKEN/keyless/partners/maven/" } } }In the
dependenciesblock of your projectbuild.gradlefile, typicallyapp/build.gradle, add:dependencies { // ... implementation 'io.keyless:keyless-android-sdk:+' }In the
androidblock of your projectbuild.gradlefile, typicallyapp/build.gradle, make sure you have the following options:android { // ... compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } // add the following only if you're using Kotlin kotlinOptions { jvmTarget = "1.8" } }
Essential configuration
There is some essential configuration to do before you can use the Keyless SDK.
Initialize the Keyless SDK in your
Applicationclass:// MainApplication override fun onCreate() { super.onCreate() // Initialize Keyless Keyless.initialize(this) }
If your application crashes due to java.lang.IllegalStateException: Attempting to launch an unregistered ActivityResultLauncher or while using React/Native bridges you can't receive a completion result at the end of an enrollment, it may be due to a difference between your applicationId and the namespace of your activities.
In such case, the Keyless.initialize(...) accepts a second parameter which is the namespace you are currently using for your Activities. Providing this parameter should fix the issue.
Example:
namespace: my.app.test
applicationId: my.app.test.extra
// MainApplication
override fun onCreate() {
super.onCreate()
// Initialize Keyless
Keyless.initialize(this, "my.app.test")
}Since we only check that the namespace of the Activity contains the namespace provided as input, .app or my.app are also valid inputs.
Add your application to the Manifest
<application ... android:name=".MainApplication" ... </application>Configure the Keyless SDK from your
MainActivity,ViewModelor any class you use to communicate withKeyless. Note thatconfigureis asynchronous so wait for the completion callback before calling the next Keyless APIsThe
configuremethod requires aSetupConfigas parameter, as well as theKEYLESS_API_KEYandKEYLESS_HOSTSyou received from Keyless. You should listen to the result as follows:val setupConfig = SetupConfig( apiKey = "KEYLESS_API_KEY", hosts = listOf("KEYLESS_HOSTS") ) Keyless.configure(setupConfig) { result -> when (result) { is Keyless.KeylessResult.Success -> { Log.d("KeylessSDK", "configure success") // Keyless is ready, you can now call // enroll/authenticate/deEnroll ... } is Keyless.KeylessResult.Failure ->{ Log.d("KeylessSDK", "configure error") // Inspect result.error for more info } } }
Additional configuration
As well as the essential configuration parameters, you can also specify the optional configuration parameters detailed in the following sections. Details of these configuration options can be summarised in the relevant sections throughout the Mobile SDK (i.e. Logging, Liveness Settings etc.) and you can inspect the Config class to see optional parameters (or the builder to see exposed methods). Some of the more the more generic configurations are described below for convenience.
Shared circuits
This is the target desired number of circuits kept on the server. To set this number use the numberOfSharedCircuits.
Networking module
If you need to perform network requests on behalf of the Keyless SDK, you can implement the KLNetworkingModule interface. Set the networkingModule parameter with an instance of the KLNetworkingModule:
public interface KLNetworkingModule {
public fun sendHTTPRequest(
baseUrl: String,
path: String,
method: String,
headers: Map<String, String>,
body: String
): KLHTTPResponse
public data class KLHTTPResponse(
val errorCode: Int,
val httpCode: Int,
val responseBody: String
)
}Last updated
Was this helpful?