AppCoordinator: Handle custom scheme URL parsing and SSO deep link.

This commit is contained in:
SBiOSoftWhare
2021-01-07 14:41:01 +01:00
parent 86b1f8d10a
commit 7773d497c8
+24 -4
View File
@@ -24,6 +24,8 @@ final class AppCoordinator: NSObject, AppCoordinatorType {
// MARK: - Constants
// MARK: - Properties
private let customSchemeURLParser: CustomSchemeURLParser
// MARK: Private
@@ -48,6 +50,7 @@ final class AppCoordinator: NSObject, AppCoordinatorType {
init(router: RootRouterType) {
self.rootRouter = router
self.customSchemeURLParser = CustomSchemeURLParser()
}
// MARK: - Public methods
@@ -57,10 +60,15 @@ final class AppCoordinator: NSObject, AppCoordinatorType {
}
func open(url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
// TODO: Implement an CustomURLSchemeParser.
// TODO: Handle element://connect for SSO redirect and check for a unique id to avoid security issue.
// As said in the Apple documentation be careful on security issues (see https://developer.apple.com/documentation/xcode/allowing_apps_and_websites_to_link_to_your_content/defining_a_custom_url_scheme_for_your_app)
return false
// NOTE: As said in the Apple documentation be careful on security issues with Custom Scheme URL (see https://developer.apple.com/documentation/xcode/allowing_apps_and_websites_to_link_to_your_content/defining_a_custom_url_scheme_for_your_app)
do {
let deepLinkOption = try self.customSchemeURLParser.parse(url: url, options: options)
return self.handleDeepLinkOption(deepLinkOption)
} catch {
NSLog("[AppCoordinator] Custom scheme URL parsing failed with error: \(error)")
return false
}
}
// MARK: - Private methods
@@ -93,6 +101,18 @@ final class AppCoordinator: NSObject, AppCoordinatorType {
// FIXME: Present an error on coordinator.toPresentable()
self.legacyAppDelegate.showError(asAlert: error)
}
private func handleDeepLinkOption(_ deepLinkOption: DeepLinkOption) -> Bool {
let canOpenLink: Bool
switch deepLinkOption {
case .connect(let loginToken, let transactionId):
canOpenLink = self.legacyAppDelegate.continueSSOLogin(withToken: loginToken, txnId: transactionId)
}
return canOpenLink
}
}
// MARK: - LegacyAppDelegateDelegate