ruma_client_api/discovery/
discover_homeserver.rs

1//! `GET /.well-known/matrix/client` ([spec])
2//!
3//! [spec]: https://spec.matrix.org/latest/client-server-api/#getwell-knownmatrixclient
4//!
5//! Get discovery information about the domain.
6
7use ruma_common::{
8    api::{request, response, Metadata},
9    metadata,
10};
11use serde::{Deserialize, Serialize};
12
13const METADATA: Metadata = metadata! {
14    method: GET,
15    rate_limited: false,
16    authentication: None,
17    history: {
18        1.0 => "/.well-known/matrix/client",
19    }
20};
21
22/// Request type for the `client_well_known` endpoint.
23#[request(error = crate::Error)]
24#[derive(Default)]
25pub struct Request {}
26
27/// Response type for the `client_well_known` endpoint.
28#[response(error = crate::Error)]
29pub struct Response {
30    /// Information about the homeserver to connect to.
31    #[serde(rename = "m.homeserver")]
32    pub homeserver: HomeserverInfo,
33
34    /// Information about the identity server to connect to.
35    #[serde(rename = "m.identity_server", skip_serializing_if = "Option::is_none")]
36    pub identity_server: Option<IdentityServerInfo>,
37
38    /// Information about the tile server to use to display location data.
39    #[cfg(feature = "unstable-msc3488")]
40    #[serde(
41        rename = "org.matrix.msc3488.tile_server",
42        alias = "m.tile_server",
43        skip_serializing_if = "Option::is_none"
44    )]
45    pub tile_server: Option<TileServerInfo>,
46
47    /// Information about the authentication server to connect to when using OpenID Connect.
48    #[cfg(feature = "unstable-msc2965")]
49    #[serde(
50        rename = "org.matrix.msc2965.authentication",
51        alias = "m.authentication",
52        skip_serializing_if = "Option::is_none"
53    )]
54    pub authentication: Option<AuthenticationServerInfo>,
55
56    /// Information about the homeserver's trusted proxy to use for sliding sync development.
57    #[cfg(feature = "unstable-msc3575")]
58    #[serde(rename = "org.matrix.msc3575.proxy", skip_serializing_if = "Option::is_none")]
59    pub sliding_sync_proxy: Option<SlidingSyncProxyInfo>,
60}
61
62impl Request {
63    /// Creates an empty `Request`.
64    pub fn new() -> Self {
65        Self {}
66    }
67}
68
69impl Response {
70    /// Creates a new `Response` with the given `HomeserverInfo`.
71    pub fn new(homeserver: HomeserverInfo) -> Self {
72        Self {
73            homeserver,
74            identity_server: None,
75            #[cfg(feature = "unstable-msc3488")]
76            tile_server: None,
77            #[cfg(feature = "unstable-msc2965")]
78            authentication: None,
79            #[cfg(feature = "unstable-msc3575")]
80            sliding_sync_proxy: None,
81        }
82    }
83}
84
85/// Information about a discovered homeserver.
86#[derive(Clone, Debug, Deserialize, Hash, Serialize)]
87#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
88pub struct HomeserverInfo {
89    /// The base URL for the homeserver for client-server connections.
90    pub base_url: String,
91}
92
93impl HomeserverInfo {
94    /// Creates a new `HomeserverInfo` with the given `base_url`.
95    pub fn new(base_url: String) -> Self {
96        Self { base_url }
97    }
98}
99
100/// Information about a discovered identity server.
101#[derive(Clone, Debug, Deserialize, Hash, Serialize)]
102#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
103pub struct IdentityServerInfo {
104    /// The base URL for the identity server for client-server connections.
105    pub base_url: String,
106}
107
108impl IdentityServerInfo {
109    /// Creates an `IdentityServerInfo` with the given `base_url`.
110    pub fn new(base_url: String) -> Self {
111        Self { base_url }
112    }
113}
114
115/// Information about a discovered map tile server.
116#[cfg(feature = "unstable-msc3488")]
117#[derive(Clone, Debug, Deserialize, Hash, Serialize)]
118#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
119pub struct TileServerInfo {
120    /// The URL of a map tile server's `style.json` file.
121    ///
122    /// See the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/) for more details.
123    pub map_style_url: String,
124}
125
126#[cfg(feature = "unstable-msc3488")]
127impl TileServerInfo {
128    /// Creates a `TileServerInfo` with the given map style URL.
129    pub fn new(map_style_url: String) -> Self {
130        Self { map_style_url }
131    }
132}
133
134/// Information about a discovered authentication server.
135#[cfg(feature = "unstable-msc2965")]
136#[derive(Clone, Debug, Deserialize, Hash, Serialize)]
137#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
138pub struct AuthenticationServerInfo {
139    /// The OIDC Provider that is trusted by the homeserver.
140    pub issuer: String,
141
142    /// The URL where the user is able to access the account management
143    /// capabilities of the OIDC Provider.
144    #[serde(skip_serializing_if = "Option::is_none")]
145    pub account: Option<String>,
146}
147
148#[cfg(feature = "unstable-msc2965")]
149impl AuthenticationServerInfo {
150    /// Creates an `AuthenticationServerInfo` with the given `issuer` and an optional `account`.
151    pub fn new(issuer: String, account: Option<String>) -> Self {
152        Self { issuer, account }
153    }
154}
155
156/// Information about a discovered sliding sync proxy.
157#[cfg(feature = "unstable-msc3575")]
158#[derive(Clone, Debug, Deserialize, Hash, Serialize)]
159#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
160pub struct SlidingSyncProxyInfo {
161    /// The URL of a sliding sync proxy that is trusted by the homeserver.
162    pub url: String,
163}
164
165#[cfg(feature = "unstable-msc3575")]
166impl SlidingSyncProxyInfo {
167    /// Creates a `SlidingSyncProxyInfo` with the given proxy URL.
168    pub fn new(url: String) -> Self {
169        Self { url }
170    }
171}