[go: nahoru, domu]

Update the publick key credential get flow to use GIS json api.

Test: Unit test, and test on device
Bug: 270182330
Change-Id: I25100adf372e101390b9a719aed97da8dc2d3cb2
diff --git a/credentials/credentials-play-services-auth/build.gradle b/credentials/credentials-play-services-auth/build.gradle
index 7fd1e0e..4558801 100644
--- a/credentials/credentials-play-services-auth/build.gradle
+++ b/credentials/credentials-play-services-auth/build.gradle
@@ -31,11 +31,17 @@
     }
 
     // Closed source dependencies
-    implementation(libs.playServicesAuth) {
+    implementation(libs.playServicesAuth){
         exclude group: "androidx.loader"
         exclude group: "androidx.fragment"
+        exclude group: "androidx.core"
     }
-    implementation(libs.playServicesFido)
+
+    implementation(libs.playServicesFido){
+        exclude group: "androidx.loader"
+        exclude group: "androidx.fragment"
+        exclude group: "androidx.core"
+    }
 
     androidTestImplementation(libs.junit)
     androidTestImplementation(libs.testExtJunit)
@@ -47,6 +53,9 @@
     androidTestImplementation(libs.multidex)
     androidTestImplementation(project(":internal-testutils-truth"))
     androidTestImplementation(libs.kotlinCoroutinesAndroid)
+    androidTestImplementation("androidx.core:core-ktx:1.10.0")
+    androidTestImplementation("androidx.fragment:fragment:1.5.7")
+    androidTestImplementation("androidx.fragment:fragment-ktx:1.5.7")
 }
 
 android {
diff --git a/credentials/credentials-play-services-auth/src/main/java/androidx/credentials/playservices/controllers/BeginSignIn/BeginSignInControllerUtility.kt b/credentials/credentials-play-services-auth/src/main/java/androidx/credentials/playservices/controllers/BeginSignIn/BeginSignInControllerUtility.kt
index 1d74750..cf5f665 100644
--- a/credentials/credentials-play-services-auth/src/main/java/androidx/credentials/playservices/controllers/BeginSignIn/BeginSignInControllerUtility.kt
+++ b/credentials/credentials-play-services-auth/src/main/java/androidx/credentials/playservices/controllers/BeginSignIn/BeginSignInControllerUtility.kt
@@ -35,7 +35,7 @@
 import androidx.credentials.GetCredentialRequest
 import androidx.credentials.GetPasswordOption
 import androidx.credentials.GetPublicKeyCredentialOption
-import androidx.credentials.playservices.controllers.CreatePublicKeyCredential.PublicKeyCredentialControllerUtility.Companion.convertToPlayAuthPasskeyRequest
+import androidx.credentials.playservices.controllers.CreatePublicKeyCredential.PublicKeyCredentialControllerUtility.Companion.convertToPlayAuthPasskeyJsonRequest
 import com.google.android.gms.auth.api.identity.BeginSignInRequest
 import com.google.android.gms.auth.api.identity.BeginSignInRequest.GoogleIdTokenRequestOptions
 import com.google.android.libraries.identity.googleid.GetGoogleIdOption
@@ -64,8 +64,8 @@
                     )
                     autoSelect = autoSelect || option.isAutoSelectAllowed
                 } else if (option is GetPublicKeyCredentialOption && !isPublicKeyCredReqFound) {
-                    requestBuilder.setPasskeysSignInRequestOptions(
-                        convertToPlayAuthPasskeyRequest(option)
+                    requestBuilder.setPasskeyJsonSignInRequestOptions(
+                        convertToPlayAuthPasskeyJsonRequest(option)
                     )
                     isPublicKeyCredReqFound = true
                     // TODO(b/262924507) : watch for GIS update on single vs multiple options of a
diff --git a/credentials/credentials-play-services-auth/src/main/java/androidx/credentials/playservices/controllers/CreatePublicKeyCredential/PublicKeyCredentialControllerUtility.kt b/credentials/credentials-play-services-auth/src/main/java/androidx/credentials/playservices/controllers/CreatePublicKeyCredential/PublicKeyCredentialControllerUtility.kt
index 613f392..d402258 100644
--- a/credentials/credentials-play-services-auth/src/main/java/androidx/credentials/playservices/controllers/CreatePublicKeyCredential/PublicKeyCredentialControllerUtility.kt
+++ b/credentials/credentials-play-services-auth/src/main/java/androidx/credentials/playservices/controllers/CreatePublicKeyCredential/PublicKeyCredentialControllerUtility.kt
@@ -162,7 +162,7 @@
             if (clientExtensionResults != null) {
                 try {
                     val uvmEntries = clientExtensionResults.uvmEntries
-                    val uvmEntriesList = uvmEntries.uvmEntryList
+                    val uvmEntriesList = uvmEntries?.uvmEntryList
                     if (uvmEntriesList != null) {
                         val uvmEntriesJSON = JSONArray()
                         for (entry in uvmEntriesList) {
@@ -222,27 +222,14 @@
 
         /**
          * Converts from the Credential Manager public key credential option to the Play Auth
-         * Module passkey option.
+         * Module passkey json option.
          *
-         * @throws JSONException If rpId or challenge either do not
-         * exist or are empty in the initial request json
          */
-        fun convertToPlayAuthPasskeyRequest(request: GetPublicKeyCredentialOption):
-            BeginSignInRequest.PasskeysRequestOptions {
-            // TODO(b/262924507) : Make sure this is in compliance with w3 as impl continues
-            // TODO(b/262924507) : Improve codebase readability as done here
-            //  (readable error capture + docs/etc)
-            val json = JSONObject(request.requestJson)
-            val rpId = json.optString("rpId", "")
-            if (rpId.isEmpty()) {
-                throw JSONException("GetPublicKeyCredentialOption - rpId not specified in the " +
-                    "request or is unexpectedly empty")
-            }
-            val challenge = getChallenge(json)
-            return BeginSignInRequest.PasskeysRequestOptions.Builder()
+        fun convertToPlayAuthPasskeyJsonRequest(option: GetPublicKeyCredentialOption):
+            BeginSignInRequest.PasskeyJsonRequestOptions {
+            return BeginSignInRequest.PasskeyJsonRequestOptions.Builder()
                 .setSupported(true)
-                .setRpId(rpId)
-                .setChallenge(challenge)
+                .setRequestJson(option.requestJson)
                 .build()
         }
 
@@ -536,4 +523,4 @@
             ErrorCode.TIMEOUT_ERR to TimeoutError()
         )
     }
-}
\ No newline at end of file
+}
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 3431ba0..a432ab0 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -223,11 +223,11 @@
 okio = { module = "com.squareup.okio:okio", version = "3.1.0" }
 playFeatureDelivery = { module = "com.google.android.play:feature-delivery", version = "2.0.1" }
 playCore = { module = "com.google.android.play:core", version = "1.10.3" }
-playServicesAuth = {module = "com.google.android.gms:play-services-auth", version = "20.4.0"}
+playServicesAuth = {module = "com.google.android.gms:play-services-auth", version = "20.5.0"}
 playServicesBase = { module = "com.google.android.gms:play-services-base", version = "17.0.0" }
 playServicesBasement = { module = "com.google.android.gms:play-services-basement", version = "17.0.0" }
 playServicesDevicePerformance = { module = "com.google.android.gms:play-services-deviceperformance", version = "16.0.0" }
-playServicesFido = {module = "com.google.android.gms:play-services-fido", version = "19.0.0"}
+playServicesFido = {module = "com.google.android.gms:play-services-fido", version = "20.0.1"}
 playServicesWearable = { module = "com.google.android.gms:play-services-wearable", version = "17.1.0" }
 paparazzi = { module = "app.cash.paparazzi:paparazzi", version.ref = "paparazzi" }
 paparazziNativeJvm = { module = "app.cash.paparazzi:layoutlib-native-jdk11", version.ref = "paparazziNative" }