Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aws-auth-cognito/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies {
implementation(libs.androidx.security)
implementation(libs.androidx.browser)
implementation(libs.androidx.credentials)
implementation(libs.androidx.credentials.play.services)

implementation(libs.aws.http)
implementation(libs.aws.cognitoidentity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.amplifyframework.auth.cognito.helpers

import android.app.Activity
import android.content.Context
import android.os.Build
import androidx.credentials.CreateCredentialResponse
import androidx.credentials.CreatePublicKeyCredentialRequest
import androidx.credentials.CreatePublicKeyCredentialResponse
Expand Down Expand Up @@ -75,22 +76,26 @@ internal class WebAuthnHelper(
}

suspend fun createCredential(requestJson: String, callingActivity: Activity): String {
try {
// Create the request for CredentialManager
val request = CreatePublicKeyCredentialRequest(requestJson)

// Create the credential
logger.verbose("Prompting user to create a PassKey")
val result: CreateCredentialResponse = credentialManager.createCredential(callingActivity, request)

// Extract the Public Key registration response. This is what we send to Cognito.
val publicKeyResult = result as? CreatePublicKeyCredentialResponse ?: throw WebAuthnFailedException(
"Android created wrong credential type",
AmplifyException.REPORT_BUG_TO_AWS_SUGGESTION
)
return publicKeyResult.registrationResponseJson
} catch (e: CreateCredentialException) {
throw e.toAuthException()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
try {
// Create the request for CredentialManager
val request = CreatePublicKeyCredentialRequest(requestJson)

// Create the credential
logger.verbose("Prompting user to create a PassKey")
val result: CreateCredentialResponse = credentialManager.createCredential(callingActivity, request)

// Extract the Public Key registration response. This is what we send to Cognito.
val publicKeyResult = result as? CreatePublicKeyCredentialResponse ?: throw WebAuthnFailedException(
"Android created wrong credential type",
AmplifyException.REPORT_BUG_TO_AWS_SUGGESTION
)
return publicKeyResult.registrationResponseJson
} catch (e: CreateCredentialException) {
throw e.toAuthException()
}
} else {
throw WebAuthnNotSupportedException(cause = null)
}
}

Expand Down
5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ fun Project.configureAndroid() {

dependencies {
add("coreLibraryDesugaring", libs.android.desugartools)
constraints {
add("implementation", libs.androidx.annotation.experimental) {
because("Fixes a lint bug with RequiresOptIn")
}
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
agp = "8.4.0"
androidx-activity = "1.2.0"
androidx-annotation = "1.9.1"
androidx-annotation-experimental = "1.4.1"
androidx-appcompat = "1.2.0"
androidx-browser = "1.4.0"
androidx-concurrent = "1.1.0"
Expand Down Expand Up @@ -57,11 +58,13 @@ turbine = "1.1.0"
android-desugartools = { module = "com.android.tools:desugar_jdk_libs", version.ref = "desugar" }
androidx-activity = { module = "androidx.activity:activity", version.ref = "androidx-activity" }
androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "androidx-annotation" }
androidx-annotation-experimental = { module = "androidx.annotation:annotation-experimental", version.ref = "androidx-annotation-experimental" }
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref="androidx-appcompat" }
androidx-browser = { module = "androidx.browser:browser", version.ref = "androidx-browser" }
androidx-core = { module = "androidx.core:core", version.ref = "androidx-core" }
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidx-core" }
androidx-credentials = { module = "androidx.credentials:credentials", version.ref="androidx-credentials" }
androidx-credentials-play-services = { module = "androidx.credentials:credentials-play-services-auth", version.ref="androidx-credentials" }
androidx-junit-ktx = { module = "androidx.test.ext:junit-ktx", version.ref = "junit-ktx" }
androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime", version.ref = "androidx-lifecycle" }
androidx-nav-fragment = { module = "androidx.navigation:navigation-fragment", version.ref = "navigation" }
Expand Down