From 9730c47b19c32fb15ae23e2b9ce0603eb2f1e0f6 Mon Sep 17 00:00:00 2001 From: Frank Rotermund Date: Wed, 5 Nov 2025 08:00:54 +0100 Subject: [PATCH 1/2] fix: enable passphrase reset with MAS (MESSENGER-7861) --- .../Common/WebViewController/WebViewViewController.h | 3 +++ .../Common/WebViewController/WebViewViewController.m | 8 ++++++++ Riot/Modules/Home/Fallback/AuthFallBackViewController.m | 3 +++ .../Reauthentication/ReauthenticationCoordinator.swift | 9 +++++++-- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Riot/Modules/Common/WebViewController/WebViewViewController.h b/Riot/Modules/Common/WebViewController/WebViewViewController.h index f686abec5..4556481e4 100644 --- a/Riot/Modules/Common/WebViewController/WebViewViewController.h +++ b/Riot/Modules/Common/WebViewController/WebViewViewController.h @@ -14,5 +14,8 @@ Please see LICENSE in the repository root for full details. @interface WebViewViewController : MXKWebViewViewController +// bwi #7861 we need to enable javascript only for reauthentication +- (void) enableJavascript:(BOOL)enable; + @end diff --git a/Riot/Modules/Common/WebViewController/WebViewViewController.m b/Riot/Modules/Common/WebViewController/WebViewViewController.m index bfd29f86f..b1e1e4024 100644 --- a/Riot/Modules/Common/WebViewController/WebViewViewController.m +++ b/Riot/Modules/Common/WebViewController/WebViewViewController.m @@ -86,4 +86,12 @@ Please see LICENSE in the repository root for full details. [super setLocalHTMLFile:localHTMLFile]; } + +// bwi #7861 we need to enable javascript only for reauthentication +- (void)enableJavascript:(BOOL)enable { + if (webView) { + webView.configuration.preferences.javaScriptEnabled = enable; + } +} + @end diff --git a/Riot/Modules/Home/Fallback/AuthFallBackViewController.m b/Riot/Modules/Home/Fallback/AuthFallBackViewController.m index b8d1131d6..b60acb9ba 100644 --- a/Riot/Modules/Home/Fallback/AuthFallBackViewController.m +++ b/Riot/Modules/Home/Fallback/AuthFallBackViewController.m @@ -53,6 +53,9 @@ NSString *FallBackViewControllerJavascriptOnLogin = @"window.matrixLogin.onLogin // the user agent to bypass the limitation of Google, as a quick fix (a proper solution will be to use the SSO SDK) webView.customUserAgent = @"Mozilla/5.0"; + // bwi #7861 this webview needs javascript to function on MAS setups + [self enableJavascript:YES]; + [self clearCookies]; } diff --git a/Riot/Modules/Reauthentication/ReauthenticationCoordinator.swift b/Riot/Modules/Reauthentication/ReauthenticationCoordinator.swift index 14c7887c3..5395535a4 100644 --- a/Riot/Modules/Reauthentication/ReauthenticationCoordinator.swift +++ b/Riot/Modules/Reauthentication/ReauthenticationCoordinator.swift @@ -141,7 +141,9 @@ final class ReauthenticationCoordinator: ReauthenticationCoordinatorType { // NOTE: Prefer use a callback and the same mechanism as SSOAuthentificationSession instead of using custom WKWebView let reauthFallbackViewController: ReauthFallBackViewController = ReauthFallBackViewController(url: authenticationURL.absoluteString) reauthFallbackViewController.title = self.parameters.title - + + reauthFallbackViewController.enableJavascript(true) + reauthFallbackViewController.didCancel = { [weak self] in guard let self = self else { return @@ -153,7 +155,7 @@ final class ReauthenticationCoordinator: ReauthenticationCoordinatorType { guard let self = self else { return } - + guard let sessionId = authenticationSession.session else { self.delegate?.reauthenticationCoordinator(self, didFailWithError: ReauthenticationCoordinatorError.failToBuildPasswordParameters) return @@ -161,10 +163,13 @@ final class ReauthenticationCoordinator: ReauthenticationCoordinatorType { let authenticationParameters = self.authenticationParametersBuilder.buildOAuthParameters(with: sessionId) self.delegate?.reauthenticationCoordinatorDidComplete(self, withAuthenticationParameters: authenticationParameters) + + self.presentingViewController.dismiss(animated: true) } let navigationController = RiotNavigationController(rootViewController: reauthFallbackViewController) + // bwi #7861 close buttons should close the view self.presentingViewController.present(navigationController, animated: true) } } From 7737aa0a6a0f80e52f5b22a1c4d4b185b2b63755 Mon Sep 17 00:00:00 2001 From: Frank Rotermund Date: Wed, 5 Nov 2025 08:21:49 +0100 Subject: [PATCH 2/2] fix: add cancel button for better UI flow (MESSENGER-7861) --- .../Controllers/MXKWebViewViewController.m | 19 +++++++++++-------- .../ReauthFallBackViewController.swift | 8 +++++++- .../ReauthenticationCoordinator.swift | 3 +++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Riot/Modules/MatrixKit/Controllers/MXKWebViewViewController.m b/Riot/Modules/MatrixKit/Controllers/MXKWebViewViewController.m index 978b40b72..b52510da4 100644 --- a/Riot/Modules/MatrixKit/Controllers/MXKWebViewViewController.m +++ b/Riot/Modules/MatrixKit/Controllers/MXKWebViewViewController.m @@ -235,14 +235,17 @@ NSString *const kMXKWebViewViewControllerJavaScriptEnableLog = canGoBack = (![webView.URL.absoluteString isEqualToString:@"about:blank"]); } - if (canGoBack) - { - self.navigationItem.rightBarButtonItem = backButton; - } - else - { - // Reset the original state - self.navigationItem.rightBarButtonItems = originalRightBarButtonItems; + // bwi #7861 don't overwrite other barbutton items here + if (self.navigationItem.rightBarButtonItem == nil) { + if (canGoBack) + { + self.navigationItem.rightBarButtonItem = backButton; + } + else + { + // Reset the original state + self.navigationItem.rightBarButtonItems = originalRightBarButtonItems; + } } } diff --git a/Riot/Modules/Reauthentication/ReauthFallBackViewController.swift b/Riot/Modules/Reauthentication/ReauthFallBackViewController.swift index 1f5435b4b..e659c1119 100644 --- a/Riot/Modules/Reauthentication/ReauthFallBackViewController.swift +++ b/Riot/Modules/Reauthentication/ReauthFallBackViewController.swift @@ -53,10 +53,16 @@ final class ReauthFallBackViewController: AuthFallBackViewController, Themable { } private func setupNavigationBar() { + // bwi #7861 change logic to both have a cancel and a close button. We don't need a back button here let doneBarButtonItem = MXKBarButtonItem(title: VectorL10n.close, style: .plain) { [weak self] in self?.didValidate?() } - self.navigationItem.leftBarButtonItem = doneBarButtonItem + self.navigationItem.rightBarButtonItem = doneBarButtonItem + + let cancelBarButtonItem = MXKBarButtonItem(title: VectorL10n.cancel, style: .plain) { [weak self] in + self?.didCancel?() + } + self.navigationItem.leftBarButtonItem = cancelBarButtonItem } } diff --git a/Riot/Modules/Reauthentication/ReauthenticationCoordinator.swift b/Riot/Modules/Reauthentication/ReauthenticationCoordinator.swift index 5395535a4..7236bf3f4 100644 --- a/Riot/Modules/Reauthentication/ReauthenticationCoordinator.swift +++ b/Riot/Modules/Reauthentication/ReauthenticationCoordinator.swift @@ -149,6 +149,9 @@ final class ReauthenticationCoordinator: ReauthenticationCoordinatorType { return } self.delegate?.reauthenticationCoordinatorDidCancel(self) + + // bwi #7861 cancel buttons should close the view + self.presentingViewController.dismiss(animated: true) } reauthFallbackViewController.didValidate = { [weak self] in