Skip to content

Commit

Permalink
Merge pull request #26 from icerockdev/develop
Browse files Browse the repository at this point in the history
Release 0.4.0
  • Loading branch information
Alex009 authored Jul 31, 2023
2 parents 5589209 + 128f858 commit 94afcab
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ project build.gradle

```groovy
dependencies {
commonMainApi("dev.icerock.moko:biometry:0.3.0")
commonMainApi("dev.icerock.moko:biometry:0.4.0")
// Compose Multiplatform
commonMainApi("dev.icerock.moko:biometry-compose:0.3.0")
commonMainApi("dev.icerock.moko:biometry-compose:0.4.0")
// Jetpack Compose (only for android, if you don't use multiplatform)
implementation("dev.icerock.moko:biometry-compose:0.3.0")
implementation("dev.icerock.moko:biometry-compose:0.4.0")
}
```

Expand All @@ -69,7 +69,8 @@ class SampleViewModel(
val isSuccess = biometryAuthenticator.checkBiometryAuthentication(
requestTitle = "Biometry".desc(),
requestReason = "Just for test".desc(),
failureButtonText = "Oops".desc()
failureButtonText = "Oops".desc(),
allowDeviceCredentials = false // true - if biometric permission is not granted user can authorise by device creds
)

if (isSuccess) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ actual class BiometryAuthenticator(
actual suspend fun checkBiometryAuthentication(
requestTitle: StringDesc,
requestReason: StringDesc,
failureButtonText: StringDesc
failureButtonText: StringDesc,
allowDeviceCredentials: Boolean
): Boolean {
val resolverFragment: ResolverFragment = getResolverFragment()

Expand All @@ -52,7 +53,7 @@ actual class BiometryAuthenticator(
requestTitle = requestTitle,
requestReason = requestReason,
failureButtonText = failureButtonText,
credentialAllowed = true
credentialAllowed = allowDeviceCredentials
) {
if (!resumed) {
continuation.resumeWith(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ expect class BiometryAuthenticator {
* @param requestReason - Text describing the reason for confirmation via biometrics
* @param failureButtonText - Text of the button to go to the backup verification method in
* case of unsuccessful biometrics recognition
* @param allowDeviceCredentials - Boolean value of device credentials availability,
* if biometric permission is not granted user can authorise by device passcode
*
* @throws Exception if authentication failed
*
Expand All @@ -24,7 +26,8 @@ expect class BiometryAuthenticator {
suspend fun checkBiometryAuthentication(
requestTitle: StringDesc,
requestReason: StringDesc,
failureButtonText: StringDesc
failureButtonText: StringDesc,
allowDeviceCredentials: Boolean = true
): Boolean

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,22 @@ actual class BiometryAuthenticator constructor() {
actual suspend fun checkBiometryAuthentication(
requestTitle: StringDesc,
requestReason: StringDesc,
failureButtonText: StringDesc
failureButtonText: StringDesc,
allowDeviceCredentials: Boolean
): Boolean {
val laContext = LAContext()
laContext.setLocalizedFallbackTitle(failureButtonText.localized())

val policy = if (allowDeviceCredentials) {
LAPolicyDeviceOwnerAuthentication
} else {
LAPolicyDeviceOwnerAuthenticationWithBiometrics
}

val (canEvaluate: Boolean?, error: NSError?) = memScoped {
val p = alloc<ObjCObjectVar<NSError?>>()
val canEvaluate: Boolean? = runCatching {
laContext.canEvaluatePolicy(LAPolicyDeviceOwnerAuthentication, error = p.ptr)
laContext.canEvaluatePolicy(policy, error = p.ptr)
}.getOrNull()
canEvaluate to p.value
}
Expand All @@ -37,7 +44,7 @@ actual class BiometryAuthenticator constructor() {

return callbackToCoroutine { callback ->
laContext.evaluatePolicy(
policy = LAPolicyDeviceOwnerAuthentication,
policy = policy,
localizedReason = requestReason.localized(),
reply = mainContinuation { result: Boolean, error: NSError? ->
callback(result, error)
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ coroutinesVersion = "1.6.4"
composeJetBrainsVersion = "1.3.1"
mokoResourcesVersion = "0.21.1"
mokoMvvmVersion = "0.16.0"
mokoBiometryVersion = "0.3.0"
mokoBiometryVersion = "0.4.0"

[libraries]
appCompat = { module = "androidx.appcompat:appcompat", version.ref = "androidAppCompatVersion" }
Expand Down

0 comments on commit 94afcab

Please sign in to comment.