chore: put handle_refresh_tokens in the AuthCtx

This commit is contained in:
Benjamin Bouvier
2023-09-05 16:05:35 +02:00
parent 28ab8e9efc
commit 4802a50609
4 changed files with 10 additions and 10 deletions

View File

@@ -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<AuthenticationServerInfo>,
/// 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.

View File

@@ -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");

View File

@@ -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;

View File

@@ -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<Result<(), RefreshTokenError>>,
/// 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<Box<[MatrixVersion]>>,
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,
)),
};