ruma_identity_service_api/association/msisdn/
create_msisdn_validation_session.rs

1//! `POST /_matrix/identity/*/validate/msisdn/requestToken`
2//!
3//! Create a session for validation of a phone number.
4
5pub mod v2 {
6    //! `/v2/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/identity-service-api/#post_matrixidentityv2validatemsisdnrequesttoken
9
10    use js_int::UInt;
11    use ruma_common::{
12        OwnedClientSecret, OwnedSessionId,
13        api::{auth_scheme::AccessToken, request, response},
14        metadata,
15    };
16
17    metadata! {
18        method: POST,
19        rate_limited: false,
20        authentication: AccessToken,
21        history: {
22            1.0 => "/_matrix/identity/v2/validate/msisdn/requestToken",
23        }
24    }
25
26    /// Request type for the `create_msisdn_validation_session` endpoint.
27    #[request]
28    pub struct Request {
29        /// A unique string generated by the client, and used to identify the validation attempt.
30        pub client_secret: OwnedClientSecret,
31
32        /// The two-letter uppercase ISO-3166-1 alpha-2 country code that the number in
33        /// `phone_number` should be parsed as if it were dialled from.
34        pub country: String,
35
36        /// The phone number to validate.
37        pub phone_number: String,
38
39        /// The server will only send an SMS if the send_attempt is a number greater than the most
40        /// recent one which it has seen, scoped to that `country` + `phone_number` +
41        /// `client_secret` triple.
42        pub send_attempt: UInt,
43
44        /// When the validation is completed, the identity server will redirect the user to this
45        /// URL.
46        #[serde(skip_serializing_if = "Option::is_none")]
47        pub next_link: Option<String>,
48    }
49
50    /// Response type for the `create_msisdn_validation_session` endpoint.
51    #[response]
52    pub struct Response {
53        /// The session ID.
54        ///
55        /// Session IDs are opaque strings generated by the identity server.
56        pub sid: OwnedSessionId,
57    }
58
59    impl Request {
60        /// Create a new `Request` with the given client secret, country code, phone number, the
61        /// `send_attempt` number and the next link to go to after validation.
62        pub fn new(
63            client_secret: OwnedClientSecret,
64            country: String,
65            phone_number: String,
66            send_attempt: UInt,
67            next_link: Option<String>,
68        ) -> Self {
69            Self { client_secret, country, phone_number, send_attempt, next_link }
70        }
71    }
72
73    impl Response {
74        /// Create a new `Response` with the given session ID.
75        pub fn new(sid: OwnedSessionId) -> Self {
76            Self { sid }
77        }
78    }
79}