mirror of
https://github.com/bitwarden/android.git
synced 2025-03-15 18:58:59 +03:00
Rename WebAuthCallbackActivity to be more generic (#1024)
This commit is contained in:
parent
874ead8f3e
commit
e9fba5b99c
5 changed files with 25 additions and 24 deletions
|
@ -57,7 +57,7 @@
|
|||
android:theme="@style/AutofillTotpCopyTheme" />
|
||||
|
||||
<activity
|
||||
android:name=".WebAuthCallbackActivity"
|
||||
android:name=".AuthCallbackActivity"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTop"
|
||||
android:noHistory="true"
|
||||
|
|
|
@ -8,21 +8,22 @@ import com.x8bit.bitwarden.data.platform.annotation.OmitFromCoverage
|
|||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
/**
|
||||
* An activity to receive callbacks from Custom Chrome tabs or other web-auth related flows such
|
||||
* the current state of the task holding the [MainActivity] can remain undisturbed.
|
||||
* An activity to receive external authentication-related callbacks so the current state of the
|
||||
* task holding the [MainActivity] can remain undisturbed.
|
||||
*
|
||||
* These callbacks can be from Custom Chrome tabs or other auth related flows, including NFC
|
||||
* related transmissions.
|
||||
*/
|
||||
@OmitFromCoverage
|
||||
@AndroidEntryPoint
|
||||
class WebAuthCallbackActivity : AppCompatActivity() {
|
||||
class AuthCallbackActivity : AppCompatActivity() {
|
||||
|
||||
private val webAuthCallbackViewModel: WebAuthCallbackViewModel by viewModels()
|
||||
private val viewModel: AuthCallbackViewModel by viewModels()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
webAuthCallbackViewModel.trySendAction(
|
||||
WebAuthCallbackAction.IntentReceive(intent = intent),
|
||||
)
|
||||
viewModel.trySendAction(AuthCallbackAction.IntentReceive(intent = intent))
|
||||
|
||||
val intent = Intent(this, MainActivity::class.java)
|
||||
.apply {
|
|
@ -10,19 +10,19 @@ import dagger.hilt.android.lifecycle.HiltViewModel
|
|||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* A view model that handles logic for the [WebAuthCallbackActivity].
|
||||
* A view model that handles logic for the [AuthCallbackActivity].
|
||||
*/
|
||||
@HiltViewModel
|
||||
class WebAuthCallbackViewModel @Inject constructor(
|
||||
class AuthCallbackViewModel @Inject constructor(
|
||||
private val authRepository: AuthRepository,
|
||||
) : BaseViewModel<Unit, Unit, WebAuthCallbackAction>(Unit) {
|
||||
override fun handleAction(action: WebAuthCallbackAction) {
|
||||
) : BaseViewModel<Unit, Unit, AuthCallbackAction>(Unit) {
|
||||
override fun handleAction(action: AuthCallbackAction) {
|
||||
when (action) {
|
||||
is WebAuthCallbackAction.IntentReceive -> handleIntentReceived(action)
|
||||
is AuthCallbackAction.IntentReceive -> handleIntentReceived(action)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleIntentReceived(action: WebAuthCallbackAction.IntentReceive) {
|
||||
private fun handleIntentReceived(action: AuthCallbackAction.IntentReceive) {
|
||||
val yubiKeyResult = action.intent.getYubiKeyResultOrNull()
|
||||
val captchaCallbackTokenResult = action.intent.getCaptchaCallbackTokenResult()
|
||||
val ssoCallbackResult = action.intent.getSsoCallbackResult()
|
||||
|
@ -49,11 +49,11 @@ class WebAuthCallbackViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
/**
|
||||
* Actions for the [WebAuthCallbackViewModel].
|
||||
* Actions for the [AuthCallbackViewModel].
|
||||
*/
|
||||
sealed class WebAuthCallbackAction {
|
||||
sealed class AuthCallbackAction {
|
||||
/**
|
||||
* Receive Intent by the application.
|
||||
*/
|
||||
data class IntentReceive(val intent: Intent) : WebAuthCallbackAction()
|
||||
data class IntentReceive(val intent: Intent) : AuthCallbackAction()
|
||||
}
|
|
@ -5,7 +5,7 @@ import android.app.PendingIntent
|
|||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.nfc.NfcAdapter
|
||||
import com.x8bit.bitwarden.WebAuthCallbackActivity
|
||||
import com.x8bit.bitwarden.AuthCallbackActivity
|
||||
import com.x8bit.bitwarden.data.autofill.util.toPendingIntentMutabilityFlag
|
||||
import com.x8bit.bitwarden.data.platform.annotation.OmitFromCoverage
|
||||
|
||||
|
@ -27,7 +27,7 @@ class NfcManagerImpl(
|
|||
PendingIntent.getActivity(
|
||||
activity,
|
||||
1,
|
||||
Intent(activity, WebAuthCallbackActivity::class.java).addFlags(
|
||||
Intent(activity, AuthCallbackActivity::class.java).addFlags(
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP,
|
||||
),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT.toPendingIntentMutabilityFlag(),
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.junit.jupiter.api.AfterEach
|
|||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class WebAuthCallbackViewModelTest : BaseViewModelTest() {
|
||||
class AuthCallbackViewModelTest : BaseViewModelTest() {
|
||||
private val authRepository = mockk<AuthRepository> {
|
||||
every { setCaptchaCallbackTokenResult(any()) } just runs
|
||||
every { setSsoCallbackResult(any()) } just runs
|
||||
|
@ -54,7 +54,7 @@ class WebAuthCallbackViewModelTest : BaseViewModelTest() {
|
|||
every { mockIntent.getYubiKeyResultOrNull() } returns null
|
||||
every { mockIntent.getSsoCallbackResult() } returns null
|
||||
|
||||
viewModel.trySendAction(WebAuthCallbackAction.IntentReceive(intent = mockIntent))
|
||||
viewModel.trySendAction(AuthCallbackAction.IntentReceive(intent = mockIntent))
|
||||
verify(exactly = 1) {
|
||||
authRepository.setCaptchaCallbackTokenResult(tokenResult = captchaCallbackTokenResult)
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ class WebAuthCallbackViewModelTest : BaseViewModelTest() {
|
|||
every { mockIntent.getYubiKeyResultOrNull() } returns null
|
||||
every { mockIntent.getCaptchaCallbackTokenResult() } returns null
|
||||
|
||||
viewModel.trySendAction(WebAuthCallbackAction.IntentReceive(intent = mockIntent))
|
||||
viewModel.trySendAction(AuthCallbackAction.IntentReceive(intent = mockIntent))
|
||||
verify(exactly = 1) {
|
||||
authRepository.setSsoCallbackResult(result = sseCallbackResult)
|
||||
}
|
||||
|
@ -87,13 +87,13 @@ class WebAuthCallbackViewModelTest : BaseViewModelTest() {
|
|||
every { mockIntent.getCaptchaCallbackTokenResult() } returns null
|
||||
every { mockIntent.getSsoCallbackResult() } returns null
|
||||
|
||||
viewModel.trySendAction(WebAuthCallbackAction.IntentReceive(intent = mockIntent))
|
||||
viewModel.trySendAction(AuthCallbackAction.IntentReceive(intent = mockIntent))
|
||||
verify(exactly = 1) {
|
||||
authRepository.setYubiKeyResult(yubiKeyResult)
|
||||
}
|
||||
}
|
||||
|
||||
private fun createViewModel() = WebAuthCallbackViewModel(
|
||||
private fun createViewModel() = AuthCallbackViewModel(
|
||||
authRepository = authRepository,
|
||||
)
|
||||
}
|
Loading…
Add table
Reference in a new issue