Feature/5308 sso on internal browser

This commit is contained in:
Frank Rotermund
2023-12-08 11:42:02 +00:00
parent bdb8a7a92f
commit 02bb97687d
19 changed files with 122 additions and 26 deletions

View File

@@ -19,7 +19,7 @@
BUNDLE_DISPLAY_NAME = BuM-Beta
BASE_BUNDLE_IDENTIFIER = de.bwi.messenger-beta
APPLICATION_GROUP_IDENTIFIER = group.de.messenger-beta
APPLICATION_SCHEME = element
APPLICATION_SCHEME = BuM
// Team
DEVELOPMENT_TEAM = Q111Q11QQ1

View File

@@ -19,7 +19,7 @@
BUNDLE_DISPLAY_NAME = BuM-BWI-MDM
BASE_BUNDLE_IDENTIFIER = de.bwi.bwmessenger.mdm
APPLICATION_GROUP_IDENTIFIER = group.de.bwmessenger.mdm
APPLICATION_SCHEME = element
APPLICATION_SCHEME = BuM4BWI
// Team
DEVELOPMENT_TEAM = Q111Q11QQ1

View File

@@ -19,7 +19,7 @@
BUNDLE_DISPLAY_NAME = BuM-Beta
BASE_BUNDLE_IDENTIFIER = de.bwi.messenger-beta
APPLICATION_GROUP_IDENTIFIER = group.de.messenger-beta
APPLICATION_SCHEME = element
APPLICATION_SCHEME = BuM-Beta
// Team
DEVELOPMENT_TEAM = Q111Q11QQ1

View File

@@ -19,7 +19,7 @@
BUNDLE_DISPLAY_NAME = BuM-Open
BASE_BUNDLE_IDENTIFIER = de.bwi.messenger-open
APPLICATION_GROUP_IDENTIFIER = group.de.messenger-open
APPLICATION_SCHEME = element
APPLICATION_SCHEME = BuM
// Team
DEVELOPMENT_TEAM = Q111Q11QQ1

View File

@@ -19,7 +19,7 @@
BUNDLE_DISPLAY_NAME = Messenger
BASE_BUNDLE_IDENTIFIER = de.bwi.messenger
APPLICATION_GROUP_IDENTIFIER = group.de.messenger
APPLICATION_SCHEME = element
APPLICATION_SCHEME = BuM
// Team
DEVELOPMENT_TEAM = Q111Q11QQ1

View File

@@ -669,3 +669,8 @@
// MARK: Secure backup recovery
"security_settings_secure_backup" = "Nachrichten wiederherstellen";
"security_settings_secure_backup_info_valid" = "Sofern du Probleme mit nicht-entschlüsselbaren Nachrichten hast, kann es helfen, die Schlüssel neu abzurufen. Klicke hierzu auf den Button und warte solange, bis alle Schlüssel wiederhergestellt wurden. Die App muss dazu geöffnet bleiben.";
// MARK: SSO
"sso_authentication_url_scheme_error_title" = "Fehler bei Authentifizierung";
"sso_authentication_url_scheme_error_message" = "Authentifizierung über Schema %@ konnte nicht geöffnet werden. Bitte wende dich an deinen Support.";

View File

@@ -579,3 +579,7 @@
// MARK: Secure backup recovery
"security_settings_secure_backup" = "Restore Messages";
"security_settings_secure_backup_info_valid" = "If you have problems with messages that cannot be decrypted, it may help to retrieve the keys again. To do this, click on the button and wait until all keys have been restored. The app must remain open for this.";
// MARK: SSO
"sso_authentication_url_scheme_error_title" = "Authentication Error";
"sso_authentication_url_scheme_error_message" = "Authentication with scheme %@ could not be opened. Please contact support.";

View File

