Add Cancelled state to UIA
This commit is contained in:
parent
6b47db92dc
commit
9414a29b80
@ -20,6 +20,7 @@ import org.matrix.android.sdk.api.auth.UIABaseAuth
|
||||
import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
|
||||
import org.matrix.android.sdk.api.failure.Failure
|
||||
import org.matrix.android.sdk.api.failure.toRegistrationFlowResponse
|
||||
import org.matrix.android.sdk.internal.util.exceptions.UiaCancelledException
|
||||
import timber.log.Timber
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
||||
@ -30,14 +31,15 @@ import kotlin.coroutines.suspendCoroutine
|
||||
* @param interceptor see doc in [UserInteractiveAuthInterceptor]
|
||||
* @param retryBlock called at the end of the process, in this block generally retry executing the task, with
|
||||
* provided authUpdate
|
||||
* @return true if UIA is handled without error
|
||||
* @return UiaResult if UIA handled, failed or cancelled
|
||||
*
|
||||
*/
|
||||
internal suspend fun handleUIA(failure: Throwable,
|
||||
interceptor: UserInteractiveAuthInterceptor,
|
||||
retryBlock: suspend (UIABaseAuth) -> Unit): Boolean {
|
||||
retryBlock: suspend (UIABaseAuth) -> Unit): UiaResult {
|
||||
Timber.d("## UIA: check error ${failure.message}")
|
||||
val flowResponse = failure.toRegistrationFlowResponse()
|
||||
?: return false.also {
|
||||
?: return UiaResult.FAILURE.also {
|
||||
Timber.d("## UIA: not a UIA error")
|
||||
}
|
||||
|
||||
@ -50,14 +52,19 @@ internal suspend fun handleUIA(failure: Throwable,
|
||||
interceptor.performStage(flowResponse, (failure as? Failure.ServerError)?.error?.code, continuation)
|
||||
}
|
||||
} catch (failure2: Throwable) {
|
||||
Timber.w(failure2, "## UIA: failed to participate")
|
||||
return false
|
||||
return if (failure2 is UiaCancelledException) {
|
||||
Timber.w(failure2, "## UIA: cancelled")
|
||||
UiaResult.CANCELLED
|
||||
} else {
|
||||
Timber.w(failure2, "## UIA: failed to participate")
|
||||
UiaResult.FAILURE
|
||||
}
|
||||
}
|
||||
|
||||
Timber.d("## UIA: updated auth")
|
||||
return try {
|
||||
retryBlock(authUpdate)
|
||||
true
|
||||
UiaResult.SUCCESS
|
||||
} catch (failure3: Throwable) {
|
||||
handleUIA(failure3, interceptor, retryBlock)
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2022 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.auth.registration
|
||||
|
||||
enum class UiaResult {
|
||||
SUCCESS,
|
||||
FAILURE,
|
||||
CANCELLED
|
||||
}
|
@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.crypto.tasks
|
||||
|
||||
import org.matrix.android.sdk.api.auth.UIABaseAuth
|
||||
import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
|
||||
import org.matrix.android.sdk.internal.auth.registration.UiaResult
|
||||
import org.matrix.android.sdk.internal.auth.registration.handleUIA
|
||||
import org.matrix.android.sdk.internal.crypto.api.CryptoApi
|
||||
import org.matrix.android.sdk.internal.crypto.model.rest.DeleteDeviceParams
|
||||
@ -47,13 +48,13 @@ internal class DefaultDeleteDeviceTask @Inject constructor(
|
||||
}
|
||||
} catch (throwable: Throwable) {
|
||||
if (params.userInteractiveAuthInterceptor == null ||
|
||||
!handleUIA(
|
||||
handleUIA(
|
||||
failure = throwable,
|
||||
interceptor = params.userInteractiveAuthInterceptor,
|
||||
retryBlock = { authUpdate ->
|
||||
execute(params.copy(userAuthParam = authUpdate))
|
||||
}
|
||||
)
|
||||
) != UiaResult.SUCCESS
|
||||
) {
|
||||
Timber.d("## UIA: propagate failure")
|
||||
throw throwable
|
||||
|
@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.crypto.tasks
|
||||
|
||||
import dagger.Lazy
|
||||
import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
|
||||
import org.matrix.android.sdk.internal.auth.registration.UiaResult
|
||||
import org.matrix.android.sdk.internal.auth.registration.handleUIA
|
||||
import org.matrix.android.sdk.internal.crypto.MXOlmDevice
|
||||
import org.matrix.android.sdk.internal.crypto.MyDeviceInfoHolder
|
||||
@ -126,13 +127,13 @@ internal class DefaultInitializeCrossSigningTask @Inject constructor(
|
||||
uploadSigningKeysTask.execute(uploadSigningKeysParams)
|
||||
} catch (failure: Throwable) {
|
||||
if (params.interactiveAuthInterceptor == null ||
|
||||
!handleUIA(
|
||||
handleUIA(
|
||||
failure = failure,
|
||||
interceptor = params.interactiveAuthInterceptor,
|
||||
retryBlock = { authUpdate ->
|
||||
uploadSigningKeysTask.execute(uploadSigningKeysParams.copy(userAuthParam = authUpdate))
|
||||
}
|
||||
)
|
||||
) != UiaResult.SUCCESS
|
||||
) {
|
||||
Timber.d("## UIA: propagate failure")
|
||||
throw failure
|
||||
|
@ -18,12 +18,14 @@ package org.matrix.android.sdk.internal.session.account
|
||||
|
||||
import org.matrix.android.sdk.api.auth.UIABaseAuth
|
||||
import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
|
||||
import org.matrix.android.sdk.internal.auth.registration.UiaResult
|
||||
import org.matrix.android.sdk.internal.auth.registration.handleUIA
|
||||
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
|
||||
import org.matrix.android.sdk.internal.network.executeRequest
|
||||
import org.matrix.android.sdk.internal.session.cleanup.CleanupSession
|
||||
import org.matrix.android.sdk.internal.session.identity.IdentityDisconnectTask
|
||||
import org.matrix.android.sdk.internal.task.Task
|
||||
import org.matrix.android.sdk.internal.util.exceptions.UiaCancelledException
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -51,18 +53,24 @@ internal class DefaultDeactivateAccountTask @Inject constructor(
|
||||
}
|
||||
true
|
||||
} catch (throwable: Throwable) {
|
||||
if (!handleUIA(
|
||||
failure = throwable,
|
||||
interceptor = params.userInteractiveAuthInterceptor,
|
||||
retryBlock = { authUpdate ->
|
||||
execute(params.copy(userAuthParam = authUpdate))
|
||||
}
|
||||
)
|
||||
) {
|
||||
Timber.d("## UIA: propagate failure")
|
||||
throw throwable
|
||||
} else {
|
||||
false
|
||||
when (handleUIA(
|
||||
failure = throwable,
|
||||
interceptor = params.userInteractiveAuthInterceptor,
|
||||
retryBlock = { authUpdate ->
|
||||
execute(params.copy(userAuthParam = authUpdate))
|
||||
}
|
||||
)) {
|
||||
UiaResult.SUCCESS -> {
|
||||
false
|
||||
}
|
||||
UiaResult.FAILURE -> {
|
||||
Timber.d("## UIA: propagate failure")
|
||||
throw throwable
|
||||
}
|
||||
UiaResult.CANCELLED -> {
|
||||
Timber.d("## UIA: cancelled")
|
||||
throw UiaCancelledException()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
|
||||
import org.matrix.android.sdk.api.failure.Failure
|
||||
import org.matrix.android.sdk.api.failure.toRegistrationFlowResponse
|
||||
import org.matrix.android.sdk.api.session.identity.ThreePid
|
||||
import org.matrix.android.sdk.internal.auth.registration.UiaResult
|
||||
import org.matrix.android.sdk.internal.auth.registration.handleUIA
|
||||
import org.matrix.android.sdk.internal.database.model.PendingThreePidEntity
|
||||
import org.matrix.android.sdk.internal.database.model.PendingThreePidEntityFields
|
||||
@ -72,13 +73,13 @@ internal class DefaultFinalizeAddingThreePidTask @Inject constructor(
|
||||
true
|
||||
} catch (throwable: Throwable) {
|
||||
if (params.userInteractiveAuthInterceptor == null ||
|
||||
!handleUIA(
|
||||
handleUIA(
|
||||
failure = throwable,
|
||||
interceptor = params.userInteractiveAuthInterceptor,
|
||||
retryBlock = { authUpdate ->
|
||||
execute(params.copy(userAuthParam = authUpdate))
|
||||
}
|
||||
)
|
||||
) != UiaResult.SUCCESS
|
||||
) {
|
||||
Timber.d("## UIA: propagate failure")
|
||||
throw throwable.toRegistrationFlowResponse()
|
||||
|
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.util.exceptions
|
||||
|
||||
class UiaCancelledException(message: String? = null) : Exception(message)
|
@ -34,6 +34,7 @@ import im.vector.app.features.analytics.plan.MobileScreen
|
||||
import im.vector.app.features.auth.ReAuthActivity
|
||||
import im.vector.app.features.settings.VectorSettingsActivity
|
||||
import org.matrix.android.sdk.api.auth.data.LoginFlowTypes
|
||||
import org.matrix.android.sdk.internal.util.exceptions.UiaCancelledException
|
||||
import javax.inject.Inject
|
||||
|
||||
class DeactivateAccountFragment @Inject constructor() : VectorBaseFragment<FragmentDeactivateAccountBinding>() {
|
||||
@ -114,7 +115,9 @@ class DeactivateAccountFragment @Inject constructor() : VectorBaseFragment<Fragm
|
||||
is DeactivateAccountViewEvents.OtherFailure -> {
|
||||
settingsActivity?.ignoreInvalidTokenError = false
|
||||
dismissLoadingDialog()
|
||||
displayErrorDialog(it.throwable)
|
||||
if (it.throwable !is UiaCancelledException) {
|
||||
displayErrorDialog(it.throwable)
|
||||
}
|
||||
}
|
||||
DeactivateAccountViewEvents.Done -> {
|
||||
MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCredentials = true, isAccountDeactivated = true))
|
||||
@ -123,7 +126,8 @@ class DeactivateAccountFragment @Inject constructor() : VectorBaseFragment<Fragm
|
||||
ReAuthActivity.newIntent(requireContext(),
|
||||
it.registrationFlowResponse,
|
||||
it.lastErrorCode,
|
||||
getString(R.string.deactivate_account_title)).let { intent ->
|
||||
getString(R.string.deactivate_account_title)
|
||||
).let { intent ->
|
||||
reAuthActivityResultLauncher.launch(intent)
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import org.matrix.android.sdk.api.failure.isInvalidUIAAuth
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.internal.crypto.crosssigning.fromBase64
|
||||
import org.matrix.android.sdk.internal.crypto.model.rest.DefaultBaseAuth
|
||||
import org.matrix.android.sdk.internal.util.exceptions.UiaCancelledException
|
||||
import timber.log.Timber
|
||||
import kotlin.coroutines.Continuation
|
||||
import kotlin.coroutines.resume
|
||||
@ -44,7 +45,7 @@ data class DeactivateAccountViewState(
|
||||
|
||||
class DeactivateAccountViewModel @AssistedInject constructor(@Assisted private val initialState: DeactivateAccountViewState,
|
||||
private val session: Session) :
|
||||
VectorViewModel<DeactivateAccountViewState, DeactivateAccountAction, DeactivateAccountViewEvents>(initialState) {
|
||||
VectorViewModel<DeactivateAccountViewState, DeactivateAccountAction, DeactivateAccountViewEvents>(initialState) {
|
||||
|
||||
@AssistedFactory
|
||||
interface Factory : MavericksAssistedViewModelFactory<DeactivateAccountViewModel, DeactivateAccountViewState> {
|
||||
@ -57,7 +58,7 @@ class DeactivateAccountViewModel @AssistedInject constructor(@Assisted private v
|
||||
override fun handle(action: DeactivateAccountAction) {
|
||||
when (action) {
|
||||
is DeactivateAccountAction.DeactivateAccount -> handleDeactivateAccount(action)
|
||||
DeactivateAccountAction.SsoAuthDone -> {
|
||||
DeactivateAccountAction.SsoAuthDone -> {
|
||||
Timber.d("## UIA - FallBack success")
|
||||
_viewEvents.post(DeactivateAccountViewEvents.Loading())
|
||||
if (pendingAuth != null) {
|
||||
@ -66,7 +67,7 @@ class DeactivateAccountViewModel @AssistedInject constructor(@Assisted private v
|
||||
uiaContinuation?.resumeWithException(IllegalArgumentException())
|
||||
}
|
||||
}
|
||||
is DeactivateAccountAction.PasswordAuthDone -> {
|
||||
is DeactivateAccountAction.PasswordAuthDone -> {
|
||||
_viewEvents.post(DeactivateAccountViewEvents.Loading())
|
||||
val decryptedPass = session.loadSecureSecret<String>(action.password.fromBase64().inputStream(), ReAuthActivity.DEFAULT_RESULT_KEYSTORE_ALIAS)
|
||||
uiaContinuation?.resume(
|
||||
@ -77,9 +78,9 @@ class DeactivateAccountViewModel @AssistedInject constructor(@Assisted private v
|
||||
)
|
||||
)
|
||||
}
|
||||
DeactivateAccountAction.ReAuthCancelled -> {
|
||||
DeactivateAccountAction.ReAuthCancelled -> {
|
||||
Timber.d("## UIA - Reauth cancelled")
|
||||
uiaContinuation?.resumeWithException(Exception())
|
||||
uiaContinuation?.resumeWithException(UiaCancelledException())
|
||||
uiaContinuation = null
|
||||
pendingAuth = null
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user