Getting started
In this guide, you will learn how to integrate the Keyless SDK in your mobile application. Keyless SDK enables you to enroll and authenticate users through the Keyless platform.
Since Keyless has more advanced features than just a simple authentication product, the guide is split into multiple functional sections with more details, with proper code snippets and examples for both iOS and Android.
For any questions or comments (at any time) during the integration phase please reach out to your primary Keyless contact or to [email protected]
Android
iOS
To allow Keyless to handle the result of registerForActivityResult, you must call Keyless from an Activity implementing ActivityResultCaller. Your best option is to 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 Progurad add the following rules:
# Keyless Proguard
-keep class io.keyless.sdk.** {*;}
-keepclassmembers class io.keyless.sdk.** {*;}
Install the following:
- Xcode 10.1 or later
- CocoaPods 1.4.0 or later
- Make sure that your project meets the following requirements:
- Your project must target iOS 13 or later.
- Swift projects must use Swift 4.0 or later.
- Set up a physical iOS device for running your app.
- Enable Camera permissions: add the
Privacy - Camera Usage Description
key in your project’sInfo.plist
by adding the following (in XCode under Project > Info):
<key>NSCameraUsageDescription</key>
<string>Keyless needs access to your camera to enroll and authenticate you. Keyless cannot be used without your camera. Please allow camera permissions.</string>
- Background processing. Enable the
Background processing
mode underSigning & Capabilities/Background Modes
. Then, add the following in your project’sInfo.plit
(in XCode, under the keyPermitted background task scheduler identifiers
):<key>NSCameraUsageDescription</key><key>BGTaskSchedulerPermittedIdentifiers</key><array><string>YOUR APP IDENTIFIER</string></array>
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.dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven {
url "https://dl.cloudsmith.io/YOUR_CLOUDSMITH_TOKEN/keyless/partners/maven/"
}
}
}
Add the following to the
dependencies
block of your project build.gradle
file, typically app/build.gradle
.app/build.gradle
dependencies {
// ...
implementation 'io.keyless:keyless-android-sdk:+'
}
Make sure you have the following options in the
android
block of the same fileapp/build.gradle
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"
}
}
Step 1: Create a Podfile if you don’t already have one
$ cd your-project-directory
$ pod init
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.git config --global credential.helper store
echo "https://token:[email protected]" >> ~/.git-credentials
Step 3: Add the KeylessSDK pod to your
Podfile
# This is the Keyless repository for partners
source 'https://dl.cloudsmith.io/basic/keyless/partners/cocoapods/index.git'
target 'MyApp' do
use_frameworks!
# Add the Keyless pod
pod 'KeylessSDK'
end
Step 4: Add the following at the bottom of the same file
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
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.
$ pod install
Analyzing dependencies
Cloning spec repo `cloudsmith-basic-keyless-partners-cocoapods-index` from `https://dl.cloudsmith.io/basic/keyless/partners/cocoapods/index.git`
Username for 'https://dl.cloudsmith.io': token
Password for 'https://dl.cloudsmith.io': YOUR_CLOUDSMITH_TOKEN
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:// MainApplication
override fun onCreate() {
super.onCreate()
// Initialize Keyless
Keyless.initialize(this)
}
Make sure to add your application to you Manifest
<application
...
android:name=".MainApplication"
...
</application>
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 next Keyless APIs
The
configure
method requires aSetupConfiguration
as parameter. You should listen to the result as follows:val setupConfiguration = SetupConfiguration.builder
.withApiKey("apiKey")
.withHosts(listOf("host"))
.build()
Keyless.configure(setupConfiguration) { 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
}
}
}
All you need to do to configure the Keyless SDK, is to create an instance object of
Keyless.SetupConfiguration
and pass it to the Keyless.configure
method, typically this in done in your app’s application(:didFinishLaunchingWithOptions: method:).
let setupConfiguration = Keyless.SetupConfiguration.builder
.withApiKey("apiKey")
.withHosts(["host"])
.build()
if let error = Keyless.configure(configuration: setupConfiguration) {
print("Keyless.Configure failed with error: \(error)")
}
Last modified 5d ago