From 71e0f6ee0ed5b608925f4c28a8bf4c882581babe Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 30 May 2023 15:50:25 +0200 Subject: [PATCH] Make the application compile with a SDK with no support for Oidc. --- .../features/login/impl/util/LoginConstants.kt | 2 +- .../impl/auth/AuthenticationException.kt | 2 ++ .../matrix/impl/auth/HomeserverDetails.kt | 2 +- .../libraries/matrix/impl/auth/OidcConfig.kt | 5 ++++- .../auth/RustMatrixAuthenticationService.kt | 18 +++++++++++++++--- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/util/LoginConstants.kt b/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/util/LoginConstants.kt index c481fdf927..cb01f8095a 100644 --- a/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/util/LoginConstants.kt +++ b/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/util/LoginConstants.kt @@ -18,6 +18,6 @@ package io.element.android.features.login.impl.util object LoginConstants { - const val DEFAULT_HOMESERVER_URL = "synapse-oidc.lab.element.dev" // "matrix.org" + const val DEFAULT_HOMESERVER_URL = "matrix.org" // TODO Oidc "synapse-oidc.lab.element.dev" const val SLIDING_SYNC_READ_MORE_URL = "https://github.com/matrix-org/sliding-sync/blob/main/docs/Landing.md" } diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/AuthenticationException.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/AuthenticationException.kt index b98ecc193f..c264a95f67 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/AuthenticationException.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/AuthenticationException.kt @@ -27,11 +27,13 @@ fun Throwable.mapAuthenticationException(): Throwable { is RustAuthenticationException.SessionMissing -> AuthenticationException.SessionMissing(this.message!!) is RustAuthenticationException.SlidingSyncNotAvailable -> AuthenticationException.SlidingSyncNotAvailable(this.message!!) + /* TODO Oidc is RustAuthenticationException.OidcException -> AuthenticationException.OidcError("OidcException", message!!) is RustAuthenticationException.OidcMetadataInvalid -> AuthenticationException.OidcError("OidcMetadataInvalid", message!!) is RustAuthenticationException.OidcMetadataMissing -> AuthenticationException.OidcError("OidcMetadataMissing", message!!) is RustAuthenticationException.OidcNotStarted -> AuthenticationException.OidcError("OidcNotStarted", message!!) is RustAuthenticationException.OidcNotSupported -> AuthenticationException.OidcError("OidcNotSupported", message!!) + */ else -> this } diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/HomeserverDetails.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/HomeserverDetails.kt index f1d3e34bf8..a3d277c6da 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/HomeserverDetails.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/HomeserverDetails.kt @@ -23,6 +23,6 @@ fun HomeserverLoginDetails.map(): MatrixHomeServerDetails = use { MatrixHomeServerDetails( url = url(), supportsPasswordLogin = supportsPasswordLogin(), - supportsOidcLogin = supportsOidcLogin(), + supportsOidcLogin = false // TODO Oidc supportsOidcLogin(), ) } diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/OidcConfig.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/OidcConfig.kt index 774c22781b..1ba5063df9 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/OidcConfig.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/OidcConfig.kt @@ -17,8 +17,10 @@ package io.element.android.libraries.matrix.impl.auth import io.element.android.libraries.matrix.api.auth.OidcConfig -import org.matrix.rustcomponents.sdk.OidcClientMetadata +// TODO Oidc +// import org.matrix.rustcomponents.sdk.OidcClientMetadata +/* val oidcClientMetadata: OidcClientMetadata = OidcClientMetadata( clientName = "Element", redirectUri = OidcConfig.redirectUri, @@ -26,4 +28,5 @@ val oidcClientMetadata: OidcClientMetadata = OidcClientMetadata( tosUri = "https://element.io/user-terms-of-service", policyUri = "https://element.io/privacy" ) + */ diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt index aaf85ce8fc..4aea938e42 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/auth/RustMatrixAuthenticationService.kt @@ -36,7 +36,8 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.withContext import org.matrix.rustcomponents.sdk.Client import org.matrix.rustcomponents.sdk.ClientBuilder -import org.matrix.rustcomponents.sdk.OidcAuthenticationUrl +// TODO Oidc +// import org.matrix.rustcomponents.sdk.OidcAuthenticationUrl import org.matrix.rustcomponents.sdk.Session import org.matrix.rustcomponents.sdk.use import java.io.File @@ -55,7 +56,8 @@ class RustMatrixAuthenticationService @Inject constructor( private val authService: RustAuthenticationService = RustAuthenticationService( basePath = baseDirectory.absolutePath, passphrase = null, - oidcClientMetadata = oidcClientMetadata, + // TODO Oidc + // oidcClientMetadata = oidcClientMetadata, customSlidingSyncProxy = null ) private var currentHomeserver = MutableStateFlow(null) @@ -114,9 +116,12 @@ class RustMatrixAuthenticationService @Inject constructor( } } - private var pendingUrlForOidcLogin: OidcAuthenticationUrl? = null + // TODO Oidc + // private var pendingUrlForOidcLogin: OidcAuthenticationUrl? = null override suspend fun getOidcUrl(): Result { + TODO("Oidc") + /* return withContext(coroutineDispatchers.io) { runCatching { val urlForOidcLogin = authService.urlForOidcLogin() @@ -127,9 +132,12 @@ class RustMatrixAuthenticationService @Inject constructor( failure.mapAuthenticationException() } } + */ } override suspend fun cancelOidcLogin(): Result { + TODO("Oidc") + /* return withContext(coroutineDispatchers.io) { runCatching { pendingUrlForOidcLogin?.close() @@ -138,12 +146,15 @@ class RustMatrixAuthenticationService @Inject constructor( failure.mapAuthenticationException() } } + */ } /** * callbackUrl should be the uriRedirect from OidcClientMetadata (with all the parameters). */ override suspend fun loginWithOidc(callbackUrl: String): Result { + TODO("Oidc") + /* return withContext(coroutineDispatchers.io) { runCatching { val urlForOidcLogin = pendingUrlForOidcLogin ?: error("You need to call `getOidcUrl()` first") @@ -156,6 +167,7 @@ class RustMatrixAuthenticationService @Inject constructor( failure.mapAuthenticationException() } } + */ } private fun createMatrixClient(client: Client): MatrixClient {