ใน 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
}
BiometricPromptData
อินสแตนซ์จะได้รับการตั้งค่าเป็นอินสแตนซ์ PublicKeyCredentialEntry
เช่นเดียวกับ CreateEntry
หากไม่ได้ตั้งค่าไว้อย่างชัดแจ้ง
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.authenticationError
// 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
หากต้องการดำเนินการต่อ ให้กำหนดค่าข้อมูลไบโอเมตริกของคุณเองเพื่อ
ตรวจสอบสิทธิ์ ซึ่งคล้ายกับวิธีที่การดำเนินการ get ได้รับการวัดผล
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.authenticationError
// Process the error
}
// Other logic...