feat: use the homeserver url from the wellknown file for JWT check (MESSENGER-6777)

This commit is contained in:
Jan Niklas Grabowski
2025-01-23 14:01:23 +01:00
parent 284119937f
commit 54d655212c
4 changed files with 86 additions and 34 deletions
@@ -24,8 +24,6 @@ struct AuthenticationServerSelectionScreen: View {
// bwi #4976 show maintenance alert
@State private var isFetchingDowntime = false
@State private var showAlert = false
@State private var isInvalidServerAlert = false
@State private var activeAlert: ServerMaintenanceAlertType = .showInvalidAppVersionAlert
private var textFieldFooterColor: Color {
@@ -84,8 +82,8 @@ struct AuthenticationServerSelectionScreen: View {
}
}
}
.alert(isPresented: $showAlert, content: {
if isInvalidServerAlert {
.alert(isPresented: $viewModel.showAlert, content: {
if viewModel.isInvalidServerAlert {
return self.invalidServerAlert()
} else {
return ServerDowntimeDefaultService.shared.alert(alertType: activeAlert) {
@@ -202,30 +200,9 @@ struct AuthenticationServerSelectionScreen: View {
/// Sends the `confirm` view action so long as the text field input is valid.
private func submit() {
guard !viewModel.viewState.hasValidationError else { return }
// bwi #6162 homeserver validation is async now, due to server calls for token validation
Task {
let verified = await isHomeserverAddressValid(viewModel.homeserverAddress)
if verified {
viewModel.send(viewAction: .confirm)
} else {
isInvalidServerAlert = true
showAlert = true
}
}
}
private func isHomeserverAddressValid(_ homeserverAddress: String) async -> Bool {
if BWIBuildSettings.shared.bwiEnableLoginProtection || BWIBuildSettings.shared.bwiEnableTokenizedLoginProtection {
let protectionService = LoginProtectionService()
protectionService.hashes = BWIBuildSettings.shared.bwiHashes
return await protectionService.isValid(homeserverAddress)
}
return true
// BWI: #6777 validate and use base url from wellknown
viewModel.send(viewAction: .confirm)
// BWI END
}
/// bwi: jump directly into the iOS settings app to allow camera access
@@ -259,14 +236,27 @@ struct AuthenticationServerSelectionScreen: View {
return Alert(
title: Text(BWIL10n.authenticationServerSelectionServerDeniedTitle),
message: Text(BWIL10n.authenticationServerSelectionServerDeniedMessage),
primaryButton: .default(Text(BWIL10n.authenticationServerSelectionServerDeniedAdvertizementWebsiteButton), action: {UIApplication.shared.vc_open(url, completionHandler: nil)}),
secondaryButton: .default(Text(VectorL10n.ok)))
primaryButton: .default(Text(BWIL10n.authenticationServerSelectionServerDeniedAdvertizementWebsiteButton), action: {
// BWI: #6777 reset isInvalidServerAlert on dismiss, otherwise server downtime errors are not displayed
viewModel.isInvalidServerAlert = false
// BWI END
UIApplication.shared.vc_open(url, completionHandler: nil)
}),
secondaryButton: .default(Text(VectorL10n.ok), action: {
// BWI: #6777 reset isInvalidServerAlert on dismiss, otherwise server downtime errors are not displayed
viewModel.isInvalidServerAlert = false
// BWI END
}))
} else {
return Alert(
title: Text(BWIL10n.authenticationServerSelectionServerDeniedTitle),
message: Text(BWIL10n.authenticationServerSelectionServerDeniedMessage),
dismissButton: .default(Text(VectorL10n.ok)))
dismissButton: .default(Text(VectorL10n.ok), action: {
// BWI: #6777 reset isInvalidServerAlert on dismiss, otherwise server downtime errors are not displayed
viewModel.isInvalidServerAlert = false
// BWI END
}))
}
}
@@ -302,7 +292,9 @@ struct AuthenticationServerSelectionScreen: View {
private func showAlertIfNeeded() {
if ServerDowntimeDefaultService.shared.showAlert() {
activeAlert = ServerDowntimeDefaultService.shared.alertType()
showAlert = true
// BWI: #6777 moved boolean to viewmodel bindings
viewModel.showAlert = true
// BWI END
} else {
self.submit()
}