@@ -1795,6 +1795,14 @@ public class BWIL10n: NSObject {
public static var splashScreenTitle: String {
return BWIL10n.tr("Bwi", "splash_screen_title")
}
/// Authentifizierung über Schema %@ konnte nicht geöffnet werden. Bitte wende dich an deinen Support.
public static func ssoAuthenticationUrlSchemeErrorMessage(_ p1: String) -> String {
return BWIL10n.tr("Bwi", "sso_authentication_url_scheme_error_message", p1)
}
/// Fehler bei Authentifizierung
public static var ssoAuthenticationUrlSchemeErrorTitle: String {
return BWIL10n.tr("Bwi", "sso_authentication_url_scheme_error_title")
}
/// Der Server ist momentan nicht erreichbar. Versuche es später erneut.
public static var standardErrorAlertTitleDowntime: String {
return BWIL10n.tr("Bwi", "standard_error_alert_title_downtime")

View File

@@ -80,7 +80,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// bwi: testing mdm config
// DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
// let dict = ["home_server_url": ""]
// let dict = ["home_server_url": "", "external_url_scheme": ""]
// UserDefaults.standard.setValue(dict, forKey: "com.apple.configuration.managed")
// }

View File

@@ -72,7 +72,10 @@ final class SSOAuthenticationPresenter: NSObject {
self.identityProvider = identityProvider
self.presentingViewController = presentingViewController
if #unavailable(iOS 15.0), UIAccessibility.isGuidedAccessEnabled {
// bwi #5308 if there is a url scheme call sso directly with that scheme
if let urlScheme = AppConfigService.shared.externalUrlScheme() {
startUrlSchemeAuthentication(with: authenticationURL)
} else if #unavailable(iOS 15.0), UIAccessibility.isGuidedAccessEnabled {
// SFAuthenticationSession and ASWebAuthenticationSession doesn't work with guided access (rdar://48376122)
// Confirmed to be fixed on iOS 15, haven't been able to test on iOS 14.
presentSafariViewController(with: authenticationURL, animated: animated)
@@ -95,7 +98,7 @@ final class SSOAuthenticationPresenter: NSObject {
guard let presentingViewController = self.presentingViewController else {
return
}
let safariViewController = SFSafariViewController(url: authenticationURL)
safariViewController.dismissButtonStyle = .cancel
safariViewController.delegate = self
@@ -104,6 +107,22 @@ final class SSOAuthenticationPresenter: NSObject {
self.safariViewController = safariViewController
}
// bwi #5303 when there is an url scheme use that to open authentication
private func startUrlSchemeAuthentication(with authenticationURL: URL) {
guard let presentingViewController = self.presentingViewController else {
return
}
if UIApplication.shared.canOpenURL(authenticationURL) {
UIApplication.shared.open(authenticationURL)
} else {
let alert = UIAlertController(title: BWIL10n.ssoAuthenticationUrlSchemeErrorTitle, message: BWIL10n.ssoAuthenticationUrlSchemeErrorMessage(AppConfigService.shared.externalUrlScheme() ?? "none"), preferredStyle: .alert)
alert.addAction(UIAlertAction(title: VectorL10n.cancel, style: .cancel))
presentingViewController.present(alert, animated: true, completion: nil)
}
}
private func startAuthenticationSession(with authenticationURL: URL) {
guard let presentingViewController = self.presentingViewController else {
return

View File

@@ -72,6 +72,11 @@ final class SSOAuthenticationService: NSObject, SSOAuthenticationServiceProtocol
authenticationComponent.queryItems = queryItems
// bwi #5308 set url scheme from https to app url acheme if given by App Config
if let urlScheme = AppConfigService.shared.externalUrlScheme() {
authenticationComponent.scheme = urlScheme
}
return authenticationComponent.url
}

View File

@@ -619,13 +619,23 @@ final class OnboardingCoordinator: NSObject, OnboardingCoordinatorProtocol {
private func showPincodePromt(for session: MXSession) {
// bwi show old coordinator flow similar to how its done for passphrase workflow
let pinCoordinator = SetPinCoordinator(session: session, viewMode: .setPinAfterLogin, pinCodePreferences: PinCodePreferences.shared)
// bwi # 5308 for sso to work use navigationRouter.push instead of present and use the right navigation router
let setPinCodeParameters = SetPinCoordinatorParameters(
navigationRouter: navigationRouter,
session: session,
viewMode: .setPinAfterLogin,
pinCodePreferences: PinCodePreferences.shared)
let pinCoordinator = SetPinCoordinator(parameters: setPinCodeParameters)
pinCoordinator.delegate = self
navigationRouter.present(pinCoordinator.toPresentable(), animated: true)
add(childCoordinator: pinCoordinator)
pinCoordinator.start()
navigationRouter.push(pinCoordinator, animated: true) { [weak self] in
self?.onboardingFinished = true
self?.completeIfReady()
}
}
// MARK: - Finished
@@ -728,11 +738,11 @@ extension OnboardingUseCaseViewModelResult {
}
extension OnboardingCoordinator: SetPinCoordinatorDelegate {
func setPinCoordinatorDidComplete(_ coordinator: SetPinCoordinatorType) {
navigationRouter.dismissModule(animated: true) { [weak self] in
self?.onboardingFinished = true
self?.completeIfReady()
}
// bwi #5308 dismiss module is not necessary anymore with using push instead of present before
self.onboardingFinished = true
self.completeIfReady()
}
func setPinCoordinatorDidCompleteWithReset(_ coordinator: SetPinCoordinatorType, dueToTooManyErrors: Bool) {

View File

@@ -19,6 +19,13 @@
import UIKit
struct SetPinCoordinatorParameters {
let navigationRouter: NavigationRouterType?
let session: MXSession?
let viewMode: SetPinCoordinatorViewMode
let pinCodePreferences: PinCodePreferences
}
@objcMembers
final class SetPinCoordinator: SetPinCoordinatorType {
@@ -44,11 +51,16 @@ final class SetPinCoordinator: SetPinCoordinatorType {
// MARK: - Setup
init(session: MXSession?, viewMode: SetPinCoordinatorViewMode, pinCodePreferences: PinCodePreferences) {
self.navigationRouter = NavigationRouter(navigationController: RiotNavigationController())
self.session = session
self.viewMode = viewMode
self.pinCodePreferences = pinCodePreferences
init(parameters: SetPinCoordinatorParameters) {
if let navigationRouter = parameters.navigationRouter {
self.navigationRouter = navigationRouter
} else {
self.navigationRouter = NavigationRouter(navigationController: RiotNavigationController())
}
self.session = parameters.session
self.viewMode = parameters.viewMode
self.pinCodePreferences = parameters.pinCodePreferences
}
private func getRootCoordinator() -> Coordinator & Presentable {

View File

@@ -82,7 +82,14 @@ final class SetPinCoordinatorBridgePresenter: NSObject {
// }
func present(from viewController: UIViewController, animated: Bool) {
let setPinCoordinator = SetPinCoordinator(session: self.session, viewMode: self.viewMode, pinCodePreferences: .shared)
let setPinCodeParameters = SetPinCoordinatorParameters(
navigationRouter: nil,
session: self.session,
viewMode: self.viewMode,
pinCodePreferences: .shared)
let setPinCoordinator = SetPinCoordinator(parameters: setPinCodeParameters)
setPinCoordinator.delegate = self
viewController.present(setPinCoordinator.toPresentable(), animated: animated, completion: nil)
setPinCoordinator.start()
@@ -97,7 +104,13 @@ final class SetPinCoordinatorBridgePresenter: NSObject {
let pinCoordinatorWindow = UIWindow(frame: window.bounds)
let setPinCoordinator = SetPinCoordinator(session: self.session, viewMode: self.viewMode, pinCodePreferences: .shared)
let setPinCodeParameters = SetPinCoordinatorParameters(
navigationRouter: nil,
session: self.session,
viewMode: self.viewMode,
pinCodePreferences: .shared)
let setPinCoordinator = SetPinCoordinator(parameters: setPinCodeParameters)
setPinCoordinator.delegate = self
pinCoordinatorWindow.rootViewController = setPinCoordinator.toPresentable()

View File

@@ -62,6 +62,7 @@
<array>
<string>http</string>
<string>https</string>
<string>awbs</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>

View File

@@ -189,7 +189,13 @@ final class UserSessionsFlowCoordinator: NSObject, Coordinator, Presentable {
private func createOtherSessionsCoordinator(sessionInfos: [UserSessionInfo],
filterBy filter: UserOtherSessionsFilter,
title: String) -> UserOtherSessionsCoordinator {
let shouldShowDeviceLogout = parameters.session.homeserverWellknown.authentication == nil
//bwi #5308 fix crash when there is no home server wellknown
var shouldShowDeviceLogout = true
if let homeserverWellknown = parameters.session.homeserverWellknown {
shouldShowDeviceLogout = homeserverWellknown.authentication == nil
}
let parameters = UserOtherSessionsCoordinatorParameters(sessionInfos: sessionInfos,
filter: filter,
title: title,

View File

@@ -39,7 +39,13 @@ final class UserSessionsOverviewCoordinator: Coordinator, Presentable {
self.parameters = parameters
service = parameters.service
let shouldShowDeviceLogout = parameters.session.homeserverWellknown.authentication == nil
//bwi #5308 fix crash when there is no home server wellknown
var shouldShowDeviceLogout = true
if let homeserverWellknown = parameters.session.homeserverWellknown {
shouldShowDeviceLogout = homeserverWellknown.authentication == nil
}
viewModel = UserSessionsOverviewViewModel(userSessionsOverviewService: parameters.service,
settingsService: RiotSettings.shared,
showDeviceLogout: shouldShowDeviceLogout)

View File

@@ -23,4 +23,5 @@ struct AppConfig: Codable, Equatable {
var contentScannerUrl: String? = nil
var pusherUrl: String? = nil
var permalinkUrl: String? = nil
var externalUrlScheme: String? = nil
}

View File

@@ -39,6 +39,7 @@ extension UserDefaults
private let contentScannerKey = "contentScanner"
private let pusherUrlKey = "pusherUrl"
private let permalinkUrlKey = "permalinkUrl"
private let externalUrlSchemeKey = "external_url_scheme"
private let savedConfig = "savedAppConfig"
@@ -143,6 +144,9 @@ extension UserDefaults
config.permalinkUrl = permalinkUrl
}
}
if let externalUrlScheme = dict[externalUrlSchemeKey] as? String {
config.externalUrlScheme = externalUrlScheme
}
// app config needs at least a valid server url
if let serverUrl = config.serverUrl {
@@ -193,5 +197,7 @@ extension UserDefaults
}
}
func externalUrlScheme() -> String? {
return appConfig.externalUrlScheme
}
}