mirror of
https://github.com/bitwarden/android.git
synced 2026-04-27 19:38:42 -05:00
PM-26575: Add AuthTab support for WebAuthN, Duo, and SSO (#6002)
This commit is contained in:
@@ -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].
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user