Rename OIDC components and variables to OAuth (#6686)

* Rename `OIDC` components and variables to `OAuth`. This matches the new behavior in the SDK.
This commit is contained in:
Jorge Martin Espinosa 2026-04-29 11:41:47 +02:00 committed by GitHub
parent 7dd81dc838
commit 367995303d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
96 changed files with 479 additions and 482 deletions

View file

@ -31,7 +31,7 @@ import io.element.android.libraries.matrix.api.createroom.RoomPreset
import io.element.android.libraries.matrix.api.linknewdevice.LinkDesktopHandler
import io.element.android.libraries.matrix.api.linknewdevice.LinkMobileHandler
import io.element.android.libraries.matrix.api.media.MatrixMediaLoader
import io.element.android.libraries.matrix.api.oidc.AccountManagementAction
import io.element.android.libraries.matrix.api.oauth.AccountManagementAction
import io.element.android.libraries.matrix.api.room.BaseRoom
import io.element.android.libraries.matrix.api.room.CurrentUserMembership
import io.element.android.libraries.matrix.api.room.JoinedRoom
@ -59,7 +59,7 @@ import io.element.android.libraries.matrix.impl.media.RustMediaLoader
import io.element.android.libraries.matrix.impl.media.RustMediaPreviewService
import io.element.android.libraries.matrix.impl.notification.RustNotificationService
import io.element.android.libraries.matrix.impl.notificationsettings.RustNotificationSettingsService
import io.element.android.libraries.matrix.impl.oidc.toRustAction
import io.element.android.libraries.matrix.impl.oauth.toRustAction
import io.element.android.libraries.matrix.impl.pushers.RustPushersService
import io.element.android.libraries.matrix.impl.room.GetRoomResult
import io.element.android.libraries.matrix.impl.room.NotJoinedRustRoom

View file

@ -214,5 +214,5 @@ fun SessionData.toSession() = Session(
deviceId = deviceId,
homeserverUrl = homeserverUrl,
slidingSyncVersion = SlidingSyncVersion.NATIVE,
oauthData = oidcData,
oauthData = oAuthData,
)

View file

@ -30,11 +30,11 @@ fun Throwable.mapAuthenticationException(): AuthenticationException {
is ClientBuildException.EventCache -> AuthenticationException.Generic(message)
}
is OAuthException -> when (this) {
is OAuthException.Generic -> AuthenticationException.Oidc(message)
is OAuthException.CallbackUrlInvalid -> AuthenticationException.Oidc(message)
is OAuthException.Cancelled -> AuthenticationException.Oidc(message)
is OAuthException.MetadataInvalid -> AuthenticationException.Oidc(message)
is OAuthException.NotSupported -> AuthenticationException.Oidc(message)
is OAuthException.Generic -> AuthenticationException.OAuth(message)
is OAuthException.CallbackUrlInvalid -> AuthenticationException.OAuth(message)
is OAuthException.Cancelled -> AuthenticationException.OAuth(message)
is OAuthException.MetadataInvalid -> AuthenticationException.OAuth(message)
is OAuthException.NotSupported -> AuthenticationException.OAuth(message)
}
else -> AuthenticationException.Generic(message)
}

View file

@ -15,6 +15,6 @@ fun HomeserverLoginDetails.map(): MatrixHomeServerDetails = use {
MatrixHomeServerDetails(
url = url(),
supportsPasswordLogin = supportsPasswordLogin(),
supportsOidcLogin = supportsOauthLogin(),
supportsOAuthLogin = supportsOauthLogin(),
)
}

View file

