1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
//! `POST /_matrix/identity/*/3pid/unbind`
//!
//! Remove an association between a session and a Matrix user ID.
pub mod v2 {
//! `/v2/` ([spec])
//!
//! [spec]: https://spec.matrix.org/latest/identity-service-api/#post_matrixidentityv23pidunbind
use ruma_common::{
api::{request, response, Metadata},
metadata,
thirdparty::Medium,
OwnedClientSecret, OwnedSessionId, OwnedUserId,
};
use serde::{Deserialize, Serialize};
const METADATA: Metadata = metadata! {
method: POST,
rate_limited: false,
authentication: AccessToken,
history: {
1.0 => "/_matrix/identity/v2/3pid/unbind",
}
};
/// Request type for the `unbind_3pid` endpoint.
#[request]
pub struct Request {
/// The proof that the client owns the 3PID.
///
/// If this is not provided, the request must be signed by the homeserver which controls
/// the `mxid`.
#[serde(flatten, skip_serializing_if = "Option::is_none")]
pub threepid_ownership_proof: Option<ThreePidOwnershipProof>,
/// The Matrix user ID to remove from the 3PIDs.
pub mxid: OwnedUserId,
/// The 3PID to remove.
///
/// Must match the 3PID used to generate the session if using `sid` and `client_secret` to
/// authenticate this request.
pub threepid: ThirdPartyId,
}
/// Response type for the `unbind_3pid` endpoint.
#[response]
#[derive(Default)]
pub struct Response {}
impl Request {
/// Creates a `Request` with the given Session ID, client secret, Matrix user ID and 3PID.
pub fn new(
threepid_ownership_proof: Option<ThreePidOwnershipProof>,
mxid: OwnedUserId,
threepid: ThirdPartyId,
) -> Self {
Self { threepid_ownership_proof, mxid, threepid }
}
}
impl Response {
/// Creates an empty `Response`.
pub fn new() -> Self {
Self {}
}
}
/// A 3PID to unbind.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct ThirdPartyId {
/// A medium matching the medium of identifier to unbind.
pub medium: Medium,
/// The 3PID address to remove.
pub address: String,
}
impl ThirdPartyId {
/// Creates a new `ThirdPartyId` with the given medium and address.
pub fn new(medium: Medium, address: String) -> Self {
Self { medium, address }
}
}
/// A proof that the client owns the 3PID.
///
/// Must be constructed using the same session ID and client secret generated and passed by the
/// `requestToken` call for the given 3PID.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct ThreePidOwnershipProof {
/// The Session ID generated by the `requestToken` call.
pub sid: OwnedSessionId,
/// The client secret passed to the `requestToken` call.
pub client_secret: OwnedClientSecret,
}
impl ThreePidOwnershipProof {
/// Creates a new `ThreePidOwnershipProof` with the given session ID and client secret.
pub fn new(sid: OwnedSessionId, client_secret: OwnedClientSecret) -> Self {
Self { sid, client_secret }
}
}
}