ruma_federation_api/thirdparty/bind_callback.rs
1//! `PUT /_matrix/federation/*/3pid/onbind`
2//!
3//! Used by identity servers to notify the homeserver that one of its users has bound a third party
4//! identifier successfully, including any pending room invites the identity server has been made
5//! aware of.
6
7pub mod v1 {
8 //! `/v1/` ([spec])
9 //!
10 //! [spec]: https://spec.matrix.org/latest/server-server-api/#put_matrixfederationv13pidonbind
11
12 use ruma_common::{
13 api::{auth_scheme::NoAuthentication, request, response},
14 metadata,
15 serde::Raw,
16 thirdparty::Medium,
17 OwnedRoomId, OwnedUserId,
18 };
19 use ruma_events::room::member::SignedContent;
20 use serde::{Deserialize, Serialize};
21
22 metadata! {
23 method: PUT,
24 rate_limited: false,
25 authentication: NoAuthentication,
26 path: "/_matrix/federation/v1/3pid/onbind",
27 }
28
29 /// Request type for the `bind_callback` endpoint.
30 #[request]
31 pub struct Request {
32 /// The type of third party identifier.
33 ///
34 /// Currently only `Medium::Email` is supported.
35 pub medium: Medium,
36
37 /// The third party identifier itself.
38 ///
39 /// For example: an email address.
40 pub address: String,
41
42 /// The user that is now bound to the third party identifier.
43 pub mxid: OwnedUserId,
44
45 /// A list of pending invites that the third party identifier has received.
46 pub invites: Vec<ThirdPartyInvite>,
47 }
48
49 /// Response type for the `bind_callback` endpoint.
50 #[response]
51 #[derive(Default)]
52 pub struct Response {}
53
54 impl Request {
55 /// Creates a new `Request` with the given medium, address, user ID and third party invites.
56 pub fn new(
57 medium: Medium,
58 address: String,
59 mxid: OwnedUserId,
60 invites: Vec<ThirdPartyInvite>,
61 ) -> Self {
62 Self { medium, address, mxid, invites }
63 }
64
65 /// Creates a new `Request` with the given email address, user ID and third party invites.
66 pub fn email(address: String, mxid: OwnedUserId, invites: Vec<ThirdPartyInvite>) -> Self {
67 Self::new(Medium::Email, address, mxid, invites)
68 }
69 }
70
71 /// A pending invite the third party identifier has received.
72 #[derive(Debug, Clone, Deserialize, Serialize)]
73 #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
74 pub struct ThirdPartyInvite {
75 /// The type of third party invite issues.
76 ///
77 /// Currently only `Medium::Email` is used.
78 pub medium: Medium,
79
80 /// The third party identifier that received the invite.
81 pub address: String,
82
83 /// The now-bound user ID that received the invite.
84 pub mxid: OwnedUserId,
85
86 /// The room ID the invite is valid for.
87 pub room_id: OwnedRoomId,
88
89 /// The user ID that sent the invite.
90 pub sender: OwnedUserId,
91
92 /// A block of content which has been signed, which servers can use to verify the
93 /// third-party invite.
94 pub signed: Raw<SignedContent>,
95 }
96
97 impl ThirdPartyInvite {
98 /// Creates a new third party invite with the given parameters.
99 pub fn new(
100 address: String,
101 mxid: OwnedUserId,
102 room_id: OwnedRoomId,
103 sender: OwnedUserId,
104 signed: Raw<SignedContent>,
105 ) -> Self {
106 Self { medium: Medium::Email, address, mxid, room_id, sender, signed }
107 }
108 }
109
110 impl Response {
111 /// Construct an empty response.
112 pub fn new() -> Self {
113 Self {}
114 }
115 }
116}