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 {