ruma_client_api/account/
request_3pid_management_token_via_msisdn.rs

1//! `POST /_matrix/client/*/account/3pid/msisdn/requestToken`
2//!
3//! Request a 3PID management token with a phone number.
4
5pub mod v3 {
6    //! `/v3/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3account3pidmsisdnrequesttoken
9
10    use js_int::UInt;
11    use ruma_common::{
12        api::{request, response, Metadata},
13        metadata, OwnedClientSecret, OwnedSessionId,
14    };
15
16    use crate::account::IdentityServerInfo;
17
18    const METADATA: Metadata = metadata! {
19        method: POST,
20        rate_limited: false,
21        authentication: None,
22        history: {
23            1.0 => "/_matrix/client/r0/account/3pid/msisdn/requestToken",
24            1.1 => "/_matrix/client/v3/account/3pid/msisdn/requestToken",
25        }
26    };
27
28    /// Request type for the `request_3pid_management_token_via_msisdn` endpoint.
29    #[request(error = crate::Error)]
30    pub struct Request {
31        /// Client-generated secret string used to protect this session.
32        pub client_secret: OwnedClientSecret,
33
34        /// Two-letter ISO 3166 country code for the phone number.
35        pub country: String,
36
37        /// Phone number to validate.
38        pub phone_number: String,
39
40        /// Used to distinguish protocol level retries from requests to re-send the SMS.
41        pub send_attempt: UInt,
42
43        /// Return URL for identity server to redirect the client back to.
44        #[serde(skip_serializing_if = "Option::is_none")]
45        pub next_link: Option<String>,
46
47        /// Optional identity server hostname and access token.
48        #[serde(flatten, skip_serializing_if = "Option::is_none")]
49        #[deprecated = "Since Matrix Client-Server API r0.6.0."]
50        pub identity_server_info: Option<IdentityServerInfo>,
51    }
52
53    /// Response type for the `request_3pid_management_token_via_msisdn` endpoint.
54    #[response(error = crate::Error)]
55    pub struct Response {
56        /// The session identifier given by the identity server.
57        pub sid: OwnedSessionId,
58
59        /// URL to submit validation token to.
60        ///
61        /// If omitted, verification happens without client.
62        ///
63        /// If you activate the `compat-empty-string-null` feature, this field being an empty
64        /// string in JSON will result in `None` here during deserialization.
65        #[serde(skip_serializing_if = "Option::is_none")]
66        #[cfg_attr(
67            feature = "compat-empty-string-null",
68            serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none")
69        )]
70        pub submit_url: Option<String>,
71    }
72
73    impl Request {
74        /// Creates a new `Request` with the given client secret, country code, phone number and
75        /// send-attempt counter.
76        #[allow(deprecated)]
77        pub fn new(
78            client_secret: OwnedClientSecret,
79            country: String,
80            phone_number: String,
81            send_attempt: UInt,
82        ) -> Self {
83            Self {
84                client_secret,
85                country,
86                phone_number,
87                send_attempt,
88                next_link: None,
89                identity_server_info: None,
90            }
91        }
92    }
93
94    impl Response {
95        /// Creates a new `Response` with the given session identifier.
96        pub fn new(sid: OwnedSessionId) -> Self {
97            Self { sid, submit_url: None }
98        }
99    }
100}