diff --git a/Riot/Modules/CrossSigning/CrossSigningService.swift b/Riot/Modules/CrossSigning/CrossSigningService.swift index cab22cb07..bca98a902 100644 --- a/Riot/Modules/CrossSigning/CrossSigningService.swift +++ b/Riot/Modules/CrossSigning/CrossSigningService.swift @@ -68,6 +68,7 @@ final class CrossSigningService: NSObject { } func setupCrossSigningRequest() -> AuthenticatedEndpointRequest { + // bwi 7295 could be fixed here to by adding a fake master key to the request let path = "\(kMXAPIPrefixPathUnstable)/keys/device_signing/upload" return AuthenticatedEndpointRequest(path: path, httpMethod: "POST", params: [:]) } diff --git a/Riot/Modules/Secrets/Reset/SecretsResetCoordinator.swift b/Riot/Modules/Secrets/Reset/SecretsResetCoordinator.swift index aa03a01ad..a2fa82d55 100644 --- a/Riot/Modules/Secrets/Reset/SecretsResetCoordinator.swift +++ b/Riot/Modules/Secrets/Reset/SecretsResetCoordinator.swift @@ -72,6 +72,23 @@ final class SecretsResetCoordinator: SecretsResetCoordinatorType { coordinator.start() self.add(childCoordinator: coordinator) } + + + // bwi 7295 need to do authentication with session on an 401 error + private func showAuthentication(with session: MXAuthenticationSession) { + let reauthenticationCoordinatorParameters = ReauthenticationCoordinatorParameters(session: self.session, + presenter: self.toPresentable(), + title: nil, + message: BWIL10n.secretsResetAuthenticationMessage, + authenticationSession: session) + + let coordinator = ReauthenticationCoordinator(parameters: reauthenticationCoordinatorParameters) + coordinator.delegate = self + coordinator.start() + self.add(childCoordinator: coordinator) + } + // bwi 7295 end + } // MARK: - SecretsResetViewModelCoordinatorDelegate @@ -81,6 +98,12 @@ extension SecretsResetCoordinator: SecretsResetViewModelCoordinatorDelegate { self.showAuthentication(with: request) } + // bwi 7295 need to do authentication with session on an 401 error + func secretsResetViewModel(_ viewModel: SecretsResetViewModelType, needsToAuthenticateWith session: MXAuthenticationSession) { + self.showAuthentication(with: session) + } + // bwi 7295 end + func secretsResetViewModelDidResetSecrets(_ viewModel: SecretsResetViewModelType) { self.delegate?.secretsResetCoordinatorDidResetSecrets(self) } diff --git a/Riot/Modules/Secrets/Reset/SecretsResetViewModel.swift b/Riot/Modules/Secrets/Reset/SecretsResetViewModel.swift index 62b0c686f..ea1a40e6a 100644 --- a/Riot/Modules/Secrets/Reset/SecretsResetViewModel.swift +++ b/Riot/Modules/Secrets/Reset/SecretsResetViewModel.swift @@ -92,7 +92,18 @@ final class SecretsResetViewModel: SecretsResetViewModelType { guard let self = self else { return } - self.update(viewState: .error(error)) + + // bwi 7295 need to do authentication with session on an 401 error + let nsError = error as NSError + + if let matrixData = nsError.userInfo["com.matrixsdk.httpclient.error.response.data"] as? [String: Any], + let session = MXAuthenticationSession(fromJSON: matrixData) { + self.coordinatorDelegate?.secretsResetViewModel(self, needsToAuthenticateWith: session) + } else { + self.update(viewState: .error(error)) + } + // bwi 7295 end + }) } diff --git a/Riot/Modules/Secrets/Reset/SecretsResetViewModelType.swift b/Riot/Modules/Secrets/Reset/SecretsResetViewModelType.swift index 5a5c88077..64530ffae 100644 --- a/Riot/Modules/Secrets/Reset/SecretsResetViewModelType.swift +++ b/Riot/Modules/Secrets/Reset/SecretsResetViewModelType.swift @@ -24,6 +24,8 @@ protocol SecretsResetViewModelViewDelegate: AnyObject { protocol SecretsResetViewModelCoordinatorDelegate: AnyObject { func secretsResetViewModel(_ viewModel: SecretsResetViewModelType, needsToAuthenticateWith request: AuthenticatedEndpointRequest) + // bwi 7295 need to do authentication with session + func secretsResetViewModel(_ viewModel: SecretsResetViewModelType, needsToAuthenticateWith session: MXAuthenticationSession) func secretsResetViewModelDidResetSecrets(_ viewModel: SecretsResetViewModelType) func secretsResetViewModelDidCancel(_ viewModel: SecretsResetViewModelType) }