
Enables biometric authentication and secure data storage using fingerprint on Android and FaceID on iOS. Features include encrypted storage of sensitive information and seamless integration in applications.
Biometric Authenticator is a Kotlin Multiplatform library designed to provide seamless biometric authentication, supporting fingerprint on Android and FaceID on iOS.
Biometric Authentication: Restrict access to sensitive logic using biometric authorization.
Encrypted Storage: Securely store sensitive data such as passwords, tokens, and more.
Add the following dependency to your Kotlin Multiplatform project:
dependencies {
implementation("io.github.zaval:biometricauth:<latest-version>")
}Replace with the latest version available on Maven Central.
Use FragmentActivity instead of AppCompatActivity in main activity class parent.
Add NSFaceIDUsageDescription key in Info.plist file of your project
<key>NSFaceIDUsageDescription</key>
<string>Privacy - Face ID Usage Description</string>Authenticate users with biometric authentication:
@Composable
fun AuthPage() {
val biometricAuthHelper = rememberBiometricAuthHelper()
Button(
onClick = {
biometricAuthHelper.authenticate(
onFailure = {errorMessage ->
println(errorMessage)
},
) {
// Execute authorized code here
}
}
) {
Text("Login with Biometric")
}
}@Composable
fun AuthPage() {
val biometricAuthHelper = rememberBiometricAuthHelper()
Button(
onClick = {
biometricAuthHelper.authenticate(
onFailure = {errorMessage ->
println(errorMessage)
},
) {authStorage ->
// save some secret value
authStorage.setValue("token", "s3cretT0ken")
// read secret value
val token = authStorage.getValue("token")
}
}
) {
Text("Login with Biometric")
}
}val biometricAuthStorage = rememberBiometricAuthStorage {
println("Auth storage $it")
val accessToken = it.getValue("token")
// accessToken is a saved value
it.setValue("token", accessToken)
// Save accessToken to the encrypted storage
}rememberBiometricAuthHelper is a composable function that provides an instance of the BiometricAuthHelper. This helper is used to manage biometric authentication in a Kotlin Multiplatform project.
title: String: The title which displays in the authentication dialog presented to the user.subTitle: String: The title which displays in the authentication dialog presented to the user. (Visible on Android only)cancelText: String: Text for the Cancel button on the authentication dialogserver: String: The server string used by BiometricAuthStorage for storing secret valuesrememberBiometricAuthStorage is a composable function that provides an instance of the BiometricAuthStorage. This helper is used to access the encrypted key-value storage in a Kotlin Multiplatform project.
title: String: The title which displays in the authentication dialog presented to the user.subTitle: String: The title which displays in the authentication dialog presented to the user. (Visible on Android only)cancelText: String: Text for the Cancel button on the authentication dialogserver: String: The server string used by BiometricAuthStorage for storing secret valuesonFailure: (String) -> Unit: A callback invoked when authentication fails, providing an error message.The BiometricAuthHelper is the core class for managing biometric authentication.
authenticate(onFailure: (String) -> Unit, onSuccess: (BiometricAuthStorage) -> Unit)
onFailure: A callback invoked when authentication fails, providing an error message.onSuccess: A callback invoked upon successful authentication, providing access to BiometricAuthStorage.val biometricAuthHelper = rememberBiometricAuthHelper()
biometricAuthHelper.authenticate(
onFailure = { errorMessage ->
println("Authentication failed: $errorMessage")
},
onSuccess = { authStorage ->
println("Authentication successful!")
}
)The BiometricAuthStorage provides secure storage for sensitive data, accessible only after successful authentication.
setValue(key: String, value: String)
key: The identifier for the data.value: The data to be stored.getValue(key: String): String?
key: The identifier for the data.authStorage.setValue("token", "s3cretT0ken")
val token = authStorage.getValue("token")
println("Retrieved token: $token")androidx.biometric for authorizationEncryptedSharedPreferences to store secret valuesLocalAuthentication for authorizationKeychain to store secret valuesContributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
Copyright 2025 Dmytrii Zavalnyi.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Biometric Authenticator is a Kotlin Multiplatform library designed to provide seamless biometric authentication, supporting fingerprint on Android and FaceID on iOS.
Biometric Authentication: Restrict access to sensitive logic using biometric authorization.
Encrypted Storage: Securely store sensitive data such as passwords, tokens, and more.
Add the following dependency to your Kotlin Multiplatform project:
dependencies {
implementation("io.github.zaval:biometricauth:<latest-version>")
}Replace with the latest version available on Maven Central.
Use FragmentActivity instead of AppCompatActivity in main activity class parent.
Add NSFaceIDUsageDescription key in Info.plist file of your project
<key>NSFaceIDUsageDescription</key>
<string>Privacy - Face ID Usage Description</string>Authenticate users with biometric authentication:
@Composable
fun AuthPage() {
val biometricAuthHelper = rememberBiometricAuthHelper()
Button(
onClick = {
biometricAuthHelper.authenticate(
onFailure = {errorMessage ->
println(errorMessage)
},
) {
// Execute authorized code here
}
}
) {
Text("Login with Biometric")
}
}@Composable
fun AuthPage() {
val biometricAuthHelper = rememberBiometricAuthHelper()
Button(
onClick = {
biometricAuthHelper.authenticate(
onFailure = {errorMessage ->
println(errorMessage)
},
) {authStorage ->
// save some secret value
authStorage.setValue("token", "s3cretT0ken")
// read secret value
val token = authStorage.getValue("token")
}
}
) {
Text("Login with Biometric")
}
}val biometricAuthStorage = rememberBiometricAuthStorage {
println("Auth storage $it")
val accessToken = it.getValue("token")
// accessToken is a saved value
it.setValue("token", accessToken)
// Save accessToken to the encrypted storage
}rememberBiometricAuthHelper is a composable function that provides an instance of the BiometricAuthHelper. This helper is used to manage biometric authentication in a Kotlin Multiplatform project.
title: String: The title which displays in the authentication dialog presented to the user.subTitle: String: The title which displays in the authentication dialog presented to the user. (Visible on Android only)cancelText: String: Text for the Cancel button on the authentication dialogserver: String: The server string used by BiometricAuthStorage for storing secret valuesrememberBiometricAuthStorage is a composable function that provides an instance of the BiometricAuthStorage. This helper is used to access the encrypted key-value storage in a Kotlin Multiplatform project.
title: String: The title which displays in the authentication dialog presented to the user.subTitle: String: The title which displays in the authentication dialog presented to the user. (Visible on Android only)cancelText: String: Text for the Cancel button on the authentication dialogserver: String: The server string used by BiometricAuthStorage for storing secret valuesonFailure: (String) -> Unit: A callback invoked when authentication fails, providing an error message.The BiometricAuthHelper is the core class for managing biometric authentication.
authenticate(onFailure: (String) -> Unit, onSuccess: (BiometricAuthStorage) -> Unit)
onFailure: A callback invoked when authentication fails, providing an error message.onSuccess: A callback invoked upon successful authentication, providing access to BiometricAuthStorage.val biometricAuthHelper = rememberBiometricAuthHelper()
biometricAuthHelper.authenticate(
onFailure = { errorMessage ->
println("Authentication failed: $errorMessage")
},
onSuccess = { authStorage ->
println("Authentication successful!")
}
)The BiometricAuthStorage provides secure storage for sensitive data, accessible only after successful authentication.
setValue(key: String, value: String)
key: The identifier for the data.value: The data to be stored.getValue(key: String): String?
key: The identifier for the data.authStorage.setValue("token", "s3cretT0ken")
val token = authStorage.getValue("token")
println("Retrieved token: $token")androidx.biometric for authorizationEncryptedSharedPreferences to store secret valuesLocalAuthentication for authorizationKeychain to store secret valuesContributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
Copyright 2025 Dmytrii Zavalnyi.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.