ruma_client_api/account/
request_registration_token_via_msisdn.rs

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