Update OIDC presentation (#987)

* Present OIDC directly on the ServerConfirmationScreen.

Read the actual window from the view.

* Pop back to the confirmation screen when a user enters an MXID that needs OIDC.

* Remove OIDC error handling from the login screen.
This commit is contained in:
Doug
2023-05-30 16:51:00 +01:00
committed by GitHub
parent 03ba211e6c
commit 6b6ea118e2
24 changed files with 130 additions and 122 deletions
@@ -43,7 +43,6 @@ final class SoftLogoutScreenCoordinator: CoordinatorProtocol {
private let parameters: SoftLogoutScreenCoordinatorParameters
private var viewModel: SoftLogoutScreenViewModelProtocol
private let oidcAuthenticationPresenter: OIDCAuthenticationPresenter
private var authenticationService: AuthenticationServiceProxyProtocol { parameters.authenticationService }
var callback: (@MainActor (SoftLogoutScreenCoordinatorResult) -> Void)?
@@ -55,8 +54,6 @@ final class SoftLogoutScreenCoordinator: CoordinatorProtocol {
viewModel = SoftLogoutScreenViewModel(credentials: parameters.credentials,
homeserver: homeserver.value,
keyBackupNeeded: parameters.keyBackupNeeded)
oidcAuthenticationPresenter = OIDCAuthenticationPresenter(authenticationService: parameters.authenticationService)
}
// MARK: - Public
@@ -74,7 +71,7 @@ final class SoftLogoutScreenCoordinator: CoordinatorProtocol {
case .clearAllData:
self.callback?(.clearAllData)
case .continueWithOIDC:
self.continueWithOIDC()
self.continueWithOIDC(presentationAnchor: viewModel.context.viewState.window)
}
}
}
@@ -130,7 +127,9 @@ final class SoftLogoutScreenCoordinator: CoordinatorProtocol {
}
}
private func continueWithOIDC() {
private func continueWithOIDC(presentationAnchor: UIWindow?) {
guard let presentationAnchor else { return }
startLoading()
Task {
@@ -141,7 +140,8 @@ final class SoftLogoutScreenCoordinator: CoordinatorProtocol {
case .success(let oidcData):
stopLoading()
switch await oidcAuthenticationPresenter.authenticate(using: oidcData) {
let presenter = OIDCAuthenticationPresenter(authenticationService: parameters.authenticationService, presentationAnchor: presentationAnchor)
switch await presenter.authenticate(using: oidcData) {
case .success(let userSession):
callback?(.signedIn(userSession))
case .failure(let error):
@@ -63,6 +63,9 @@ struct SoftLogoutScreenViewState: BindableState {
/// The types of login supported by the homeserver.
var loginMode: LoginMode { homeserver.loginMode }
/// The presentation anchor used for OIDC authentication.
var window: UIWindow?
/// Whether to show recover encryption keys message
var showRecoverEncryptionKeysMessage: Bool {
@@ -83,6 +86,8 @@ struct SoftLogoutScreenBindings {
}
enum SoftLogoutScreenViewAction {
/// Updates the window used as the OIDC presentation anchor.
case updateWindow(UIWindow?)
/// Login.
case login
/// Forgot password
@@ -43,6 +43,9 @@ class SoftLogoutScreenViewModel: SoftLogoutScreenViewModelType, SoftLogoutScreen
callback?(.clearAllData)
case .continueWithOIDC:
callback?(.continueWithOIDC)
case .updateWindow(let window):
guard state.window != window else { return }
Task { state.window = window }
}
}
@@ -49,6 +49,10 @@ struct SoftLogoutScreen: View {
}
.background(Color.element.background.ignoresSafeArea())
.alert(item: $context.alertInfo) { $0.alert }
.introspectViewController { viewController in
guard let window = viewController.view.window else { return }
context.send(viewAction: .updateWindow(window))
}
}
/// The title, message and icon at the top of the screen.