Skip to content

feat(android): add confirmationRequired option to authenticationPrompt #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

quangsuong
Copy link

@quangsuong quangsuong commented May 16, 2025

🔥 Feature: Add confirmationRequired Option to Android Authentication Prompt

✨ Summary

This PR introduces a new optional field confirmationRequired in the authenticationPrompt config for Android. It allows developers to control whether the user must press an explicit confirmation (OK) button after biometric authentication.

By default, confirmationRequired is now set to false, enabling a faster, more seamless biometric UX unless explicitly overridden.


✅ Changes

Android Native:

  • KeychainModule.kt:
    • Reads confirmationRequired from authenticationPrompt.
    • Applies it to PromptInfo.Builder.setConfirmationRequired(...).
    • Default is now false (user does not need to confirm after authentication unless specified).

TypeScript Types:

  • Extended AuthenticationPrompt type to support:
confirmationRequired?: boolean;

@herbig
Copy link

herbig commented May 16, 2025

If you default this to true it will change the behavior of existing apps who upgrade to the latest version.

@quangsuong quangsuong force-pushed the feature/android-auth-confirmation-required branch from 487ae2c to a635a21 Compare May 16, 2025 15:10
@quangsuong
Copy link
Author

If you default this to true it will change the behavior of existing apps who upgrade to the latest version.

Thanks for the feedback! 🙌 I confused it with the default behavior in a project I’m currently working on. You’re absolutely right — I’ve updated the code to restore the default to false. Appreciate the heads-up!

@DorianMazur DorianMazur requested a review from Copilot May 24, 2025 21:43
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new confirmationRequired option to Android’s biometric auth prompt, defaulting to false for a faster UX.

  • Extend the TS AuthenticationPrompt type with confirmationRequired?: boolean.
  • Read the new field in KeychainModule.kt and apply it via PromptInfo.Builder.setConfirmationRequired().

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/types.ts Declare confirmationRequired?: boolean in AuthenticationPrompt
android/src/main/java/com/oblador/keychain/KeychainModule.kt Define and consume confirmationRequired when building the prompt
Comments suppressed due to low confidence (2)

android/src/main/java/com/oblador/keychain/KeychainModule.kt:783

  • Consider adding an Android unit/integration test to verify that confirmationRequired defaults to false and respects the override when set to true.
// Default is false — no confirmation required unless explicitly set

android/src/main/java/com/oblador/keychain/KeychainModule.kt:786

  • The code refers to AuthPromptOptions.CONFIRMATION_REQUIRED, but the constant is defined in the companion object of KeychainModule. Either move CONFIRMATION_REQUIRED into AuthPromptOptions or update this reference to use KeychainModule.CONFIRMATION_REQUIRED for consistency.
if (it.hasKey(AuthPromptOptions.CONFIRMATION_REQUIRED)) {

Comment on lines +784 to +789
var confirmationRequired = false
promptInfoOptionsMap?.let {
if (it.hasKey(AuthPromptOptions.CONFIRMATION_REQUIRED)) {
confirmationRequired = it.getBoolean(AuthPromptOptions.CONFIRMATION_REQUIRED)
}
}
Copy link
Preview

Copilot AI May 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify this block by using a single expression with a default value, e.g.: val confirmationRequired = promptInfoOptionsMap?.getBoolean(CONFIRMATION_REQUIRED) ?: false.

Suggested change
var confirmationRequired = false
promptInfoOptionsMap?.let {
if (it.hasKey(AuthPromptOptions.CONFIRMATION_REQUIRED)) {
confirmationRequired = it.getBoolean(AuthPromptOptions.CONFIRMATION_REQUIRED)
}
}
val confirmationRequired = promptInfoOptionsMap?.getBoolean(AuthPromptOptions.CONFIRMATION_REQUIRED) ?: false

Copilot uses AI. Check for mistakes.

@DorianMazur
Copy link
Collaborator

@herbig
Copy link

herbig commented May 25, 2025

@herbig Well, that's not really true. It defaults to true https://developer.android.com/reference/androidx/biometric/BiometricPrompt.PromptInfo.Builder#setConfirmationRequired(boolean)

RNC currently sets this field to false. @quangsuong was proposing to set this to true, unless the user sets the field in the RNC prompt props.

The Android API default isn't used in either case, since we're always setting it explicitly.

@quangsuong quangsuong closed this Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants