ผสานรวมการสร้างพาสคีย์ด้วยการแตะเพียงครั้งเดียวและการลงชื่อเข้าใช้ด้วยพรอมต์ข้อมูลไบโอเมตริก

ใน Android 15 เครื่องมือจัดการข้อมูลเข้าสู่ระบบรองรับขั้นตอนการแตะเพียงครั้งเดียวสำหรับข้อมูลเข้าสู่ระบบ การสร้างและดึงข้อมูล ในขั้นตอนนี้ ข้อมูลของข้อมูลเข้าสู่ระบบที่สร้างหรือกำลังใช้จะแสดงในข้อความแจ้งข้อมูลไบโอเมตริกโดยตรง พร้อมกับจุดแรกเข้าสำหรับตัวเลือกเพิ่มเติม กระบวนการที่ไม่ซับซ้อนนี้ การสร้างและดึงข้อมูลรับรองที่มีประสิทธิภาพและประสิทธิผล

ข้อกำหนดมีดังนี้

  • มีการตั้งค่าข้อมูลไบโอเมตริกในอุปกรณ์ของผู้ใช้ และผู้ใช้อนุญาตให้ดำเนินการต่อไปนี้ การตรวจสอบสิทธิ์ลงในแอปพลิเคชัน
  • สำหรับขั้นตอนการลงชื่อเข้าใช้ ฟีเจอร์นี้จะเปิดใช้สำหรับสถานการณ์บัญชีเดียวเท่านั้น แม้ว่าจะมีข้อมูลเข้าสู่ระบบหลายรายการ (เช่น พาสคีย์และรหัสผ่าน) สำหรับบัญชีนั้น

เปิดใช้การแตะเพียงครั้งเดียวในขั้นตอนการสร้างพาสคีย์

ขั้นตอนการสร้างของวิธีนี้ตรงกับการสร้างข้อมูลเข้าสู่ระบบที่มีอยู่ กระบวนการ ใน BeginCreatePublicKeyCredentialRequest ให้ใช้ handleCreatePasskeyQuery() เพื่อดำเนินการตามคำขอหากเป็นพาสคีย์

is BeginCreatePublicKeyCredentialRequest -> {
  Log.i(TAG, "Request is passkey type")
  return handleCreatePasskeyQuery(request, passwordCount, passkeyCount)
}

ใน handleCreatePasskeyQuery() ให้รวม BiometricPromptData ด้วย ชั้นเรียน CreateEntry:

val createEntry = CreateEntry(
  // Additional properties...
  biometricPromptData = BiometricPromptData(
    allowedAuthenticators = allowedAuthenticator
  )
)

ผู้ให้บริการข้อมูลเข้าสู่ระบบควรตั้งค่าพร็อพเพอร์ตี้ allowedAuthenticator อย่างชัดแจ้ง ในอินสแตนซ์ BiometricPromptData หากไม่ได้ตั้งค่าคุณสมบัตินี้ ค่า ค่าเริ่มต้นคือ DEVICE_WEAK ตั้งค่าพร็อพเพอร์ตี้ cryptoObject ที่ไม่บังคับหากจําเป็นสำหรับกรณีการใช้งาน

เปิดใช้ขั้นตอนพาสคีย์สำหรับการลงชื่อเข้าใช้ด้วยการแตะเพียงครั้งเดียว

การดำเนินการนี้จะเป็นไปตามการตั้งค่าที่มีอยู่สำหรับการจัดการการลงชื่อเข้าใช้ของผู้ใช้ ซึ่งคล้ายกับขั้นตอนการสร้างพาสคีย์ ภายใต้ BeginGetPublicKeyCredentialOption ให้ใช้ populatePasskeyData()เพื่อรวบรวมข้อมูลที่เกี่ยวข้องกับ คำขอตรวจสอบสิทธิ์:

is BeginGetPublicKeyCredentialOption -> {
  // ... other logic

  populatePasskeyData(
    origin,
    option,
    responseBuilder,
    autoSelectEnabled,
    allowedAuthenticator
  )

  // ... other logic as needed
}

เช่นเดียวกับ CreateEntry ระบบจะตั้งค่าอินสแตนซ์ BiometricPromptData เป็น PublicKeyCredentialEntry อินสแตนซ์ หากไม่ได้ตั้งค่าไว้อย่างชัดแจ้ง allowedAuthenticator จะมีค่าเริ่มต้นเป็น BIOMETRIC_WEAK

PublicKeyCredentialEntry(
  // other properties...

  biometricPromptData = BiometricPromptData(
    allowedAuthenticators = allowedAuthenticator
  )
)

จัดการการเลือกรายการข้อมูลเข้าสู่ระบบ

ขณะจัดการการเลือกรายการข้อมูลเข้าสู่ระบบสําหรับการสร้างพาสคีย์หรือการเลือกพาสคีย์ระหว่างการลงชื่อเข้าใช้ ให้เรียกใช้ PendingIntentHandler's retrieveProviderCreateCredentialRequest หรือ retrieveProviderGetCredentialRequest ตามความเหมาะสม ซึ่งจะแสดงผลออบเจ็กต์ที่มีข้อมูลเมตาที่จําเป็นสําหรับผู้ให้บริการ เช่น เมื่อจัดการ การเลือกรายการการสร้างพาสคีย์ ให้อัปเดตรหัสดังต่อไปนี้

val createRequest = PendingIntentHandler.retrieveProviderCreateCredentialRequest(intent)
if (createRequest == null) {
  Log.i(TAG, "request is null")
  setUpFailureResponseAndFinish("Unable to extract request from intent")
  return
}
// Other logic...

val biometricPromptResult = createRequest.biometricPromptResult

// Add your logic based on what needs to be done
// after getting biometrics

if (createRequest.callingRequest is CreatePublicKeyCredentialRequest) {
  val publicKeyRequest: CreatePublicKeyCredentialRequest =
    createRequest.callingRequest as CreatePublicKeyCredentialRequest

  if (biometricPromptResult == null) {
    // Do your own authentication flow, if needed
  }
  else if (biometricPromptResult.isSuccessful) {
    createPasskey(
        publicKeyRequest.requestJson,
        createRequest.callingAppInfo,
        publicKeyRequest.clientDataHash,
        accountId
    )
  } else {
    val error = biometricPromptResult.authenitcationError
    // Process the error
}

  // Other logic...
}

ตัวอย่างนี้มีข้อมูลเกี่ยวกับความสําเร็จของขั้นตอนข้อมูลไบโอเมตริก รวมถึงมีข้อมูลอื่นๆ เกี่ยวกับข้อมูลเข้าสู่ระบบด้วย หากขั้นตอนล้มเหลว ให้ใช้ ใต้ biometricPromptResult.authenticationError เพื่อประกอบการตัดสินใจ รหัสข้อผิดพลาดที่แสดงเป็นส่วนหนึ่งของ biometricPromptResult.authenticationError.errorCode เป็นรหัสข้อผิดพลาดเดียวกัน ที่กำหนดไว้ในไลบรารี androidx.biometric เช่น androidx.biometric.BiometricPrompt.NO_SPACE androidx.biometric.BiometricPrompt.UNABLE_TO_PROCESS androidx.biometric.BiometricPrompt.ERROR_TIMEOUT และคล้ายกัน authenticationError จะมีข้อความแสดงข้อผิดพลาดที่เชื่อมโยงกับ errorCode ที่แสดงใน UI ได้

ในทำนองเดียวกัน ให้ดึงข้อมูลเมตาในระหว่าง retrieveProviderGetCredentialRequest ตรวจสอบว่าขั้นตอนการตรวจสอบข้อมูลไบโอเมตริกเป็น null หรือไม่ หากใช่ ให้กำหนดค่าข้อมูลไบโอเมตริกของคุณเองเป็น ตรวจสอบสิทธิ์แล้ว ซึ่งคล้ายกับวิธีวัดคุมการดำเนินการรับ ดังนี้

val getRequest =
    PendingIntentHandler.retrieveProviderGetCredentialRequest(intent)

if (getRequest == null) {
  Log.i(TAG, "request is null")
  setUpFailureResponseAndFinish("Unable to extract request from intent")
  return
}

// Other logic...

val biometricPromptResult = getRequest.biometricPromptResult

// Add your logic based on what needs to be done
// after getting biometrics

if (biometricPromptResult == null)
{
  // Do your own authentication flow, if necessary
} else if (biometricPromptResult.isSuccessful) {

Log.i(TAG, "The response from the biometricPromptResult was ${biometricPromptResult.authenticationResult.authenticationType}")

validatePasskey(
    publicKeyRequest.requestJson,
    origin,
    packageName,
    uid,
    passkey.username,
    credId,
    privateKey
)
  } else {
    val error = biometricPromptResult.authenitcationError
    // Process the error
}

  // Other logic...