-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow overriding biometric reauth logic in latte
- Loading branch information
Showing
3 changed files
with
50 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
sdk/src/main/java/com/oursky/authgear/latte/ReauthenticateBiometricCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.oursky.authgear.latte | ||
|
||
import androidx.biometric.BiometricPrompt | ||
import com.oursky.authgear.BiometricPromptAuthenticationException | ||
import com.oursky.authgear.isBiometricCancelError | ||
import com.oursky.authgear.wrapException | ||
|
||
interface ReauthenticateBiometricCallback { | ||
|
||
@JvmDefault | ||
fun onAuthenticationFailed(complete: FlowCompletor) { | ||
// This callback will be invoked EVERY time the recognition failed. | ||
// So while the prompt is still opened, this callback can be called repetitively. | ||
// Finally, either onAuthenticationError or onAuthenticationSucceeded will be called. | ||
// So this callback is not important to the developer. | ||
} | ||
|
||
@JvmDefault | ||
fun onAuthenticationError( | ||
errorCode: Int, | ||
errString: CharSequence, | ||
complete: FlowCompletor | ||
) { | ||
if (isBiometricCancelError(errorCode)) { | ||
return | ||
} | ||
complete( | ||
Result.failure( | ||
wrapException( | ||
BiometricPromptAuthenticationException( | ||
errorCode | ||
) | ||
) | ||
) | ||
) | ||
} | ||
|
||
@JvmDefault | ||
fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult, complete: FlowCompletor) { | ||
complete(Result.success(true)) | ||
} | ||
} | ||
|
||
typealias FlowCompletor = (Result<Boolean>) -> Unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters