Authentication and biometric support for Kotlin Multiplatform.
- A common biometric API with availability checks and detailed authentication results.
- Platform biometric implementations:
- Android Biometric Prompt.
- Windows Hello on JVM and Kotlin/Native.
- Touch ID on macOS ARM64 and JVM on macOS ARM64.
fprintdon Linux JVM.
- PIN authentication with pluggable hashing and storage providers.
- A responsive Compose Multiplatform PIN and biometric authentication screen.
| Artifact | Description | Targets |
|---|---|---|
biometric |
Common biometric API and platform implementations | JVM, Android, macOS ARM64, mingwX64 |
auth |
PIN storage, hashing, and combined PIN/biometric authentication | JVM, Android |
auth-compose |
Compose Multiplatform authentication screen | JVM, Android |
Choose the highest-level module that your application needs. auth-compose exposes auth, and auth exposes biometric.
kotlin {
sourceSets {
commonMain.dependencies {
implementation("com.ucasoft.koncierge:biometric:0.2.0")
// Or:
// implementation("com.ucasoft.koncierge:auth:0.2.0")
// implementation("com.ucasoft.koncierge:auth-compose:0.2.0")
}
}
}On JVM, macOS ARM64, and mingwX64:
val koncierge = Koncierge()On Android, pass a FragmentActivity as the context:
val koncierge = Koncierge(activity)Create the platform instance at the application boundary and pass it to common code.
when (val result = koncierge.authenticate("Confirm your identity")) {
BiometricResults.AuthenticationSuccessful -> {
// Continue to protected content.
}
BiometricResults.AuthenticationCancelled -> {
// The request was cancelled.
}
else -> {
// Handle unavailable hardware, missing enrollment, lockout, or failure.
}
}Use koncierge.isBiometricAvailable() when you only need an availability check.
val authenticator = Authenticator(koncierge)
authenticator.storePinCode("1234")
if (authenticator.verifyPinCode("1234")) {
// PIN verified.
}By default, Authenticator hashes the PIN with SHA-256 and stores the result with Multiplatform Settings. Implement PinCodeHashProvider or PinCodeStoreProvider to use hashing and storage appropriate for your application's security requirements.
@Composable
fun LoginScreen(
authenticator: Authenticator,
onAuthorized: () -> Unit,
) {
AuthScreen(
authenticator = authenticator,
title = { Text("Koncierge") },
description = { Text("Authenticate to continue") },
onAuthorizationFailed = { method ->
// Handle a failed PIN or biometric attempt.
},
onAuthorized = onAuthorized,
)
}Biometric authentication is requested automatically when it is available. Set autoRequestBiometry = false to wait for the user to tap the biometric button.
- Android requires API 26 or newer. Pass a
FragmentActivitytoKoncierge. - JVM applications require Java 17 or newer.
- Linux JVM biometric authentication requires
fprintd-listandfprintd-verifyonPATH, with a fingerprint already enrolled. - The packaged macOS JVM native library currently supports ARM64.
- The packaged Windows JVM native library supports x86-64.
Koncierge is currently at version 0.2.0 and is under active development.
Koncierge is licensed under the Apache License 2.0.