diff --git a/Riot/Modules/CrossSigning/Setup/CrossSigningSetupCoordinator.swift b/Riot/Modules/CrossSigning/Setup/CrossSigningSetupCoordinator.swift index 2877de09d7..4be29d75c0 100644 --- a/Riot/Modules/CrossSigning/Setup/CrossSigningSetupCoordinator.swift +++ b/Riot/Modules/CrossSigning/Setup/CrossSigningSetupCoordinator.swift @@ -45,7 +45,7 @@ final class CrossSigningSetupCoordinator: CrossSigningSetupCoordinatorType { // MARK: - Public methods func start() { - self.showReauthentication() + setupCrossSigning() } func toPresentable() -> UIViewController { @@ -54,15 +54,14 @@ final class CrossSigningSetupCoordinator: CrossSigningSetupCoordinatorType { // MARK: - Private methods - private func showReauthentication() { - + private func showReauthentication(authenticationSession: MXAuthenticationSession) { let setupCrossSigningRequest = self.crossSigningService.setupCrossSigningRequest() let reauthenticationParameters = ReauthenticationCoordinatorParameters(session: parameters.session, presenter: parameters.presenter, title: parameters.title, message: parameters.message, - authenticatedEndpointRequest: setupCrossSigningRequest) + authenticationSession: authenticationSession) let coordinator = ReauthenticationCoordinator(parameters: reauthenticationParameters) coordinator.delegate = self @@ -71,21 +70,21 @@ final class CrossSigningSetupCoordinator: CrossSigningSetupCoordinatorType { coordinator.start() } - private func setupCrossSigning(with authenticationParameters: [String: Any]) { - guard let crossSigning = self.parameters.session.crypto?.crossSigning else { - return - } + private func setupCrossSigning(with authenticationParameters: [String: Any] = [:]) { + guard let crossSigning = parameters.session.crypto?.crossSigning else { return } crossSigning.setup(withAuthParams: authenticationParameters) { [weak self] in - guard let self = self else { - return - } - self.delegate?.crossSigningSetupCoordinatorDidComplete(self) + guard let self else { return } + delegate?.crossSigningSetupCoordinatorDidComplete(self) } failure: { [weak self] error in - guard let self = self else { - return + guard let self else { return } + + if let responseData = (error as NSError).userInfo[MXHTTPClientErrorResponseDataKey] as? [AnyHashable: Any], + let authenticationSession = MXAuthenticationSession(fromJSON: responseData) { + showReauthentication(authenticationSession: authenticationSession) + } else { + delegate?.crossSigningSetupCoordinator(self, didFailWithError: error) } - self.delegate?.crossSigningSetupCoordinator(self, didFailWithError: error) } } }