diff --git a/CHANGES.md b/CHANGES.md index 4a82693feb..4584d74b06 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ Bugfix 🐛: - Loudspeaker is always used (#1685) - Fix uploads still don't work with room v6 (#1879) - Can't handle ongoing call events in background (#1992) + - Login with Matrix-Id | Autodiscovery fails if identity server is invalid and Homeserver ok (#2027) Translations 🗣: - diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/wellknown/WellknownResult.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/wellknown/WellknownResult.kt index a736a4f1be..ec2dfd214c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/wellknown/WellknownResult.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/wellknown/WellknownResult.kt @@ -45,7 +45,7 @@ sealed class WellknownResult { /** * Inform the user that auto-discovery failed due to invalid/empty data and PROMPT for the parameter. */ - object FailPrompt : WellknownResult() + data class FailPrompt(val homeServerUrl: String?, val wellKnown: WellKnown?) : WellknownResult() /** * Inform the user that auto-discovery did not return any usable URLs. Do not continue further with the current login process. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/wellknown/GetWellknownTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/wellknown/GetWellknownTask.kt index e20fe9a304..80ede5e884 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/wellknown/GetWellknownTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/wellknown/GetWellknownTask.kt @@ -97,7 +97,7 @@ internal class DefaultGetWellknownTask @Inject constructor( // Success val homeServerBaseUrl = wellKnown.homeServer?.baseURL if (homeServerBaseUrl.isNullOrBlank()) { - WellknownResult.FailPrompt + WellknownResult.FailPrompt(null, null) } else { if (homeServerBaseUrl.isValidUrl()) { // Check that HS is a real one @@ -120,11 +120,11 @@ internal class DefaultGetWellknownTask @Inject constructor( is Failure.OtherServerError -> { when (throwable.httpCode) { HttpsURLConnection.HTTP_NOT_FOUND -> WellknownResult.Ignore - else -> WellknownResult.FailPrompt + else -> WellknownResult.FailPrompt(null, null) } } is MalformedJsonException, is EOFException -> { - WellknownResult.FailPrompt + WellknownResult.FailPrompt(null, null) } else -> { throw throwable @@ -162,7 +162,7 @@ internal class DefaultGetWellknownTask @Inject constructor( // All is ok WellknownResult.Prompt(homeServerBaseUrl, identityServerBaseUrl, wellKnown) } else { - WellknownResult.FailError + WellknownResult.FailPrompt(homeServerBaseUrl, wellKnown) } } else { WellknownResult.FailError diff --git a/vector/src/main/java/im/vector/app/features/login/LoginViewModel.kt b/vector/src/main/java/im/vector/app/features/login/LoginViewModel.kt index 93f8f7a45c..aed186bcd6 100644 --- a/vector/src/main/java/im/vector/app/features/login/LoginViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/login/LoginViewModel.kt @@ -522,6 +522,13 @@ class LoginViewModel @AssistedInject constructor( when (data) { is WellknownResult.Prompt -> onWellknownSuccess(action, data, homeServerConnectionConfig) + is WellknownResult.FailPrompt -> + // Relax on IS discovery if home server is valid + if (data.homeServerUrl != null && data.wellKnown != null) { + onWellknownSuccess(action, WellknownResult.Prompt(data.homeServerUrl!!, null, data.wellKnown!!), homeServerConnectionConfig) + } else { + onWellKnownError() + } is WellknownResult.InvalidMatrixId -> { setState { copy( @@ -531,12 +538,7 @@ class LoginViewModel @AssistedInject constructor( _viewEvents.post(LoginViewEvents.Failure(Exception(stringProvider.getString(R.string.login_signin_matrix_id_error_invalid_matrix_id)))) } else -> { - setState { - copy( - asyncLoginAction = Uninitialized - ) - } - _viewEvents.post(LoginViewEvents.Failure(Exception(stringProvider.getString(R.string.autodiscover_well_known_error)))) + onWellKnownError() } }.exhaustive } @@ -547,6 +549,15 @@ class LoginViewModel @AssistedInject constructor( }) } + private fun onWellKnownError() { + setState { + copy( + asyncLoginAction = Uninitialized + ) + } + _viewEvents.post(LoginViewEvents.Failure(Exception(stringProvider.getString(R.string.autodiscover_well_known_error)))) + } + private fun onWellknownSuccess(action: LoginAction.LoginOrRegister, wellKnownPrompt: WellknownResult.Prompt, homeServerConnectionConfig: HomeServerConnectionConfig?) {