ruma_identity_service_api/association/bind_3pid.rs
1//! `POST /_matrix/identity/*/3pid/bind`
2//!
3//! Publish an association between a session and a Matrix user ID.
4
5pub mod v2 {
6 //! `/v2/` ([spec])
7 //!
8 //! [spec]: https://spec.matrix.org/latest/identity-service-api/#post_matrixidentityv23pidbind
9
10 use ruma_common::{
11 api::{request, response, Metadata},
12 metadata,
13 thirdparty::Medium,
14 MilliSecondsSinceUnixEpoch, OwnedClientSecret, OwnedSessionId, OwnedUserId,
15 ServerSignatures,
16 };
17
18 const METADATA: Metadata = metadata! {
19 method: POST,
20 rate_limited: false,
21 authentication: AccessToken,
22 history: {
23 1.0 => "/_matrix/identity/v2/3pid/bind",
24 }
25 };
26
27 /// Request type for the `bind_3pid` endpoint.
28 #[request]
29 pub struct Request {
30 /// The session ID generated by the `requestToken` call.
31 pub sid: OwnedSessionId,
32
33 /// The client secret passed to the `requestToken` call.
34 pub client_secret: OwnedClientSecret,
35
36 /// The Matrix user ID to associate with the 3PIDs.
37 pub mxid: OwnedUserId,
38 }
39
40 /// Response type for the `bind_3pid` endpoint.
41 #[response]
42 pub struct Response {
43 /// The 3PID address of the user being looked up.
44 pub address: String,
45
46 /// The medium type of the 3PID.
47 pub medium: Medium,
48
49 /// The Matrix user ID associated with the 3PID.
50 pub mxid: OwnedUserId,
51
52 /// A UNIX timestamp before which the association is not known to be valid.
53 pub not_before: MilliSecondsSinceUnixEpoch,
54
55 /// A UNIX timestamp after which the association is not known to be valid.
56 pub not_after: MilliSecondsSinceUnixEpoch,
57
58 /// The UNIX timestamp at which the association was verified.
59 pub ts: MilliSecondsSinceUnixEpoch,
60
61 /// The signatures of the verifying identity servers which show that the
62 /// association should be trusted, if you trust the verifying identity services.
63 pub signatures: ServerSignatures,
64 }
65
66 impl Request {
67 /// Creates a `Request` with the given session ID, client secret and Matrix user ID.
68 pub fn new(
69 sid: OwnedSessionId,
70 client_secret: OwnedClientSecret,
71 mxid: OwnedUserId,
72 ) -> Self {
73 Self { sid, client_secret, mxid }
74 }
75 }
76
77 impl Response {
78 /// Creates a `Response` with the given 3PID address, medium, Matrix user ID, timestamps and
79 /// signatures.
80 pub fn new(
81 address: String,
82 medium: Medium,
83 mxid: OwnedUserId,
84 not_before: MilliSecondsSinceUnixEpoch,
85 not_after: MilliSecondsSinceUnixEpoch,
86 ts: MilliSecondsSinceUnixEpoch,
87 signatures: ServerSignatures,
88 ) -> Self {
89 Self { address, medium, mxid, not_before, not_after, ts, signatures }
90 }
91 }
92}