Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,40 @@ class PasskeyAndPasswordFunctions (
}
}

fun autofillImplementation(
requestJson: String
) {
// [START android_identity_autofill_construct_request]
// Retrieves the user's saved password for your app.
val getPasswordOption = GetPasswordOption()

// Get a passkey from the user's public key credential provider.
val getPublicKeyCredentialOption = GetPublicKeyCredentialOption(
requestJson = requestJson
)

val getCredRequest = GetCredentialRequest(
listOf(getPasswordOption, getPublicKeyCredentialOption)
)
// [END android_identity_autofill_construct_request]

runBlocking {
// [START android_identity_autofill_get_credential_api]
coroutineScope {
try {
val result = credentialManager.getCredential(
context = activityContext, // Use an activity-based context.
request = getCredRequest
)
handleSignIn(result);
} catch (e: GetCredentialException) {
handleFailure(e);
}
}
// [END android_identity_autofill_get_credential_api]
}
}

// [START android_identity_launch_sign_in_flow_2]
fun handleSignIn(result: GetCredentialResponse) {
// Handle the successfully returned credential.
Expand Down Expand Up @@ -239,6 +273,8 @@ class PasskeyAndPasswordFunctions (
}
// [END android_identity_handle_create_passkey_failure]

fun handleFailure(e: GetCredentialException) { }

// [START android_identity_register_password]
suspend fun registerPassword(username: String, password: String) {
// Initialize a CreatePasswordRequest object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,25 @@ class WebViewMainActivity : ComponentActivity() {
coroutineScope: CoroutineScope,
credentialManagerHandler: CredentialManagerHandler
) {
// [START android_identity_create_webview_object]
val passkeyWebListener = PasskeyWebListener(activity, coroutineScope, credentialManagerHandler)

val webViewClient = object : WebViewClient() {
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
webView.evaluateJavascript(PasskeyWebListener.INJECTED_VAL, null)
}
}

webView.webViewClient = webViewClient
// [END android_identity_create_webview_object]

// [START android_identity_set_web]
val rules = setOf("*")
if (WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_LISTENER)) {
WebViewCompat.addWebMessageListener(webView, PasskeyWebListener.INTERFACE_NAME,
rules, passkeyWebListener)
}

webView.webViewClient = webViewClient
// [END android_identity_set_web]
}
}