Skip to content

Commit a765b3c

Browse files
committed
fix(oidc): Add missing feature checks.
1 parent 2a11150 commit a765b3c

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

crates/matrix-sdk/src/client/futures.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
1+
#[cfg(feature = "experimental-oidc")]
2+
use std::ops::Deref;
13
use std::{
24
fmt::Debug,
35
future::{Future, IntoFuture},
4-
ops::Deref,
56
pin::Pin,
67
};
78

89
use cfg_vis::cfg_vis;
910
use eyeball::SharedObservable;
1011
#[cfg(not(target_arch = "wasm32"))]
1112
use eyeball::Subscriber;
13+
#[cfg(feature = "experimental-oidc")]
1214
use mas_oidc_client::{
1315
error::{
1416
Error as OidcClientError, ErrorBody as OidcErrorBody, HttpError as OidcHttpError,
1517
TokenRefreshError, TokenRequestError,
1618
},
17-
requests::authorization_code::AuthorizationValidationData,
1819
types::errors::ClientErrorCode,
1920
};
2021
use ruma::api::{client::error::ErrorKind, error::FromHttpResponseError, OutgoingRequest};
2122
use tracing::trace;
2223

2324
use super::super::Client;
25+
#[cfg(feature = "experimental-oidc")]
26+
use crate::oidc::OidcError;
2427
use crate::{
2528
config::RequestConfig,
2629
error::{HttpError, HttpResult},
27-
oidc::OidcError,
2830
RefreshTokenError, TransmissionProgress,
2931
};
3032

@@ -100,6 +102,7 @@ where
100102
// Refreshing access tokens is not supported by this `Session`, ignore.
101103
client.broadcast_unknown_token(soft_logout);
102104
}
105+
#[cfg(feature = "experimental-oidc")]
103106
RefreshTokenError::Oidc(oidc_error) => {
104107
let oidc_error = oidc_error.deref();
105108
match oidc_error {

crates/matrix-sdk/src/client/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,22 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17+
#[cfg(feature = "experimental-oidc")]
18+
use std::ops::Deref;
1719
#[cfg(feature = "experimental-sliding-sync")]
1820
use std::sync::RwLock as StdRwLock;
1921
use std::{
2022
collections::{btree_map, BTreeMap},
2123
fmt::{self, Debug},
2224
future::Future,
23-
ops::Deref,
2425
pin::Pin,
2526
sync::{Arc, Mutex as StdMutex},
2627
};
2728

2829
use dashmap::DashMap;
2930
use eyeball::{Observable, SharedObservable, Subscriber};
3031
use futures_core::Stream;
32+
#[cfg(feature = "experimental-oidc")]
3133
use mas_oidc_client::{
3234
error::{
3335
Error as OidcClientError, ErrorBody as OidcErrorBody, HttpError as OidcHttpError,
@@ -42,6 +44,8 @@ use matrix_sdk_base::{
4244
SyncOutsideWasm,
4345
};
4446
use matrix_sdk_common::instant::Instant;
47+
#[cfg(feature = "experimental-oidc")]
48+
use ruma::api::client::error::ErrorKind;
4549
#[cfg(feature = "appservice")]
4650
use ruma::TransactionId;
4751
use ruma::{
@@ -56,7 +60,6 @@ use ruma::{
5660
get_capabilities::{self, Capabilities},
5761
get_supported_versions,
5862
},
59-
error::ErrorKind,
6063
filter::{create_filter::v3::Request as FilterUploadRequest, FilterDefinition},
6164
membership::{join_room_by_id, join_room_by_id_or_alias},
6265
profile::get_profile,
@@ -83,7 +86,7 @@ use url::Url;
8386
#[cfg(feature = "e2e-encryption")]
8487
use crate::encryption::Encryption;
8588
#[cfg(feature = "experimental-oidc")]
86-
use crate::oidc::Oidc;
89+
use crate::oidc::{Oidc, OidcError};
8790
use crate::{
8891
authentication::AuthData,
8992
config::RequestConfig,
@@ -94,7 +97,6 @@ use crate::{
9497
http_client::HttpClient,
9598
matrix_auth::MatrixAuth,
9699
notification_settings::NotificationSettings,
97-
oidc::OidcError,
98100
sync::{RoomUpdate, SyncResponse},
99101
Account, AuthApi, AuthSession, Error, Media, RefreshTokenError, Result, Room,
100102
TransmissionProgress,
@@ -434,7 +436,12 @@ impl Client {
434436
if let Some(discovered_server) = &self.inner.authentication_server_info {
435437
return Some(discovered_server);
436438
};
437-
self.inner.auth_data.get().and_then(|d| d.as_oidc().map(|o| &o.issuer_info))
439+
440+
match self.inner.auth_data.get()? {
441+
AuthData::Matrix(_) => None,
442+
#[cfg(feature = "experimental-oidc")]
443+
AuthData::Oidc(o) => Some(&o.issuer_info),
444+
}
438445
}
439446

440447
/// The sliding sync proxy that is trusted by the homeserver.
@@ -1346,6 +1353,7 @@ impl Client {
13461353
// Refreshing access tokens is not supported by this `Session`, ignore.
13471354
self.broadcast_unknown_token(soft_logout);
13481355
}
1356+
#[cfg(feature = "experimental-oidc")]
13491357
RefreshTokenError::Oidc(oidc_error) => {
13501358
let oidc_error = oidc_error.deref();
13511359
match oidc_error {

crates/matrix-sdk/src/oidc/data_serde.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use serde::{de, ser::SerializeStruct, Deserialize, Serialize};
1717
use super::SessionTokens;
1818

1919
impl Serialize for SessionTokens {
20-
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
20+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
2121
where
2222
S: serde::Serializer,
2323
{

crates/matrix-sdk/src/oidc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ impl Oidc {
741741
// Get the user ID.
742742
let whoami_res = self.client.whoami().await.map_err(crate::Error::from)?;
743743

744-
let session = matrix_sdk_base::SessionMeta {
744+
let session = SessionMeta {
745745
user_id: whoami_res.user_id,
746746
device_id: whoami_res.device_id.ok_or(OidcError::MissingDeviceId)?,
747747
};

0 commit comments

Comments
 (0)