mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:32:34 +00:00
Remove ExternalSession, fallback login with Element Web is gone.
This commit is contained in:
-34
@@ -27,7 +27,6 @@ import io.element.android.libraries.matrix.api.auth.MatrixHomeServerDetails
|
||||
import io.element.android.libraries.matrix.api.auth.OAuthDetails
|
||||
import io.element.android.libraries.matrix.api.auth.OAuthPrompt
|
||||
import io.element.android.libraries.matrix.api.auth.SessionRestorationException
|
||||
import io.element.android.libraries.matrix.api.auth.external.ExternalSession
|
||||
import io.element.android.libraries.matrix.api.auth.qrlogin.MatrixQrCodeLoginData
|
||||
import io.element.android.libraries.matrix.api.auth.qrlogin.QrCodeLoginStep
|
||||
import io.element.android.libraries.matrix.api.core.SessionId
|
||||
@@ -232,39 +231,6 @@ class RustMatrixAuthenticationService(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun importCreatedSession(externalSession: ExternalSession): Result<SessionId> =
|
||||
withContext(coroutineDispatchers.io) {
|
||||
runCatchingExceptions {
|
||||
val client = currentClient ?: error("You need to call `setHomeserver()` first")
|
||||
val currentSessionPaths = sessionPaths ?: error("You need to call `setHomeserver()` first")
|
||||
val sessionData = externalSession.toSessionData(
|
||||
isTokenValid = true,
|
||||
loginType = LoginType.PASSWORD,
|
||||
passphrase = pendingKey.formattedAsString(),
|
||||
sessionPaths = currentSessionPaths,
|
||||
)
|
||||
|
||||
// We restore the client using the just retrieved session data
|
||||
client.restoreSession(sessionData.toSession())
|
||||
val matrixClient = rustMatrixClientFactory.create(client, sessionData, isMessageSearchAvailable())
|
||||
|
||||
// Apply enterprise hooks to the newly created client as soon as possible
|
||||
clientEnterpriseHook(matrixClient)
|
||||
|
||||
// We wait for the verification state to be known
|
||||
matrixClient.waitForKnownVerificationState()
|
||||
|
||||
// And once it's ready we share it and save the actual session data
|
||||
newMatrixClientObservers.forEach { it.invoke(matrixClient) }
|
||||
sessionStore.addSession(sessionData)
|
||||
|
||||
// Clean up the strong reference held here since it's no longer necessary
|
||||
clear(destroyClient = false)
|
||||
|
||||
SessionId(sessionData.userId)
|
||||
}
|
||||
}
|
||||
|
||||
private var pendingOAuthAuthorizationData: OAuthAuthorizationData? = null
|
||||
|
||||
override suspend fun getOAuthUrl(
|
||||
|
||||
-25
@@ -8,7 +8,6 @@
|
||||
|
||||
package io.element.android.libraries.matrix.impl.mapper
|
||||
|
||||
import io.element.android.libraries.matrix.api.auth.external.ExternalSession
|
||||
import io.element.android.libraries.matrix.api.paths.SessionPaths
|
||||
import io.element.android.libraries.sessionstorage.api.LoginType
|
||||
import io.element.android.libraries.sessionstorage.api.SessionData
|
||||
@@ -40,27 +39,3 @@ internal fun Session.toSessionData(
|
||||
userDisplayName = null,
|
||||
userAvatarUrl = null,
|
||||
)
|
||||
|
||||
internal fun ExternalSession.toSessionData(
|
||||
isTokenValid: Boolean,
|
||||
loginType: LoginType,
|
||||
passphrase: String?,
|
||||
sessionPaths: SessionPaths,
|
||||
) = SessionData(
|
||||
userId = userId,
|
||||
deviceId = deviceId,
|
||||
accessToken = accessToken,
|
||||
refreshToken = refreshToken,
|
||||
homeserverUrl = homeserverUrl,
|
||||
oAuthData = null,
|
||||
loginTimestamp = Date(),
|
||||
isTokenValid = isTokenValid,
|
||||
loginType = loginType,
|
||||
passphrase = passphrase,
|
||||
sessionPath = sessionPaths.fileDirectory.absolutePath,
|
||||
cachePath = sessionPaths.cacheDirectory.absolutePath,
|
||||
position = 0,
|
||||
lastUsageIndex = 0,
|
||||
userDisplayName = null,
|
||||
userAvatarUrl = null,
|
||||
)
|
||||
|
||||
-48
@@ -9,7 +9,6 @@
|
||||
package io.element.android.libraries.matrix.impl.mapper
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.matrix.api.auth.external.ExternalSession
|
||||
import io.element.android.libraries.matrix.api.paths.SessionPaths
|
||||
import io.element.android.libraries.matrix.impl.fixtures.factories.aRustSession
|
||||
import io.element.android.libraries.matrix.test.A_DEVICE_ID
|
||||
@@ -67,51 +66,4 @@ class SessionKtTest {
|
||||
)
|
||||
assertThat(result.homeserverUrl).isEqualTo(A_HOMESERVER_URL_2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ExternalSession toSessionData compute the expected result`() {
|
||||
val result = anExternalSession().toSessionData(
|
||||
isTokenValid = true,
|
||||
loginType = LoginType.PASSWORD,
|
||||
passphrase = A_SECRET,
|
||||
sessionPaths = SessionPaths(File("/a/file"), File("/a/cache")),
|
||||
)
|
||||
assertThat(result.userId).isEqualTo(A_USER_ID.value)
|
||||
assertThat(result.deviceId).isEqualTo(A_DEVICE_ID.value)
|
||||
assertThat(result.accessToken).isEqualTo("accessToken")
|
||||
assertThat(result.refreshToken).isNull()
|
||||
assertThat(result.homeserverUrl).isEqualTo(A_HOMESERVER_URL)
|
||||
assertThat(result.isTokenValid).isTrue()
|
||||
assertThat(result.oAuthData).isNull()
|
||||
assertThat(result.loginType).isEqualTo(LoginType.PASSWORD)
|
||||
assertThat(result.loginTimestamp).isNotNull()
|
||||
assertThat(result.passphrase).isEqualTo(A_SECRET)
|
||||
assertThat(result.sessionPath).isEqualTo("/a/file")
|
||||
assertThat(result.cachePath).isEqualTo("/a/cache")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ExternalSession toSessionData can change the validity of the token`() {
|
||||
val result = anExternalSession().toSessionData(
|
||||
isTokenValid = false,
|
||||
loginType = LoginType.PASSWORD,
|
||||
passphrase = A_SECRET,
|
||||
sessionPaths = SessionPaths(File("/a/file"), File("/a/cache")),
|
||||
)
|
||||
assertThat(result.isTokenValid).isFalse()
|
||||
}
|
||||
}
|
||||
|
||||
private fun anExternalSession(
|
||||
userId: String = A_USER_ID.value,
|
||||
deviceId: String = A_DEVICE_ID.value,
|
||||
accessToken: String = "accessToken",
|
||||
refreshToken: String? = null,
|
||||
homeserverUrl: String = A_HOMESERVER_URL,
|
||||
) = ExternalSession(
|
||||
userId = userId,
|
||||
deviceId = deviceId,
|
||||
accessToken = accessToken,
|
||||
refreshToken = refreshToken,
|
||||
homeserverUrl = homeserverUrl,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user