Cancel FIDO 2 registration job when cancellation occurs (#3583)

This commit is contained in:
Patrick Honkonen 2024-07-19 11:44:33 -04:00 committed by GitHub
parent 4abf907dc5
commit 7ddbc99add
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -25,7 +25,6 @@ import com.x8bit.bitwarden.data.auth.repository.model.UserState
import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager
import com.x8bit.bitwarden.ui.platform.manager.intent.IntentManager import com.x8bit.bitwarden.ui.platform.manager.intent.IntentManager
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicInteger
@ -51,22 +50,23 @@ class Fido2ProviderProcessorImpl(
cancellationSignal: CancellationSignal, cancellationSignal: CancellationSignal,
callback: OutcomeReceiver<BeginCreateCredentialResponse, CreateCredentialException>, callback: OutcomeReceiver<BeginCreateCredentialResponse, CreateCredentialException>,
) { ) {
cancellationSignal.setOnCancelListener {
callback.onError(CreateCredentialCancellationException())
scope.cancel()
}
val userId = authRepository.activeUserId val userId = authRepository.activeUserId
if (userId == null) { if (userId == null) {
callback.onError(CreateCredentialUnknownException("Active user is required.")) callback.onError(CreateCredentialUnknownException("Active user is required."))
return return
} }
scope.launch { val createCredentialJob = scope.launch {
processCreateCredentialRequest(request = request) processCreateCredentialRequest(request = request)
?.let { callback.onResult(it) } ?.let { callback.onResult(it) }
?: callback.onError(CreateCredentialUnknownException()) ?: callback.onError(CreateCredentialUnknownException())
} }
cancellationSignal.setOnCancelListener {
if (createCredentialJob.isActive) {
createCredentialJob.cancel()
}
callback.onError(CreateCredentialCancellationException())
}
} }
private fun processCreateCredentialRequest( private fun processCreateCredentialRequest(