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