From f7bf39b346444363fefd698f8a079501e735a765 Mon Sep 17 00:00:00 2001 From: Doug Date: Fri, 24 Apr 2026 16:23:53 +0100 Subject: [PATCH] ffi: Rename OIDC errors to OAuth errors. --- bindings/matrix-sdk-ffi/src/authentication.rs | 46 +++++++++---------- bindings/matrix-sdk-ffi/src/client.rs | 16 ++++--- bindings/matrix-sdk-ffi/src/qr_code.rs | 8 ++-- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/authentication.rs b/bindings/matrix-sdk-ffi/src/authentication.rs index bbffff56b..474d3d310 100644 --- a/bindings/matrix-sdk-ffi/src/authentication.rs +++ b/bindings/matrix-sdk-ffi/src/authentication.rs @@ -150,11 +150,11 @@ pub struct OAuthConfiguration { } impl OAuthConfiguration { - pub(crate) fn redirect_uri(&self) -> Result { - Url::parse(&self.redirect_uri).map_err(|_| OidcError::CallbackUrlInvalid) + pub(crate) fn redirect_uri(&self) -> Result { + Url::parse(&self.redirect_uri).map_err(|_| OAuthError::CallbackUrlInvalid) } - pub(crate) fn client_metadata(&self) -> Result, OidcError> { + pub(crate) fn client_metadata(&self) -> Result, OAuthError> { let redirect_uri = self.redirect_uri()?; let client_name = self.client_name.as_ref().map(|n| Localized::new(n.to_owned(), [])); let client_uri = self.client_uri.localized_url()?; @@ -178,10 +178,10 @@ impl OAuthConfiguration { ) }; - Raw::new(&metadata).map_err(|_| OidcError::MetadataInvalid) + Raw::new(&metadata).map_err(|_| OAuthError::MetadataInvalid) } - pub(crate) fn registration_data(&self) -> Result { + pub(crate) fn registration_data(&self) -> Result { let client_metadata = self.client_metadata()?; let mut registration_data = ClientRegistrationData::new(client_metadata); @@ -208,43 +208,43 @@ impl OAuthConfiguration { #[derive(Debug, thiserror::Error, uniffi::Error)] #[uniffi(flat_error)] -pub enum OidcError { +pub enum OAuthError { #[error( "The homeserver doesn't provide an authentication issuer in its well-known configuration." )] NotSupported, - #[error("Unable to use OIDC as the supplied client metadata is invalid.")] + #[error("Unable to use OAuth as the supplied client metadata is invalid.")] MetadataInvalid, - #[error("The supplied callback URL used to complete OIDC is invalid.")] + #[error("The supplied callback URL used to complete OAuth is invalid.")] CallbackUrlInvalid, - #[error("The OIDC login was cancelled by the user.")] + #[error("The OAuth login was cancelled by the user.")] Cancelled, #[error("An error occurred: {message}")] Generic { message: String }, } -impl From for OidcError { - fn from(e: SdkOAuthError) -> OidcError { +impl From for OAuthError { + fn from(e: SdkOAuthError) -> OAuthError { match e { - SdkOAuthError::Discovery(error) if error.is_not_supported() => OidcError::NotSupported, + SdkOAuthError::Discovery(error) if error.is_not_supported() => OAuthError::NotSupported, SdkOAuthError::AuthorizationCode(OAuthAuthorizationCodeError::RedirectUri(_)) | SdkOAuthError::AuthorizationCode(OAuthAuthorizationCodeError::InvalidState) => { - OidcError::CallbackUrlInvalid + OAuthError::CallbackUrlInvalid } SdkOAuthError::AuthorizationCode(OAuthAuthorizationCodeError::Cancelled) => { - OidcError::Cancelled + OAuthError::Cancelled } - _ => OidcError::Generic { message: e.to_string() }, + _ => OAuthError::Generic { message: e.to_string() }, } } } -impl From for OidcError { - fn from(e: Error) -> OidcError { +impl From for OAuthError { + fn from(e: Error) -> OAuthError { match e { Error::OAuth(e) => (*e).into(), - _ => OidcError::Generic { message: e.to_string() }, + _ => OAuthError::Generic { message: e.to_string() }, } } } @@ -254,11 +254,11 @@ impl From for OidcError { trait OptionExt { /// Convenience method to convert an `Option` to a URL and returns /// it as a Localized URL. No localization is actually performed. - fn localized_url(&self) -> Result>, OidcError>; + fn localized_url(&self) -> Result>, OAuthError>; } impl OptionExt for Option { - fn localized_url(&self) -> Result>, OidcError> { + fn localized_url(&self) -> Result>, OAuthError> { self.as_deref().map(StrExt::localized_url).transpose() } } @@ -266,11 +266,11 @@ impl OptionExt for Option { trait StrExt { /// Convenience method to convert a string to a URL and returns it as a /// Localized URL. No localization is actually performed. - fn localized_url(&self) -> Result, OidcError>; + fn localized_url(&self) -> Result, OAuthError>; } impl StrExt for str { - fn localized_url(&self) -> Result, OidcError> { - Ok(Localized::new(Url::parse(self).map_err(|_| OidcError::MetadataInvalid)?, [])) + fn localized_url(&self) -> Result, OAuthError> { + Ok(Localized::new(Url::parse(self).map_err(|_| OAuthError::MetadataInvalid)?, [])) } } diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index 648eda9cd..7ff867928 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -28,7 +28,9 @@ use matrix_sdk::STATE_STORE_DATABASE_NAME; use matrix_sdk::media::MediaFileHandle as SdkMediaFileHandle; use matrix_sdk::{ Account, AuthApi, AuthSession, Client as MatrixClient, Error, SessionChange, SessionTokens, - authentication::oauth::{ClientId, OAuthAuthorizationData, OAuthError, OAuthSession}, + authentication::oauth::{ + ClientId, OAuthAuthorizationData, OAuthError as SdkOAuthError, OAuthSession, + }, deserialized_responses::RawAnySyncOrStrippedTimelineEvent, executor::AbortOnDrop, media::{MediaFormat, MediaRequestParameters, MediaRetentionPolicy, MediaThumbnailSettings}, @@ -124,7 +126,9 @@ use super::{ }; use crate::{ ClientError, - authentication::{HomeserverLoginDetails, OAuthConfiguration, OidcError, SsoError, SsoHandler}, + authentication::{ + HomeserverLoginDetails, OAuthConfiguration, OAuthError, SsoError, SsoHandler, + }, client, encryption::Encryption, live_locations_observer::BeaconInfoUpdate, @@ -641,7 +645,7 @@ impl Client { login_hint: Option, device_id: Option, additional_scopes: Option>, - ) -> Result, OidcError> { + ) -> Result, OAuthError> { let registration_data = oauth_configuration.registration_data()?; let redirect_uri = oauth_configuration.redirect_uri()?; @@ -676,8 +680,8 @@ impl Client { } /// Completes the OAuth login process. - pub async fn login_with_oauth_callback(&self, callback_url: String) -> Result<(), OidcError> { - let url = Url::parse(&callback_url).or(Err(OidcError::CallbackUrlInvalid))?; + pub async fn login_with_oauth_callback(&self, callback_url: String) -> Result<(), OAuthError> { + let url = Url::parse(&callback_url).or(Err(OAuthError::CallbackUrlInvalid))?; self.inner.oauth().finish_login(url.into()).await?; @@ -1236,7 +1240,7 @@ impl Client { Ok(server_metadata) => server_metadata, Err(e) => { error!("Failed retrieving cached server metadata: {e}"); - return Err(OAuthError::from(e).into()); + return Err(SdkOAuthError::from(e).into()); } }; diff --git a/bindings/matrix-sdk-ffi/src/qr_code.rs b/bindings/matrix-sdk-ffi/src/qr_code.rs index 36275587b..1fcc49734 100644 --- a/bindings/matrix-sdk-ffi/src/qr_code.rs +++ b/bindings/matrix-sdk-ffi/src/qr_code.rs @@ -73,7 +73,7 @@ impl LoginWithQrCodeHandler { let registration_data = self .oauth_configuration .registration_data() - .map_err(|_| HumanQrLoginError::OidcMetadataInvalid)?; + .map_err(|_| HumanQrLoginError::OAuthMetadataInvalid)?; let login = self.oauth.login_with_qr_code(Some(®istration_data)).scan(&qr_code_data.inner); @@ -118,7 +118,7 @@ impl LoginWithQrCodeHandler { let registration_data = self .oauth_configuration .registration_data() - .map_err(|_| HumanQrLoginError::OidcMetadataInvalid)?; + .map_err(|_| HumanQrLoginError::OAuthMetadataInvalid)?; let login = self.oauth.login_with_qr_code(Some(®istration_data)).generate(); @@ -322,8 +322,8 @@ pub enum HumanQrLoginError { Unknown, #[error("The homeserver doesn't provide sliding sync in its configuration.")] SlidingSyncNotAvailable, - #[error("Unable to use OIDC as the supplied client metadata is invalid.")] - OidcMetadataInvalid, + #[error("Unable to use OAuth as the supplied client metadata is invalid.")] + OAuthMetadataInvalid, #[error("The other device is not signed in and as such can't sign in other devices.")] OtherDeviceNotSignedIn, #[error("The check code was already sent.")]