in Fido2/app/src/main/java/com/google/android/gms/identity/sample/fido2/api/AuthApi.kt [152:184]
suspend fun registerResponse(
sessionId: String,
credential: PublicKeyCredential
): ApiResult<List<Credential>> {
val rawId = credential.rawId.toBase64()
val response = credential.response as AuthenticatorAttestationResponse
val call = client.newCall(
Request.Builder()
.url("$BASE_URL/registerResponse")
.addHeader("Cookie", formatCookie(sessionId))
.method("POST", jsonRequestBody {
name("id").value(rawId)
name("type").value(PublicKeyCredentialType.PUBLIC_KEY.toString())
name("rawId").value(rawId)
name("response").objectValue {
name("clientDataJSON").value(
response.clientDataJSON.toBase64()
)
name("attestationObject").value(
response.attestationObject.toBase64()
)
}
})
.build()
)
val apiResponse = call.await()
return apiResponse.result("Error calling /registerResponse") {
parseUserCredentials(
body ?: throw ApiException("Empty response from /registerResponse")
)
}
}