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