PM-26575: Add AuthTab support for WebAuthN, Duo, and SSO (#6002)

This commit is contained in:
David Perez
2025-10-10 16:38:31 -05:00
committed by GitHub
parent 0604d15d7d
commit c6f132d5f7
16 changed files with 381 additions and 37 deletions

View File

@@ -5,6 +5,7 @@ import android.content.Intent
import android.net.Uri
import androidx.activity.compose.ManagedActivityResultLauncher
import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultLauncher
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import com.bitwarden.annotation.OmitFromCoverage
@@ -45,6 +46,14 @@ interface IntentManager {
*/
fun launchUri(uri: Uri)
/**
* Start an Auth Tab Activity using the provided [Uri].
*/
fun startAuthTab(
uri: Uri,
launcher: ActivityResultLauncher<Intent>,
)
/**
* Start an activity using the provided [Intent] and provides a callback, via [onResult], for
* retrieving the [ActivityResult].

View File

@@ -13,7 +13,10 @@ import android.webkit.MimeTypeMap
import androidx.activity.compose.ManagedActivityResultLauncher
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.browser.auth.AuthTabIntent
import androidx.browser.customtabs.CustomTabsClient
import androidx.browser.customtabs.CustomTabsIntent
import androidx.compose.runtime.Composable
import androidx.core.content.ContextCompat
@@ -71,6 +74,19 @@ internal class IntentManagerImpl(
onResult = onResult,
)
override fun startAuthTab(
uri: Uri,
launcher: ActivityResultLauncher<Intent>,
) {
val providerPackageName = CustomTabsClient.getPackageName(activity, null).toString()
if (CustomTabsClient.isAuthTabSupported(activity, providerPackageName)) {
AuthTabIntent.Builder().build().launch(launcher, uri, "bitwarden")
} else {
// Fall back to a Custom Tab.
startCustomTabsActivity(uri = uri)
}
}
override fun startCustomTabsActivity(uri: Uri) {
CustomTabsIntent
.Builder()