From aae6fa28430462e5ce98cdcb64d0f8b7b6517de4 Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Thu, 16 Jun 2022 19:56:16 +0100 Subject: [PATCH] client-api: Add MSC2965 feature and m.authentication discovery --- crates/ruma-client-api/CHANGELOG.md | 1 + crates/ruma-client-api/Cargo.toml | 1 + .../src/discovery/discover_homeserver.rs | 29 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/crates/ruma-client-api/CHANGELOG.md b/crates/ruma-client-api/CHANGELOG.md index 23e939fd..5e885e4b 100644 --- a/crates/ruma-client-api/CHANGELOG.md +++ b/crates/ruma-client-api/CHANGELOG.md @@ -16,6 +16,7 @@ Improvements: * Add unstable support for querying relating events (MSC2675) * Move `filter::RelationType` to `ruma_common::events::relations` +* Add unstable support for discovering an OpenID Connect server (MSC2965) # 0.14.1 diff --git a/crates/ruma-client-api/Cargo.toml b/crates/ruma-client-api/Cargo.toml index 8da6f2aa..e77d5355 100644 --- a/crates/ruma-client-api/Cargo.toml +++ b/crates/ruma-client-api/Cargo.toml @@ -26,6 +26,7 @@ unstable-msc2675 = [] unstable-msc2676 = [] unstable-msc2677 = [] unstable-msc2918 = [] +unstable-msc2965 = [] unstable-msc3316 = [] unstable-msc3440 = [] unstable-msc3488 = [] diff --git a/crates/ruma-client-api/src/discovery/discover_homeserver.rs b/crates/ruma-client-api/src/discovery/discover_homeserver.rs index ae07df87..744f4fb8 100644 --- a/crates/ruma-client-api/src/discovery/discover_homeserver.rs +++ b/crates/ruma-client-api/src/discovery/discover_homeserver.rs @@ -32,6 +32,11 @@ ruma_api! { #[cfg(feature = "unstable-msc3488")] #[serde(rename = "org.matrix.msc3488.tile_server", alias = "m.tile_server")] pub tile_server: Option, + + /// Information about the authentication server to connect to when using OpenID Connect. + #[cfg(feature = "unstable-msc2965")] + #[serde(rename = "m.authentication")] + pub authentication: Option, } error: crate::Error @@ -52,6 +57,8 @@ impl Response { identity_server: None, #[cfg(feature = "unstable-msc3488")] tile_server: None, + #[cfg(feature = "unstable-msc2965")] + authentication: None, } } } @@ -104,3 +111,25 @@ impl TileServerInfo { Self { map_style_url } } } + +/// Information about a discovered authentication server. +#[cfg(feature = "unstable-msc2965")] +#[derive(Clone, Debug, Deserialize, Hash, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] +pub struct AuthenticationServerInfo { + /// The OIDC Provider that is trusted by the homeserver. + pub issuer: String, + + /// The URL where the user is able to access the account management + /// capabilities of the OIDC Provider. + #[serde(skip_serializing_if = "Option::is_none")] + pub account: Option, +} + +#[cfg(feature = "unstable-msc2965")] +impl AuthenticationServerInfo { + /// Creates an `AuthenticationServerInfo` with the given `issuer` and an optional `account. + pub fn new(issuer: String, account: Option) -> Self { + Self { issuer, account } + } +}