From b9eef8d8e26d60ebf489c796702cdf0a1110474b Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Tue, 5 Nov 2024 15:16:47 +0100 Subject: [PATCH] Enable SSO handling (login and UIA) by feature flag --- Btchap/Config/BuildSettings.swift | 3 ++ DevTchap/Config/BuildSettings.swift | 3 ++ .../DeactivateAccountService.swift | 6 +-- ...UserInteractiveAuthenticationService.swift | 10 ++--- Tchap/Config/BuildSettings.swift | 3 ++ .../View/TchapOnboardingSplashScreen.swift | 45 ++++++++++--------- changelog.d/1110.change | 1 + 7 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 changelog.d/1110.change diff --git a/Btchap/Config/BuildSettings.swift b/Btchap/Config/BuildSettings.swift index be8ca5276..d873f79d1 100644 --- a/Btchap/Config/BuildSettings.swift +++ b/Btchap/Config/BuildSettings.swift @@ -243,6 +243,9 @@ final class BuildSettings: NSObject { tchapFeatureAnyFeature: [ tchapFeatureAnyHomeServer ] ] + // Tchap: handle SSO feature flag. Presents SSO button on Onboarding screen and give priority to SSO on UIA. + static let tchapFeatureHandleSSO = false + // MARK: - Side Menu static let enableSideMenu: Bool = true && !newAppLayoutEnabled static let sideMenuShowInviteFriends: Bool = true diff --git a/DevTchap/Config/BuildSettings.swift b/DevTchap/Config/BuildSettings.swift index 5df485d5a..3b0e39924 100644 --- a/DevTchap/Config/BuildSettings.swift +++ b/DevTchap/Config/BuildSettings.swift @@ -243,6 +243,9 @@ final class BuildSettings: NSObject { tchapFeatureAnyFeature: [ tchapFeatureAnyHomeServer ] ] + // Tchap: handle SSO feature flag. Presents SSO button on Onboarding screen and give priority to SSO on UIA. + static let tchapFeatureHandleSSO = true + // MARK: - Side Menu static let enableSideMenu: Bool = true && !newAppLayoutEnabled static let sideMenuShowInviteFriends: Bool = true diff --git a/Riot/Modules/Settings/DeactivateAccount/DeactivateAccountService.swift b/Riot/Modules/Settings/DeactivateAccount/DeactivateAccountService.swift index 680d9717e..1ec4ef112 100644 --- a/Riot/Modules/Settings/DeactivateAccount/DeactivateAccountService.swift +++ b/Riot/Modules/Settings/DeactivateAccount/DeactivateAccountService.swift @@ -93,9 +93,9 @@ enum DeactivateAccountServiceError: Error { /// - Parameter authenticationSession: The authentication session to be used. /// - Returns: A tuple containing the required authentication method along with a URL for fallback if necessary. private func handleAuthenticationSession(_ authenticationSession: MXAuthenticationSession) throws -> (DeactivateAccountAuthentication, URL?) { - // Tchap: give priority to SSO authentication - // guard let nextStage = uiaService.firstUncompletedFlowIdentifier(in: authenticationSession) else { - guard let nextStage = uiaService.firstUncompletedFlowIdentifier(in: authenticationSession, priorityToSso: true) else { + // Tchap: give priority to SSO authentication if SSO handling is activated by feature flag. + // guard let nextStage = uiaService.firstUncompletedFlowIdentifier(in: authenticationSession) else { + guard let nextStage = uiaService.firstUncompletedFlowIdentifier(in: authenticationSession, priorityToSso: BuildSettings.tchapFeatureHandleSSO) else { MXLog.error("[DeactivateAccountService] handleAuthenticationSession: Failed to determine the next stage.") throw DeactivateAccountServiceError.missingStage } diff --git a/Riot/Modules/UserInteractiveAuthentication/UserInteractiveAuthenticationService.swift b/Riot/Modules/UserInteractiveAuthentication/UserInteractiveAuthenticationService.swift index bc86be8c1..602ccc23f 100644 --- a/Riot/Modules/UserInteractiveAuthentication/UserInteractiveAuthenticationService.swift +++ b/Riot/Modules/UserInteractiveAuthentication/UserInteractiveAuthenticationService.swift @@ -212,9 +212,9 @@ final class UserInteractiveAuthenticationService: NSObject { /// - Returns: The fallback URL for the first uncompleted stage found. func firstUncompletedStageAuthenticationFallbackURL(for authenticationSession: MXAuthenticationSession) -> URL? { guard let sessiondId = authenticationSession.session, - // Tchap: give priority to SSO authentication + // Tchap: give priority to SSO authentication if SSO handling is activated by feature flag. // let firstUncompletedStageIdentifier = self.firstUncompletedFlowIdentifier(in: authenticationSession) else { - let firstUncompletedStageIdentifier = self.firstUncompletedFlowIdentifier(in: authenticationSession, priorityToSso: true) else { + let firstUncompletedStageIdentifier = self.firstUncompletedFlowIdentifier(in: authenticationSession, priorityToSso: BuildSettings.tchapFeatureHandleSSO) else { return nil } return self.authenticationFallbackURL(for: firstUncompletedStageIdentifier, sessionId: sessiondId) @@ -261,8 +261,8 @@ final class UserInteractiveAuthenticationService: NSObject { let completedStagesSet = NSOrderedSet(array: completedStages) uncompletedStages.minus(completedStagesSet) - // Tchap - if uncompletedStages.contains(kMXLoginFlowTypeSSO) { + // Tchap: return SSO if priority is given to SSO login flow type and SSO flow type is available on the homeServer. + if priorityToSso && uncompletedStages.contains(kMXLoginFlowTypeSSO) { return kMXLoginFlowTypeSSO } @@ -284,7 +284,7 @@ final class UserInteractiveAuthenticationService: NSObject { // Tchap /// Check if an array of login flows contains "m.login.sso" flow. func tchapHasSsoFlowAvailable(authenticationSession: MXAuthenticationSession) -> Bool { - return self.firstUncompletedFlowIdentifier(in: authenticationSession, priorityToSso: true) == kMXLoginFlowTypeSSO + return self.firstUncompletedFlowIdentifier(in: authenticationSession, priorityToSso: BuildSettings.tchapFeatureHandleSSO) == kMXLoginFlowTypeSSO } // MARK: - Private diff --git a/Tchap/Config/BuildSettings.swift b/Tchap/Config/BuildSettings.swift index 4b07a2611..4acd6065d 100644 --- a/Tchap/Config/BuildSettings.swift +++ b/Tchap/Config/BuildSettings.swift @@ -301,6 +301,9 @@ final class BuildSettings: NSObject { ] ] + // Tchap: handle SSO feature flag. Presents SSO button on Onboarding screen and give priority to SSO on UIA. + static let tchapFeatureHandleSSO = false + // MARK: - Side Menu static let enableSideMenu: Bool = true && !newAppLayoutEnabled static let sideMenuShowInviteFriends: Bool = true diff --git a/Tchap/Modules/Onboarding/SplashScreen/View/TchapOnboardingSplashScreen.swift b/Tchap/Modules/Onboarding/SplashScreen/View/TchapOnboardingSplashScreen.swift index dde74877c..f936b0567 100644 --- a/Tchap/Modules/Onboarding/SplashScreen/View/TchapOnboardingSplashScreen.swift +++ b/Tchap/Modules/Onboarding/SplashScreen/View/TchapOnboardingSplashScreen.swift @@ -92,28 +92,31 @@ struct TchapOnboardingSplashScreen: View { HStack { // HStack to center horizontally Spacer() VStack { - // Button ProConnect - Button(action: { viewModel.send(viewAction: .login(.sso(ssoIdentityProviders: []))) }, label: { - HStack { - Image(uiImage: Asset_tchap.Images.proConnectIcon.image) - Text(LocalizedStringKey(TchapL10n.welcomeProConnectTitle)) // LocalizedStringKey is needed for markdown interpretation. - .fixedSize(horizontal: false, vertical: true) // .lineLimit(Int.max) doesn't work here. - .foregroundColor(.white) - } - .padding(EdgeInsets(top: 10.0, leading: 32.0, bottom: 10.0, trailing: 32.0)) - }) - .background( - Color(UIColor(rgb: 0x000091)), - in: RoundedRectangle(cornerRadius: 12.0) - ) - .padding(.bottom, 8.0) - - // Button "What is ProConnect?" - Button(action: { openProConnectWebsite() }, label: { - Text(TchapL10n.welcomeProConnectInfo) - }) - .padding(.bottom, 32.0) + // Display ProConnect option only if enabled by feature flag. + if BuildSettings.tchapFeatureHandleSSO { + // Button ProConnect + Button(action: { viewModel.send(viewAction: .login(.sso(ssoIdentityProviders: []))) }, label: { + HStack { + Image(uiImage: Asset_tchap.Images.proConnectIcon.image) + Text(LocalizedStringKey(TchapL10n.welcomeProConnectTitle)) // LocalizedStringKey is needed for markdown interpretation. + .fixedSize(horizontal: false, vertical: true) // .lineLimit(Int.max) doesn't work here. + .foregroundColor(.white) + } + .padding(EdgeInsets(top: 10.0, leading: 32.0, bottom: 10.0, trailing: 32.0)) + }) + .background( + Color(UIColor(rgb: 0x000091)), + in: RoundedRectangle(cornerRadius: 12.0) + ) + .padding(.bottom, 8.0) + // Button "What is ProConnect?" + Button(action: { openProConnectWebsite() }, label: { + Text(TchapL10n.welcomeProConnectInfo) + }) + .padding(.bottom, 32.0) + } + /// Button "Connect with password" Button(action: { viewModel.send(viewAction: .login(.password)) }, label: { Text(TchapL10n.welcomePasswordTitle) diff --git a/changelog.d/1110.change b/changelog.d/1110.change new file mode 100644 index 000000000..6d61c3a66 --- /dev/null +++ b/changelog.d/1110.change @@ -0,0 +1 @@ +Activation de la gestion de ProConnect (login et UIA) via feature flag. \ No newline at end of file