Getting started

Let's get started!

In this getting started guide, we will add the Keyless SDK to your Mobile application project. This will allow you to enroll and authenticate users with Keyless.

Prerequisites

Android
Android 6.0 (API level 23) and above
Gradle 6.5+
AndroidX
NOTE: to allow Keyless to handle the result of registerForActivityResult, you must call Keyless from an Activity implementing ActivityResultCaller. Your best option should be to extend any androidX activity that implements the interface for you, for example use the generic ComponentActivity or the more widespread AppCompatActivity
If you use Progurad add the following rules:
1
# Keyless Proguard
2
-keep class io.keyless.sdk.** {*;}
3
-keepclassmembers class io.keyless.sdk.** {*;}
Copied!

Installation

Android - Gradle
iOS - Cocoapods
Add the following within the repositories section of the settings.gradle file of your Android application. Replace the YOUR_CLOUDSMITH_TOKEN text with the CloudSmith token for partners provided to you by Keyless.
1
dependencyResolutionManagement {
2
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
3
repositories {
4
google()
5
mavenCentral()
6
maven {
7
url "https://dl.cloudsmith.io/YOUR_CLOUDSMITH_TOKEN/keyless/partners/maven/"
8
}
9
}
10
}
Copied!
Add the following to the dependencies block of your project build.gradle file, typically app/build.gradle.
app/build.gradle
1
dependencies {
2
// ...
3
4
implementation 'io.keyless:keyless-android-sdk:+'
5
}
Copied!
Make sure you have the following options in the android block of the same file
app/build.gradle
1
android {
2
// ...
3
4
compileOptions {
5
sourceCompatibility JavaVersion.VERSION_1_8
6
targetCompatibility JavaVersion.VERSION_1_8
7
}
8
9
// add the following only if you're using Kotlin
10
kotlinOptions {
11
jvmTarget = "1.8"
12
}
13
}
Copied!
Step 1: Create a Podfile if you don’t already have one
1
$ cd your-project-directory
2
$ pod init
Copied!
Step 2: Setup Cocoapods to use your Cloudsmith credentials, by running the following commands and replacing YOUR_CLOUDSMITH_TOKEN with the Cloudsmith token for partners provided you by Keyless.
1
git config --global credential.helper store
2
echo "https://token:[email protected]" >> ~/.git-credentials
Copied!
Step 3: Add the KeylessSDK pod to your Podfile
1
# This is the Keyless repository for partners
2
source 'https://dl.cloudsmith.io/basic/keyless/partners/cocoapods/index.git'
3
4
target 'MyApp' do
5
use_frameworks!
6
7
# Add the Keyless pod
8
pod 'KeylessSDK'
9
end
Copied!
Step 4: Add the following at the bottom of the same file
1
post_install do |installer|
2
installer.pods_project.targets.each do |target|
3
target.build_configurations.each do |config|
4
config.build_settings['ENABLE_BITCODE'] = 'NO'
5
end
6
end
7
end
Copied!
Step 5: Install the pods. If pod prompts you for authentication insert the string token as your username and then fill in YOUR_CLOUDSMITH_TOKEN as the password.
1
$ pod install
2
3
Analyzing dependencies
4
Cloning spec repo `cloudsmith-basic-keyless-partners-cocoapods-index` from `https://dl.cloudsmith.io/basic/keyless/partners/cocoapods/index.git`
5
Username for 'https://dl.cloudsmith.io': token
6
Password for 'https://dl.cloudsmith.io': YOUR_CLOUDSMITH_TOKEN
Copied!

Configuration

Now all the dependencies should be set. To start using the Keyless SDK you just need to configure it.
Android
iOS
First initialize the Keyless SDK in your Application class:
1
// MainApplication
2
override fun onCreate() {
3
super.onCreate()
4
// Initialize Keyless
5
Keyless.initialize(this)
6
}
Copied!
Make sure to add your application to you Manifest
1
<application
2
...
3
android:name=".MainApplication">
4
...
5
</application>
Copied!
Then configure the Keyless SDK from your MainActivity, ViewModel or any class you use to communicate with Keyless.
Note: configure is asynchronous so wait for the completion callback before calling the nexts Keyless APIs
The configure method requires aSetupConfiguration as parameter. You should listen to the result as follows:
1
val setupConfiguration = SetupConfiguration.builder
2
.withApiKey("apiKey")
3
.withHosts(listOf("host_1:port_1", "host_2:port_2", "host_3:port_3"))
4
.build()
5
6
Keyless.configure(setupConfiguration) { result ->
7
when (result) {
8
is Keyless.KeylessResult.Success -> {
9
Log.d("KeylessSDK", "configure success")
10
// Keyless is ready, you can now call
11
// enroll/authenticate/deEnroll ...
12
}
13
is Keyless.KeylessResult.Failure ->{
14
Log.d("KeylessSDK", "configure error")
15
// Inspect result.error for more info
16
}
17
}
18
}
Copied!
All you need to do to configure the Keyless SDK, is to create an instance object of Keyless.Configuration and pass it to the Keyless.configure method, typically this in done in your app’s application(:didFinishLaunchingWithOptions: method:).
1
let configuration = Keyless.SetupConfiguration.builder
2
.withApiKey("apiKey")
3
.withHosts(["host_1:port_1", "host_2:port_2", "host_3:port_3"])
4
.build()
5
6
if let error = Keyless.configure(configuration: configuration) {
7
print("Keyless.Configure failed with error: \(error)")
8
}
Copied!