@ -10,22 +10,22 @@ package io.element.android.libraries.matrix.impl.auth
import dev.zacsweers.metro.Inject
import io.element.android.libraries.core.meta.BuildMeta
import io.element.android.libraries.matrix.api.auth.OidcConfig
import io.element.android.libraries.matrix.api.auth.OidcRedirectUrlProvider
import io.element.android.libraries.matrix.api.auth.OAuthConfig
import io.element.android.libraries.matrix.api.auth.OAuthRedirectUrlProvider
import org.matrix.rustcomponents.sdk.OAuthConfiguration
@Inject
class OidcConfigurationProvider(
class OAuthConfigurationProvider(
private val buildMeta: BuildMeta,
private val oidcRedirectUrlProvider: OidcRedirectUrlProvider,
private val oAuthRedirectUrlProvider: OAuthRedirectUrlProvider,
) {
fun get(): OAuthConfiguration = OAuthConfiguration(
clientName = buildMeta.applicationName,
redirectUri = oidcRedirectUrlProvider.provide(),
clientUri = OidcConfig.CLIENT_URI,
logoUri = OidcConfig.LOGO_URI,
tosUri = OidcConfig.TOS_URI,
policyUri = OidcConfig.POLICY_URI,
staticRegistrations = OidcConfig.STATIC_REGISTRATIONS,
redirectUri = oAuthRedirectUrlProvider.provide(),
clientUri = OAuthConfig.CLIENT_URI,
logoUri = OAuthConfig.LOGO_URI,
tosUri = OAuthConfig.TOS_URI,
policyUri = OAuthConfig.POLICY_URI,
staticRegistrations = OAuthConfig.STATIC_REGISTRATIONS,
)
}

View file

@ -8,13 +8,13 @@
package io.element.android.libraries.matrix.impl.auth
import io.element.android.libraries.matrix.api.auth.OidcPrompt
import org.matrix.rustcomponents.sdk.OAuthPrompt as RustOidcPrompt
import io.element.android.libraries.matrix.api.auth.OAuthPrompt
import org.matrix.rustcomponents.sdk.OAuthPrompt as RustOAuthPrompt
internal fun OidcPrompt.toRustPrompt(): RustOidcPrompt {
internal fun OAuthPrompt.toRustPrompt(): RustOAuthPrompt {
return when (this) {
OidcPrompt.Login -> RustOidcPrompt.Unknown("consent")
OidcPrompt.Create -> RustOidcPrompt.Create
is OidcPrompt.Unknown -> RustOidcPrompt.Unknown(value)
OAuthPrompt.Login -> RustOAuthPrompt.Unknown("consent")
OAuthPrompt.Create -> RustOAuthPrompt.Create
is OAuthPrompt.Unknown -> RustOAuthPrompt.Unknown(value)
}
}

View file

@ -31,7 +31,7 @@ class RustHomeServerLoginCompatibilityChecker(
it.homeserverLoginDetails()
}
.use {
Timber.d("Homeserver $url | OIDC: ${it.supportsOauthLogin()} | Password: ${it.supportsPasswordLogin()} | SSO: ${it.supportsSsoLogin()}")
Timber.d("Homeserver $url | OAuth: ${it.supportsOauthLogin()} | Password: ${it.supportsPasswordLogin()} | SSO: ${it.supportsSsoLogin()}")
it.supportsOauthLogin() || it.supportsPasswordLogin()
}
}

View file

@ -19,8 +19,8 @@ import io.element.android.libraries.matrix.api.auth.AuthenticationException
import io.element.android.libraries.matrix.api.auth.ElementClassicSession
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.OidcDetails
import io.element.android.libraries.matrix.api.auth.OidcPrompt
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
@ -65,7 +65,7 @@ class RustMatrixAuthenticationService(
private val sessionStore: SessionStore,
private val rustMatrixClientFactory: RustMatrixClientFactory,
private val passphraseGenerator: PassphraseGenerator,
private val oidcConfigurationProvider: OidcConfigurationProvider,
private val oAuthConfigurationProvider: OAuthConfigurationProvider,
) : MatrixAuthenticationService {
// Any existing Element Classic session that we want to try to import secrets from during login.
private var elementClassicSession: ElementClassicSession? = null
@ -253,15 +253,15 @@ class RustMatrixAuthenticationService(
private var pendingOAuthAuthorizationData: OAuthAuthorizationData? = null
override suspend fun getOidcUrl(
prompt: OidcPrompt,
override suspend fun getOAuthUrl(
prompt: OAuthPrompt,
loginHint: String?,
): Result<OidcDetails> {
): Result<OAuthDetails> {
return withContext(coroutineDispatchers.io) {
runCatchingExceptions {
val client = currentClient ?: error("You need to call `setHomeserver()` first")
val oAuthAuthorizationData = client.urlForOauth(
oauthConfiguration = oidcConfigurationProvider.get(),
oauthConfiguration = oAuthConfigurationProvider.get(),
prompt = prompt.toRustPrompt(),
loginHint = loginHint,
// If we want to restore a previous session for which we have encryption keys, we can pass the deviceId here. At the moment, we don't
@ -270,15 +270,15 @@ class RustMatrixAuthenticationService(
)
val url = oAuthAuthorizationData.loginUrl()
pendingOAuthAuthorizationData = oAuthAuthorizationData
OidcDetails(url)
OAuthDetails(url)
}.mapFailure { failure ->
Timber.e(failure, "Failed to get OIDC URL")
Timber.e(failure, "Failed to get OAuth URL")
failure.mapAuthenticationException()
}
}
}
override suspend fun cancelOidcLogin(): Result<Unit> {
override suspend fun cancelOAuthLogin(): Result<Unit> {
return withContext(coroutineDispatchers.io) {
runCatchingExceptions {
pendingOAuthAuthorizationData?.use {
@ -286,7 +286,7 @@ class RustMatrixAuthenticationService(
}
pendingOAuthAuthorizationData = null
}.mapFailure { failure ->
Timber.e(failure, "Failed to cancel OIDC login")
Timber.e(failure, "Failed to cancel OAuth login")
failure.mapAuthenticationException()
}
}
@ -297,9 +297,9 @@ class RustMatrixAuthenticationService(
}
/**
* callbackUrl should be the uriRedirect from OidcClientMetadata (with all the parameters).
* callbackUrl should be the `url` from `OAuthAction` (with all the parameters).
*/
override suspend fun loginWithOidc(callbackUrl: String): Result<SessionId> {
override suspend fun loginWithOAuth(callbackUrl: String): Result<SessionId> {
return withContext(coroutineDispatchers.io) {
runCatchingExceptions {
val client = currentClient ?: error("You need to call `setHomeserver()` first")
@ -330,7 +330,7 @@ class RustMatrixAuthenticationService(
SessionId(sessionData.userId)
}.mapFailure { failure ->
Timber.e(failure, "Failed to login with OIDC")
Timber.e(failure, "Failed to login with OAuth")
failure.mapAuthenticationException()
}
}
@ -355,7 +355,7 @@ class RustMatrixAuthenticationService(
withContext(coroutineDispatchers.io) {
val sdkQrCodeLoginData = (qrCodeData as SdkQrCodeLoginData).rustQrCodeData
val emptySessionPaths = rotateSessionPath()
val oidcConfiguration = oidcConfigurationProvider.get()
val oAuthConfiguration = oAuthConfigurationProvider.get()
val progressListener = object : QrLoginProgressListener {
override fun onUpdate(state: QrLoginProgress) {
Timber.d("QR Code login progress: $state")
@ -368,7 +368,7 @@ class RustMatrixAuthenticationService(
qrCodeData = sdkQrCodeLoginData,
)
client.newLoginWithQrCodeHandler(
oauthConfiguration = oidcConfiguration,
oauthConfiguration = oAuthConfiguration,
).use {
it.scan(
qrCodeData = qrCodeData.rustQrCodeData,

View file

@ -42,7 +42,7 @@ object QrErrorMapper {
is RustHumanQrLoginException.OtherDeviceNotSignedIn -> QrLoginException.OtherDeviceNotSignedIn
is RustHumanQrLoginException.LinkingNotSupported -> QrLoginException.LinkingNotSupported
is RustHumanQrLoginException.Unknown -> QrLoginException.Unknown
is RustHumanQrLoginException.OAuthMetadataInvalid -> QrLoginException.OidcMetadataInvalid
is RustHumanQrLoginException.OAuthMetadataInvalid -> QrLoginException.OAuthMetadataInvalid
is RustHumanQrLoginException.SlidingSyncNotAvailable -> QrLoginException.SlidingSyncNotAvailable
is RustHumanQrLoginException.CheckCodeAlreadySent -> QrLoginException.CheckCodeAlreadySent
is RustHumanQrLoginException.CheckCodeCannotBeSent -> QrLoginException.CheckCodeCannotBeSent

View file

@ -10,7 +10,7 @@ package io.element.android.libraries.matrix.impl.encryption
import io.element.android.libraries.core.extensions.runCatchingExceptions
import io.element.android.libraries.matrix.api.core.UserId
import io.element.android.libraries.matrix.api.encryption.IdentityOidcResetHandle
import io.element.android.libraries.matrix.api.encryption.IdentityOAuthResetHandle
import io.element.android.libraries.matrix.api.encryption.IdentityPasswordResetHandle
import io.element.android.libraries.matrix.api.encryption.IdentityResetHandle
import org.matrix.rustcomponents.sdk.AuthData
@ -25,7 +25,7 @@ object RustIdentityResetHandleFactory {
return runCatchingExceptions {
identityResetHandle?.let {
when (val authType = identityResetHandle.authType()) {
is CrossSigningResetAuthType.OAuth -> RustOidcIdentityResetHandle(identityResetHandle, authType.info.approvalUrl)
is CrossSigningResetAuthType.OAuth -> RustIdentityOAuthResetHandle(identityResetHandle, authType.info.approvalUrl)
// User interactive authentication (user + password)
CrossSigningResetAuthType.Uiaa -> RustPasswordIdentityResetHandle(userId, identityResetHandle)
}
@ -47,11 +47,11 @@ class RustPasswordIdentityResetHandle(
}
}
class RustOidcIdentityResetHandle(
class RustIdentityOAuthResetHandle(
private val identityResetHandle: org.matrix.rustcomponents.sdk.IdentityResetHandle,
override val url: String,
) : IdentityOidcResetHandle {
override suspend fun resetOidc(): Result<Unit> {
) : IdentityOAuthResetHandle {
override suspend fun resetOAuth(): Result<Unit> {
return runCatchingExceptions { identityResetHandle.reset(null) }
}

View file

@ -27,7 +27,7 @@ internal fun Session.toSessionData(
accessToken = accessToken,
refreshToken = refreshToken,
homeserverUrl = homeserverUrl ?: this.homeserverUrl,
oidcData = oauthData,
oAuthData = oauthData,
loginTimestamp = Date(),
isTokenValid = isTokenValid,
loginType = loginType,
@ -52,7 +52,7 @@ internal fun ExternalSession.toSessionData(
accessToken = accessToken,
refreshToken = refreshToken,
homeserverUrl = homeserverUrl,
oidcData = null,
oAuthData = null,
loginTimestamp = Date(),
isTokenValid = isTokenValid,
loginType = loginType,

View file

@ -6,9 +6,9 @@
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.libraries.matrix.impl.oidc
package io.element.android.libraries.matrix.impl.oauth
import io.element.android.libraries.matrix.api.oidc.AccountManagementAction
import io.element.android.libraries.matrix.api.oauth.AccountManagementAction
import org.matrix.rustcomponents.sdk.AccountManagementAction as RustAccountManagementAction
fun AccountManagementAction.toRustAction(): RustAccountManagementAction {

View file

@ -64,17 +64,17 @@ class AuthenticationExceptionMappingTest {
}
@Test
fun `mapping Oidc exceptions map to the Oidc Kotlin`() {
fun `mapping Oidc exceptions map to the OAuth Kotlin`() {
assertThat(OAuthException.Generic("Generic").mapAuthenticationException())
.isException<AuthenticationException.Oidc>("Generic")
.isException<AuthenticationException.OAuth>("Generic")
assertThat(OAuthException.CallbackUrlInvalid("CallbackUrlInvalid").mapAuthenticationException())
.isException<AuthenticationException.Oidc>("CallbackUrlInvalid")
.isException<AuthenticationException.OAuth>("CallbackUrlInvalid")
assertThat(OAuthException.Cancelled("Cancelled").mapAuthenticationException())
.isException<AuthenticationException.Oidc>("Cancelled")
.isException<AuthenticationException.OAuth>("Cancelled")
assertThat(OAuthException.MetadataInvalid("MetadataInvalid").mapAuthenticationException())
.isException<AuthenticationException.Oidc>("MetadataInvalid")
.isException<AuthenticationException.OAuth>("MetadataInvalid")
assertThat(OAuthException.NotSupported("NotSupported").mapAuthenticationException())
.isException<AuthenticationException.Oidc>("NotSupported")
.isException<AuthenticationException.OAuth>("NotSupported")
}
private inline fun <reified T> ThrowableSubject.isException(message: String) {

View file

@ -20,7 +20,7 @@ class HomeserverDetailsKtTest {
val homeserverLoginDetails = FakeFfiHomeserverLoginDetails(
url = "https://example.org",
supportsPasswordLogin = true,
supportsOidcLogin = false
supportsOAuthLogin = false
)
// When
@ -31,7 +31,7 @@ class HomeserverDetailsKtTest {
MatrixHomeServerDetails(
url = "https://example.org",
supportsPasswordLogin = true,
supportsOidcLogin = false
supportsOAuthLogin = false
)
)
}

View file

@ -10,18 +10,18 @@ package io.element.android.libraries.matrix.impl.auth
import com.google.common.truth.Truth.assertThat
import io.element.android.libraries.matrix.test.auth.FAKE_REDIRECT_URL
import io.element.android.libraries.matrix.test.auth.FakeOidcRedirectUrlProvider
import io.element.android.libraries.matrix.test.auth.FakeOAuthRedirectUrlProvider
import io.element.android.libraries.matrix.test.core.aBuildMeta
import org.junit.Test
class OidcConfigurationProviderTest {
class OAuthConfigurationProviderTest {
@Test
fun get() {
val result = OidcConfigurationProvider(
val result = OAuthConfigurationProvider(
buildMeta = aBuildMeta(
applicationName = "myName",
),
oidcRedirectUrlProvider = FakeOidcRedirectUrlProvider(),
oAuthRedirectUrlProvider = FakeOAuthRedirectUrlProvider(),
).get()
assertThat(result.clientName).isEqualTo("myName")
assertThat(result.redirectUri).isEqualTo(FAKE_REDIRECT_URL)

View file

@ -18,8 +18,8 @@ import org.junit.Test
class RustHomeserverLoginCompatibilityCheckerTest {
@Test
fun `check - is valid if it supports OIDC login`() = runTest {
val sut = createChecker { FakeFfiHomeserverLoginDetails(supportsOidcLogin = true) }
fun `check - is valid if it supports OAuth login`() = runTest {
val sut = createChecker { FakeFfiHomeserverLoginDetails(supportsOAuthLogin = true) }
assertThat(sut.check("https://matrix.host.org").getOrNull()).isTrue()
}

View file

@ -16,7 +16,7 @@ import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeFfiClient
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeFfiClientBuilder
import io.element.android.libraries.matrix.impl.fixtures.fakes.FakeFfiHomeserverLoginDetails
import io.element.android.libraries.matrix.impl.paths.SessionPathsFactory
import io.element.android.libraries.matrix.test.auth.FakeOidcRedirectUrlProvider
import io.element.android.libraries.matrix.test.auth.FakeOAuthRedirectUrlProvider
import io.element.android.libraries.matrix.test.core.aBuildMeta
import io.element.android.libraries.sessionstorage.api.SessionStore
import io.element.android.libraries.sessionstorage.test.InMemorySessionStore
@ -64,9 +64,9 @@ class RustMatrixAuthenticationServiceTest {
sessionStore = sessionStore,
rustMatrixClientFactory = rustMatrixClientFactory,
passphraseGenerator = FakePassphraseGenerator(),
oidcConfigurationProvider = OidcConfigurationProvider(
oAuthConfigurationProvider = OAuthConfigurationProvider(
buildMeta = aBuildMeta(),
oidcRedirectUrlProvider = FakeOidcRedirectUrlProvider(),
oAuthRedirectUrlProvider = FakeOAuthRedirectUrlProvider(),
),
)
}

View file

@ -32,7 +32,7 @@ class QrErrorMapperTest {
assertThat(QrErrorMapper.map(RustHumanQrLoginException.OtherDeviceNotSignedIn())).isEqualTo(QrLoginException.OtherDeviceNotSignedIn)
assertThat(QrErrorMapper.map(RustHumanQrLoginException.LinkingNotSupported())).isEqualTo(QrLoginException.LinkingNotSupported)
assertThat(QrErrorMapper.map(RustHumanQrLoginException.Unknown())).isEqualTo(QrLoginException.Unknown)
assertThat(QrErrorMapper.map(RustHumanQrLoginException.OAuthMetadataInvalid())).isEqualTo(QrLoginException.OidcMetadataInvalid)
assertThat(QrErrorMapper.map(RustHumanQrLoginException.OAuthMetadataInvalid())).isEqualTo(QrLoginException.OAuthMetadataInvalid)
assertThat(QrErrorMapper.map(RustHumanQrLoginException.SlidingSyncNotAvailable())).isEqualTo(QrLoginException.SlidingSyncNotAvailable)
}
}

View file

@ -14,11 +14,11 @@ import org.matrix.rustcomponents.sdk.NoHandle
class FakeFfiHomeserverLoginDetails(
private val url: String = "https://example.org",
private val supportsPasswordLogin: Boolean = false,
private val supportsOidcLogin: Boolean = false,
private val supportsOAuthLogin: Boolean = false,
private val supportsSsoLogin: Boolean = false,
) : HomeserverLoginDetails(NoHandle) {
override fun url(): String = url
override fun supportsOauthLogin(): Boolean = supportsOidcLogin
override fun supportsOauthLogin(): Boolean = supportsOAuthLogin
override fun supportsPasswordLogin(): Boolean = supportsPasswordLogin
override fun supportsSsoLogin(): Boolean = supportsSsoLogin
}

View file

@ -36,7 +36,7 @@ class SessionKtTest {
assertThat(result.refreshToken).isEqualTo("refreshToken")
assertThat(result.homeserverUrl).isEqualTo(A_HOMESERVER_URL)
assertThat(result.isTokenValid).isTrue()
assertThat(result.oidcData).isNull()
assertThat(result.oAuthData).isNull()
assertThat(result.loginType).isEqualTo(LoginType.PASSWORD)
assertThat(result.loginTimestamp).isNotNull()
assertThat(result.passphrase).isEqualTo(A_SECRET)
@ -82,7 +82,7 @@ class SessionKtTest {
assertThat(result.refreshToken).isNull()
assertThat(result.homeserverUrl).isEqualTo(A_HOMESERVER_URL)
assertThat(result.isTokenValid).isTrue()
assertThat(result.oidcData).isNull()
assertThat(result.oAuthData).isNull()
assertThat(result.loginType).isEqualTo(LoginType.PASSWORD)
assertThat(result.loginTimestamp).isNotNull()
assertThat(result.passphrase).isEqualTo(A_SECRET)

View file

@ -6,10 +6,10 @@
* Please see LICENSE files in the repository root for full details.
*/
package io.element.android.libraries.matrix.impl.oidc
package io.element.android.libraries.matrix.impl.oauth
import com.google.common.truth.Truth.assertThat
import io.element.android.libraries.matrix.api.oidc.AccountManagementAction
import io.element.android.libraries.matrix.api.oauth.AccountManagementAction
import io.element.android.libraries.matrix.test.A_DEVICE_ID
import org.junit.Test
import org.matrix.rustcomponents.sdk.AccountManagementAction as RustAccountManagementAction