From fdc2ca0c9e667f4deec24c3919957a027a360d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Sat, 22 Mar 2025 10:14:48 +0100 Subject: [PATCH] fix(oauth): Do not expose OAuthRegistrationStore under wasm32 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It usually won't be possible to write data to a file. Signed-off-by: Kévin Commaille --- crates/matrix-sdk/src/authentication/oauth/error.rs | 7 ++++--- crates/matrix-sdk/src/authentication/oauth/mod.rs | 8 +++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/matrix-sdk/src/authentication/oauth/error.rs b/crates/matrix-sdk/src/authentication/oauth/error.rs index d7b03da3c..49e974656 100644 --- a/crates/matrix-sdk/src/authentication/oauth/error.rs +++ b/crates/matrix-sdk/src/authentication/oauth/error.rs @@ -29,9 +29,9 @@ use ruma::{ serde::{PartialEqAsRefStr, StringEnum}, }; -pub use super::{ - cross_process::CrossProcessRefreshLockError, registration_store::OAuthRegistrationStoreError, -}; +pub use super::cross_process::CrossProcessRefreshLockError; +#[cfg(not(target_arch = "wasm32"))] +pub use super::registration_store::OAuthRegistrationStoreError; /// An error when interacting with the OAuth 2.0 authorization server. pub type OAuthRequestError = @@ -262,6 +262,7 @@ pub enum OAuthClientRegistrationError { FromJson(serde_json::Error), /// Failed to access or store the registration in the store. + #[cfg(not(target_arch = "wasm32"))] #[error("failed to use registration store: {0}")] Store(#[from] OAuthRegistrationStoreError), } diff --git a/crates/matrix-sdk/src/authentication/oauth/mod.rs b/crates/matrix-sdk/src/authentication/oauth/mod.rs index c9f743c2c..37fb17bb2 100644 --- a/crates/matrix-sdk/src/authentication/oauth/mod.rs +++ b/crates/matrix-sdk/src/authentication/oauth/mod.rs @@ -175,10 +175,13 @@ mod oidc_discovery; #[cfg(all(feature = "e2e-encryption", not(target_arch = "wasm32")))] pub mod qrcode; pub mod registration; +#[cfg(not(target_arch = "wasm32"))] mod registration_store; #[cfg(test)] mod tests; +#[cfg(not(target_arch = "wasm32"))] +pub use self::registration_store::OAuthRegistrationStore; use self::{ account_management_url::build_account_management_url, cross_process::{CrossProcessRefreshLockGuard, CrossProcessRefreshManager}, @@ -191,7 +194,6 @@ pub use self::{ account_management_url::AccountManagementActionFull, auth_code_builder::{OAuthAuthCodeUrlBuilder, OAuthAuthorizationData}, error::OAuthError, - registration_store::OAuthRegistrationStore, }; use super::{AuthData, SessionTokens}; use crate::{client::SessionChange, Client, HttpError, RefreshTokenError, Result}; @@ -424,6 +426,7 @@ impl OAuth { /// /// Returns an error if there is an error while accessing the store, or /// while registering the client. + #[cfg(not(target_arch = "wasm32"))] async fn restore_or_register_client( &self, server_metadata: &AuthorizationServerMetadata, @@ -471,6 +474,7 @@ impl OAuth { ClientRegistrationMethod::Metadata(client_metadata) => { self.register_client_inner(server_metadata, client_metadata).await?; } + #[cfg(not(target_arch = "wasm32"))] ClientRegistrationMethod::Store(registrations) => { self.restore_or_register_client(server_metadata, registrations).await? } @@ -1552,6 +1556,7 @@ pub enum ClientRegistrationMethod { Metadata(Raw), /// Use an [`OAuthRegistrationStore`] to handle registrations. + #[cfg(not(target_arch = "wasm32"))] Store(OAuthRegistrationStore), } @@ -1567,6 +1572,7 @@ impl From> for ClientRegistrationMethod { } } +#[cfg(not(target_arch = "wasm32"))] impl From for ClientRegistrationMethod { fn from(value: OAuthRegistrationStore) -> Self { Self::Store(value)