mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-10-31 16:22:49 +00:00
Remove ExternalSession, fallback login with Element Web is gone.
This commit is contained in:
-8
@@ -10,7 +10,6 @@ package io.element.android.libraries.matrix.api.auth
|
||||
|
||||
import io.element.android.libraries.matrix.api.MatrixClient
|
||||
import io.element.android.libraries.matrix.api.MatrixClientProvider
|
||||
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
|
||||
@@ -47,13 +46,6 @@ interface MatrixAuthenticationService {
|
||||
*/
|
||||
suspend fun login(username: String, password: String): Result<SessionId>
|
||||
|
||||
/**
|
||||
* Import a session that was created using another client, for instance Element Web.
|
||||
*
|
||||
* @param externalSession the tokens and identifiers of the session to import.
|
||||
*/
|
||||
suspend fun importCreatedSession(externalSession: ExternalSession): Result<SessionId>
|
||||
|
||||
/*
|
||||
* OAuth part.
|
||||
*/
|
||||
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Element Creations Ltd.
|
||||
* Copyright 2024, 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.api.auth.external
|
||||
|
||||
/***
|
||||
* Represents a session data of a session created by another client.
|
||||
*/
|
||||
data class ExternalSession(
|
||||
val userId: String,
|
||||
val deviceId: String,
|
||||
val accessToken: String,
|
||||
val refreshToken: String?,
|
||||
val homeserverUrl: String,
|
||||
)
|
||||
-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,
|
||||
)
|
||||
|
||||
-6
@@ -14,7 +14,6 @@ import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService
|
||||
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.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
|
||||
@@ -32,7 +31,6 @@ class FakeMatrixAuthenticationService(
|
||||
var matrixClientResult: ((SessionId) -> Result<MatrixClient>)? = null,
|
||||
var loginWithQrCodeResult: (qrCodeData: MatrixQrCodeLoginData, progress: (QrCodeLoginStep) -> Unit) -> Result<SessionId> =
|
||||
lambdaRecorder<MatrixQrCodeLoginData, (QrCodeLoginStep) -> Unit, Result<SessionId>> { _, _ -> Result.success(A_SESSION_ID) },
|
||||
private val importCreatedSessionLambda: (ExternalSession) -> Result<SessionId> = { lambdaError() },
|
||||
private val setHomeserverResult: (String) -> Result<MatrixHomeServerDetails> = { lambdaError() },
|
||||
private val setElementClassicSessionResult: (ElementClassicSession?) -> Unit = { lambdaError() },
|
||||
private val doSecretsContainBackupKeyResult: (UserId, String, String) -> Boolean = { _, _, _ -> lambdaError() },
|
||||
@@ -66,10 +64,6 @@ class FakeMatrixAuthenticationService(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun importCreatedSession(externalSession: ExternalSession): Result<SessionId> = simulateLongTask {
|
||||
return importCreatedSessionLambda(externalSession)
|
||||
}
|
||||
|
||||
/** The login hint passed to the most recent [getOAuthUrl] call. */
|
||||
var getOAuthUrlLoginHint: String? = null
|
||||
private set
|
||||
|
||||
Reference in New Issue
Block a user