exposing if the homeserver supports signing out all devices when starting the reset process

This commit is contained in:
Adam Brown 2022-05-30 16:51:23 +01:00
parent 924e668023
commit c10254dbfa
6 changed files with 50 additions and 3 deletions

View File

@ -18,6 +18,7 @@ package org.matrix.android.sdk.api.auth.login
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.util.JsonDict
import org.matrix.android.sdk.internal.auth.login.ResetCapabilities
/**
* Set of methods to be able to login to an existing account on a homeserver.
@ -65,8 +66,9 @@ interface LoginWizard {
* [resetPasswordMailConfirmed] is successfully called.
*
* @param email an email previously associated to the account the user wants the password to be reset.
* @return a [ResetCapabilities] if the reset is successful
*/
suspend fun resetPassword(email: String)
suspend fun resetPassword(email: String): ResetCapabilities
/**
* Confirm the new password, once the user has checked their email

View File

@ -31,6 +31,7 @@ import org.matrix.android.sdk.internal.auth.data.TokenLoginParams
import org.matrix.android.sdk.internal.auth.db.PendingSessionData
import org.matrix.android.sdk.internal.auth.registration.AddThreePidRegistrationParams
import org.matrix.android.sdk.internal.auth.registration.RegisterAddThreePidTask
import org.matrix.android.sdk.internal.auth.version.doesServerSupportLogoutDevices
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.content.DefaultContentUrlResolver
import org.matrix.android.sdk.internal.session.contentscanner.DisabledContentScannerService
@ -103,7 +104,7 @@ internal class DefaultLoginWizard(
return sessionCreator.createSession(credentials, pendingSessionData.homeServerConnectionConfig)
}
override suspend fun resetPassword(email: String) {
override suspend fun resetPassword(email: String): ResetCapabilities {
val param = RegisterAddThreePidTask.Params(
RegisterThreePid.Email(email),
pendingSessionData.clientSecret,
@ -119,6 +120,13 @@ internal class DefaultLoginWizard(
pendingSessionData = pendingSessionData.copy(resetPasswordData = ResetPasswordData(result))
.also { pendingSessionStore.savePendingSessionData(it) }
val versions = executeRequest(null) {
authAPI.versions()
}
return ResetCapabilities(supportsLogoutAllDevices = versions.doesServerSupportLogoutDevices())
}
override suspend fun resetPasswordMailConfirmed(newPassword: String) {

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.auth.login
/**
* The reset capabilities of the selected Homeserver
*/
data class ResetCapabilities(
/**
* True if the server supports MSC2457 `logout_devices` parameter when setting a new password.
*/
val supportsLogoutAllDevices: Boolean
)

View File

@ -58,6 +58,7 @@ internal data class HomeServerVersion(
val r0_4_0 = HomeServerVersion(major = 0, minor = 4, patch = 0)
val r0_5_0 = HomeServerVersion(major = 0, minor = 5, patch = 0)
val r0_6_0 = HomeServerVersion(major = 0, minor = 6, patch = 0)
val r0_6_1 = HomeServerVersion(major = 0, minor = 6, patch = 1)
val v1_3_0 = HomeServerVersion(major = 1, minor = 3, patch = 0)
}
}

View File

@ -111,6 +111,15 @@ private fun Versions.doesServerSeparatesAddAndBind(): Boolean {
unstableFeatures?.get(FEATURE_SEPARATE_ADD_AND_BIND) ?: false
}
/**
* Indicate if the server supports MSC2457 `logout_devices` parameter when setting a new password
*
* @return true if logout_devices is supported
*/
internal fun Versions.doesServerSupportLogoutDevices(): Boolean {
return getMaxVersion() >= HomeServerVersion.r0_6_1
}
private fun Versions.getMaxVersion(): HomeServerVersion {
return supportedVersions
?.mapNotNull { HomeServerVersion.parse(it) }

View File

@ -87,7 +87,7 @@ data class PersonalizationState(
@Parcelize
data class ResetState(
val email: String? = null,
val newPassword: String? = null,
val newPassword: String? = null
) : Parcelable
@Parcelize