Login screens: ensure homeserver version is supported - fix bug for SSO

This commit is contained in:
Benoit Marty 2019-11-26 12:16:39 +01:00
parent 9b207dd5dc
commit 3eb2e1655f
4 changed files with 40 additions and 22 deletions

View File

@ -20,6 +20,10 @@ import im.vector.matrix.android.internal.auth.data.LoginFlowResponse
// Either a LoginFlowResponse, or an error if the homeserver is outdated
sealed class LoginFlowResult {
data class Success(val loginFlowResponse: LoginFlowResponse) : LoginFlowResult()
data class Success(
val loginFlowResponse: LoginFlowResponse,
val isLoginAndRegistrationSupported: Boolean
) : LoginFlowResult()
object OutdatedHomeserver : LoginFlowResult()
}

View File

@ -47,13 +47,13 @@ data class Versions(
)
// MatrixClientServerAPIVersion
private const val r0_0_1 = "r0_0_1"
private const val r0_1_0 = "r0_1_0"
private const val r0_2_0 = "r0_2_0"
private const val r0_3_0 = "r0_3_0"
private const val r0_4_0 = "r0_4_0"
private const val r0_5_0 = "r0_5_0"
private const val r0_6_0 = "r0_6_0"
private const val r0_0_1 = "r0.0.1"
private const val r0_1_0 = "r0.1.0"
private const val r0_2_0 = "r0.2.0"
private const val r0_3_0 = "r0.3.0"
private const val r0_4_0 = "r0.4.0"
private const val r0_5_0 = "r0.5.0"
private const val r0_6_0 = "r0.6.0"
// MatrixVersionsFeature
private const val FEATURE_LAZY_LOAD_MEMBERS = "m.lazy_load_members"
@ -67,7 +67,13 @@ private const val FEATURE_SEPARATE_ADD_AND_BIND = "m.separate_add_and_bind"
*/
fun Versions.isSupportedBySdk(): Boolean {
return supportLazyLoadMembers()
&& !doesServerRequireIdentityServerParam()
}
/**
* Return true if the SDK supports this homeserver version for login and registration
*/
fun Versions.isLoginAndRegistrationSupportedBySdk(): Boolean {
return !doesServerRequireIdentityServerParam()
&& doesServerAcceptIdentityAccessToken()
&& doesServerSeparatesAddAndBind()
}

View File

@ -102,7 +102,7 @@ internal class DefaultAuthenticationService @Inject constructor(@Unauthenticated
val loginFlowResponse = executeRequest<LoginFlowResponse> {
apiCall = authAPI.getLoginFlows()
}
LoginFlowResult.Success(loginFlowResponse)
LoginFlowResult.Success(loginFlowResponse, versions.isLoginAndRegistrationSupportedBySdk())
} else {
// Not supported
LoginFlowResult.OutdatedHomeserver

View File

@ -545,24 +545,32 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
else -> LoginMode.Unsupported(data.loginFlowResponse.flows.mapNotNull { it.type }.toList())
}
setState {
copy(
asyncHomeServerLoginFlowRequest = Success(loginMode)
)
if (loginMode == LoginMode.Password && !data.isLoginAndRegistrationSupported) {
notSupported()
} else {
setState {
copy(
asyncHomeServerLoginFlowRequest = Success(loginMode)
)
}
}
}
is LoginFlowResult.OutdatedHomeserver -> {
// Notify the UI
_viewEvents.post(LoginViewEvents.OutdatedHomeserver)
setState {
copy(
asyncHomeServerLoginFlowRequest = Uninitialized
)
}
notSupported()
}
}
}
private fun notSupported() {
// Notify the UI
_viewEvents.post(LoginViewEvents.OutdatedHomeserver)
setState {
copy(
asyncHomeServerLoginFlowRequest = Uninitialized
)
}
}
})
}
}