From 0b2e3e07949fb0f2ff5ff1c6a935484957909011 Mon Sep 17 00:00:00 2001 From: Yorusaka Miyabi <23130178+ShadowRZ@users.noreply.github.com> Date: Thu, 12 Jun 2025 15:29:40 +0800 Subject: [PATCH] feat(ffi): Expose legacy SSO support infomation Currently Element X can't distinguish the cases where a homeserver only supports legacy SSO without OIDC (and password login isn't avaliable), and other server unreachable scenarios. This patch exposes legacy SSO support infomation so that Element X side can give a dedicated error message when it encounters a homeserver that can only support legacy SSO. Signed-off-by: Yorusaka Miyabi <23130178+ShadowRZ@users.noreply.github.com> --- bindings/matrix-sdk-ffi/CHANGELOG.md | 7 ++++ bindings/matrix-sdk-ffi/src/authentication.rs | 6 ++++ bindings/matrix-sdk-ffi/src/client.rs | 32 +++++++++++-------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/bindings/matrix-sdk-ffi/CHANGELOG.md b/bindings/matrix-sdk-ffi/CHANGELOG.md index 664ac6fdd22..f3671acffa5 100644 --- a/bindings/matrix-sdk-ffi/CHANGELOG.md +++ b/bindings/matrix-sdk-ffi/CHANGELOG.md @@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file. ## [Unreleased] - ReleaseDate +### Features: + +- Add `HomeserverLoginDetails::supports_sso_login` for legacy SSO support infomation. + This is primarily for Element X to give a dedicated error message in case + it connects a homeserver with only this method avaliable. + ([#5222](https://github.com/matrix-org/matrix-rust-sdk/pull/5222)) + ### Breaking changes: - `Client::url_for_oidc` now allows requesting additional scopes for the OAuth2 authorization code grant. diff --git a/bindings/matrix-sdk-ffi/src/authentication.rs b/bindings/matrix-sdk-ffi/src/authentication.rs index cd04fff6558..1e7186f814c 100644 --- a/bindings/matrix-sdk-ffi/src/authentication.rs +++ b/bindings/matrix-sdk-ffi/src/authentication.rs @@ -23,6 +23,7 @@ pub struct HomeserverLoginDetails { pub(crate) sliding_sync_version: SlidingSyncVersion, pub(crate) supports_oidc_login: bool, pub(crate) supported_oidc_prompts: Vec, + pub(crate) supports_sso_login: bool, pub(crate) supports_password_login: bool, } @@ -43,6 +44,11 @@ impl HomeserverLoginDetails { self.supports_oidc_login } + /// Whether the current homeserver supports login using legacy SSO. + pub fn supports_sso_login(&self) -> bool { + self.supports_sso_login + } + /// The prompts advertised by the authentication issuer for use in the login /// URL. pub fn supported_oidc_prompts(&self) -> Vec { diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index 357b3412751..d569cd86836 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -341,7 +341,24 @@ impl Client { } }; - let supports_password_login = self.supports_password_login().await.ok().unwrap_or(false); + let login_types = self.inner.matrix_auth().get_login_types().await.ok(); + let supports_password_login = login_types + .as_ref() + .map(|login_types| { + login_types.flows.iter().any(|login_type| { + matches!(login_type, get_login_types::v3::LoginType::Password(_)) + }) + }) + .unwrap_or(false); + let supports_sso_login = login_types + .as_ref() + .map(|login_types| { + login_types + .flows + .iter() + .any(|login_type| matches!(login_type, get_login_types::v3::LoginType::Sso(_))) + }) + .unwrap_or(false); let sliding_sync_version = self.sliding_sync_version(); Arc::new(HomeserverLoginDetails { @@ -349,6 +366,7 @@ impl Client { sliding_sync_version, supports_oidc_login, supported_oidc_prompts, + supports_sso_login, supports_password_login, }) } @@ -808,18 +826,6 @@ impl Client { } } -impl Client { - /// Whether or not the client's homeserver supports the password login flow. - pub(crate) async fn supports_password_login(&self) -> anyhow::Result { - let login_types = self.inner.matrix_auth().get_login_types().await?; - let supports_password = login_types - .flows - .iter() - .any(|login_type| matches!(login_type, get_login_types::v3::LoginType::Password(_))); - Ok(supports_password) - } -} - #[matrix_sdk_ffi_macros::export] impl Client { /// The sliding sync version.