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