Add missing 3PID endpoints

This commit is contained in:
iinuwa 2020-01-13 16:22:09 -06:00 committed by Jonas Platte
parent 258fbf5a01
commit 4bc52af69a
7 changed files with 118 additions and 17 deletions

View File

@ -1,7 +1,9 @@
//! Endpoints for account registration and management.
pub mod bind_3pid;
pub mod change_password;
pub mod deactivate;
pub mod delete_3pid;
pub mod get_username_availability;
pub mod register;
pub mod request_3pid_management_token_via_email;
@ -10,6 +12,7 @@ pub mod request_password_change_token_via_email;
pub mod request_password_change_token_via_msisdn;
pub mod request_registration_token_via_email;
pub mod request_registration_token_via_msisdn;
pub mod unbind_3pid;
pub mod whoami;
@ -30,8 +33,15 @@ pub struct AuthenticationData {
pub struct IdentityServerInfo {
/// The ID server to send the onward request to as a hostname with an
/// appended colon and port number if the port is not the default.
/// Deprecated since r0.6.0.
pub id_server: String,
/// Access token previously registered with identity server.
pub id_access_token: String,
}
/// Possible values for deleting or unbinding 3PIDs
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
enum ThirdPartyIdRemovalStatus {
NoSupport,
Success,
}

View File

@ -0,0 +1,29 @@
//! [POST /_matrix/client/r0/account/3pid/bind](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-bind)
use ruma_api::ruma_api;
use super::IdentityServerInfo;
ruma_api! {
metadata {
description: "Bind a 3PID to a user's account on an identity server",
method: POST,
name: "bind_3pid",
path: "/_matrix/client/r0/account/3pid/bind",
rate_limited: true,
requires_authentication: true,
}
request {
/// Client-generated secret string used to protect this session.
pub client_secret: String,
/// The ID server to send the onward request to as a hostname with an
/// appended colon and port number if the port is not the default.
#[serde(flatten)]
pub identity_server_info: IdentityServerInfo,
/// The session identifier given by the identity server.
pub sid: String,
}
response {}
}

View File

@ -0,0 +1,33 @@
//! [POST /_matrix/client/r0/account/3pid/delete](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-delete)
use ruma_api::ruma_api;
use super::ThirdPartyIdRemovalStatus;
use crate::r0::thirdparty::Medium;
ruma_api! {
metadata {
description: "Delete a 3PID from a user's account on an identity server.",
method: POST,
name: "delete_3pid",
path: "/_matrix/client/r0/account/3pid/delete",
rate_limited: false,
requires_authentication: true,
}
request {
/// Identity server to delete from.
#[serde(skip_serializing_if = "Option::is_none")]
id_server: Option<String>,
/// Medium of the 3PID to be removed.
medium: Medium,
/// Third-party address being removed.
address: String,
}
response {
/// Result of unbind operation.
id_server_unbind_result: ThirdPartyIdRemovalStatus,
}
}

View File

@ -0,0 +1,33 @@
//! [POST /_matrix/client/r0/account/3pid/unbind](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-unbind)
use ruma_api::ruma_api;
use super::ThirdPartyIdRemovalStatus;
use crate::r0::thirdparty::Medium;
ruma_api! {
metadata {
description: "Unbind a 3PID from a user's account on an identity server.",
method: POST,
name: "unbind_3pid",
path: "/_matrix/client/r0/account/3pid/unbind",
rate_limited: false,
requires_authentication: true,
}
request {
/// Identity server to unbind from.
#[serde(skip_serializing_if = "Option::is_none")]
id_server: Option<String>,
/// Medium of the 3PID to be removed.
medium: Medium,
/// Third-party address being removed.
address: String,
}
response {
/// Result of unbind operation.
id_server_unbind_result: ThirdPartyIdRemovalStatus,
}
}

View File

@ -1,5 +1,6 @@
//! [GET /_matrix/client/r0/account/3pid](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-account-3pid)
use crate::r0::thirdparty::Medium;
use ruma_api::ruma_api;
use serde::{Deserialize, Serialize};
@ -22,14 +23,6 @@ ruma_api! {
}
}
/// The medium of third party identifier.
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum Medium {
/// An email address.
#[serde(rename = "email")]
Email,
}
/// An identifier external to Matrix.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ThirdPartyIdentifier {

View File

@ -1,5 +1,6 @@
//! [POST /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-login)
use crate::r0::thirdparty::Medium;
use ruma_api::ruma_api;
use ruma_identifiers::{DeviceId, UserId};
use serde::{Deserialize, Serialize};
@ -52,14 +53,6 @@ ruma_api! {
}
}
/// The medium of a third party identifier.
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum Medium {
/// An email address.
#[serde(rename = "email")]
Email,
}
/// The authentication mechanism.
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum LoginType {

View File

@ -72,3 +72,13 @@ pub struct User {
/// Information used to identify this third party user.
pub fields: HashMap<String, String>,
}
/// The medium of a third party identifier.
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Medium {
/// Email address identifier
Email,
/// Phone number identifier
MSISDN,
}