From 4802a506097ef23bb2099dd78f18a2e77db172b6 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 5 Sep 2023 16:05:35 +0200 Subject: [PATCH] chore: put `handle_refresh_tokens` in the `AuthCtx` --- crates/matrix-sdk/src/authentication.rs | 4 ++++ crates/matrix-sdk/src/client/builder.rs | 6 ++++-- crates/matrix-sdk/src/client/futures.rs | 2 +- crates/matrix-sdk/src/client/mod.rs | 8 +------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/matrix-sdk/src/authentication.rs b/crates/matrix-sdk/src/authentication.rs index f759a7819..511ccf0d4 100644 --- a/crates/matrix-sdk/src/authentication.rs +++ b/crates/matrix-sdk/src/authentication.rs @@ -25,6 +25,10 @@ pub(crate) struct AuthCtx { /// The authentication server info discovered from the homeserver. #[cfg_attr(not(feature = "experimental-oidc"), allow(dead_code))] pub(crate) authentication_server_info: Option, + + /// Whether to try to refresh the access token automatically when an + /// `M_UNKNOWN_TOKEN` error is encountered. + pub(crate) handle_refresh_tokens: bool, } /// An enum over all the possible authentication APIs. diff --git a/crates/matrix-sdk/src/client/builder.rs b/crates/matrix-sdk/src/client/builder.rs index ac4ba9a14..314ebabc6 100644 --- a/crates/matrix-sdk/src/client/builder.rs +++ b/crates/matrix-sdk/src/client/builder.rs @@ -422,7 +422,10 @@ impl ClientBuilder { let homeserver = Url::parse(&homeserver)?; - let auth_ctx = Arc::new(AuthCtx { authentication_server_info }); + let auth_ctx = Arc::new(AuthCtx { + authentication_server_info, + handle_refresh_tokens: self.handle_refresh_tokens, + }); let inner = Arc::new(ClientInner::new( auth_ctx, @@ -433,7 +436,6 @@ impl ClientBuilder { base_client, self.server_versions, self.respect_login_well_known, - self.handle_refresh_tokens, )); debug!("Done building the Client"); diff --git a/crates/matrix-sdk/src/client/futures.rs b/crates/matrix-sdk/src/client/futures.rs index d8090eedc..e885360f4 100644 --- a/crates/matrix-sdk/src/client/futures.rs +++ b/crates/matrix-sdk/src/client/futures.rs @@ -94,7 +94,7 @@ where { trace!("Token refresh: Unknown token error received."); // If automatic token refresh isn't supported, there is nothing more to do. - if !client.inner.handle_refresh_tokens { + if !client.inner.auth_ctx.handle_refresh_tokens { trace!("Token refresh: Automatic refresh disabled."); client.broadcast_unknown_token(soft_logout); return res; diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 01a2c4e99..adb4d7266 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -186,9 +186,6 @@ pub(crate) struct ClientInner { /// Whether the client should update its homeserver URL with the discovery /// information present in the login response. respect_login_well_known: bool, - /// Whether to try to refresh the access token automatically when an - /// `M_UNKNOWN_TOKEN` error is encountered. - handle_refresh_tokens: bool, /// Lock making sure we're only doing one token refresh at a time. pub(crate) refresh_token_lock: Mutex>, /// An event that can be listened on to wait for a successful sync. The @@ -238,7 +235,6 @@ impl ClientInner { base_client: BaseClient, server_versions: Option>, respect_login_well_known: bool, - handle_refresh_tokens: bool, ) -> Self { let session_change_sender = broadcast::Sender::new(1); @@ -263,7 +259,6 @@ impl ClientInner { sync_gap_broadcast_txs: Default::default(), respect_login_well_known, sync_beat: event_listener::Event::new(), - handle_refresh_tokens, refresh_token_lock: Mutex::new(Ok(())), session_change_sender, auth_data: Default::default(), @@ -1261,7 +1256,7 @@ impl Client { { trace!("Token refresh: Unknown token error received."); // If automatic token refresh isn't supported, there is nothing more to do. - if !self.inner.handle_refresh_tokens { + if !self.inner.auth_ctx.handle_refresh_tokens { trace!("Token refresh: Automatic refresh disabled."); self.broadcast_unknown_token(soft_logout); return res; @@ -1991,7 +1986,6 @@ impl Client { self.inner.base_client.clone_with_in_memory_state_store(), self.inner.server_versions.get().cloned(), self.inner.respect_login_well_known, - self.inner.handle_refresh_tokens, )), };