refactor(oidc): put the OidcContext in the AuthCtx

This commit is contained in:
Benjamin Bouvier
2023-09-11 17:42:19 +02:00
parent 7e142c8132
commit 3144d87c3a
4 changed files with 7 additions and 14 deletions

View File

@@ -21,7 +21,7 @@ use ruma::api::client::discovery::discover_homeserver::AuthenticationServerInfo;
use tokio::sync::{broadcast, Mutex, OnceCell};
#[cfg(feature = "experimental-oidc")]
use crate::oidc::{self, Oidc, OidcAuthData};
use crate::oidc::{self, Oidc, OidcAuthData, OidcContext};
use crate::{
matrix_auth::{self, MatrixAuth, MatrixAuthData},
Client, RefreshTokenError, SessionChange,
@@ -51,6 +51,9 @@ pub(crate) struct AuthCtx {
#[cfg_attr(not(feature = "experimental-oidc"), allow(dead_code))]
pub(crate) authentication_server_info: Option<AuthenticationServerInfo>,
#[cfg(feature = "experimental-oidc")]
pub(crate) oidc_context: OidcContext,
/// Whether to try to refresh the access token automatically when an
/// `M_UNKNOWN_TOKEN` error is encountered.
pub(crate) handle_refresh_tokens: bool,

View File

@@ -433,6 +433,8 @@ impl ClientBuilder {
auth_data: OnceCell::default(),
reload_session_callback: OnceCell::default(),
save_session_callback: OnceCell::default(),
#[cfg(feature = "experimental-oidc")]
oidc_context: OidcContext::default(),
});
let inner = Arc::new(ClientInner::new(
@@ -444,8 +446,6 @@ impl ClientBuilder {
base_client,
self.server_versions,
self.respect_login_well_known,
#[cfg(feature = "experimental-oidc")]
Arc::new(OidcContext::default()),
));
debug!("Done building the Client");

View File

@@ -71,8 +71,6 @@ use url::Url;
#[cfg(feature = "experimental-oidc")]
use crate::oidc::Oidc;
#[cfg(feature = "experimental-oidc")]
use crate::oidc::OidcContext;
use crate::{
authentication::{AuthCtx, AuthData, ReloadSessionCallback, SaveSessionCallback},
config::RequestConfig,
@@ -185,9 +183,6 @@ pub(crate) struct ClientInner {
/// store.
pub(crate) sync_beat: event_listener::Event,
#[cfg(feature = "experimental-oidc")]
pub(crate) oidc_context: Arc<OidcContext>,
#[cfg(feature = "e2e-encryption")]
pub(crate) cross_process_crypto_store_lock:
OnceCell<CrossProcessStoreLock<LockableCryptoStore>>,
@@ -229,7 +224,6 @@ impl ClientInner {
base_client: BaseClient,
server_versions: Option<Box<[MatrixVersion]>>,
respect_login_well_known: bool,
#[cfg(feature = "experimental-oidc")] oidc_context: Arc<OidcContext>,
) -> Self {
Self {
homeserver: RwLock::new(homeserver),
@@ -256,8 +250,6 @@ impl ClientInner {
cross_process_crypto_store_lock: OnceCell::new(),
#[cfg(feature = "e2e-encryption")]
crypto_store_generation: Arc::new(Mutex::new(None)),
#[cfg(feature = "experimental-oidc")]
oidc_context,
}
}
}
@@ -1940,8 +1932,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,
#[cfg(feature = "experimental-oidc")]
self.inner.oidc_context.clone(),
)),
};

View File

@@ -264,7 +264,7 @@ impl Oidc {
}
fn ctx(&self) -> &OidcContext {
&self.client.inner.oidc_context
&self.client.inner.auth_ctx.oidc_context
}
/// Enable a cross-process store lock on the state store, to coordinate