From 097bd6a86c84cca8da0ef2207830416fda64020f Mon Sep 17 00:00:00 2001 From: iinuwa Date: Thu, 9 Jan 2020 05:45:28 -0600 Subject: [PATCH] Add/update endpoints for requesting account management tokens --- CHANGELOG.md | 11 ++++- src/r0/account.rs | 20 ++++++++- ...request_3pid_management_token_via_email.rs | 41 ++++++++++++++++++ ...equest_3pid_management_token_via_msisdn.rs | 43 +++++++++++++++++++ .../account/request_password_change_token.rs | 29 ------------- ...request_password_change_token_via_email.rs | 41 ++++++++++++++++++ ...equest_password_change_token_via_msisdn.rs | 37 ++++++++++++++++ src/r0/account/request_register_token.rs | 29 ------------- .../request_registration_token_via_email.rs | 41 ++++++++++++++++++ .../request_registration_token_via_msisdn.rs | 43 +++++++++++++++++++ 10 files changed, 274 insertions(+), 61 deletions(-) create mode 100644 src/r0/account/request_3pid_management_token_via_email.rs create mode 100644 src/r0/account/request_3pid_management_token_via_msisdn.rs delete mode 100644 src/r0/account/request_password_change_token.rs create mode 100644 src/r0/account/request_password_change_token_via_email.rs create mode 100644 src/r0/account/request_password_change_token_via_msisdn.rs delete mode 100644 src/r0/account/request_register_token.rs create mode 100644 src/r0/account/request_registration_token_via_email.rs create mode 100644 src/r0/account/request_registration_token_via_msisdn.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index f5ba26a9..af0ba747 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ Breaking changes: * Move `r0::sync::get_state_events` to `r0::state::get_state_events` * Move `r0::sync::get_state_events_for_empty_key` to `r0::state::get_state_events_for_empty_key` * Move `r0::sync::get_state_events_for_key` to `r0::state::get_state_events_for_key` +* Update endpoints for requesting account management tokens via email: + * Move `r0::account::request_password_change_token` to `r0::account::request_password_change_token_via_email` + * Move `r0::account::request_register_token` to `r0::account::request_registration_token_via_email` + * Modify `r0::account::request_registration_token_via_email` not to be rate-limited and require authentication Improvements: @@ -23,6 +27,11 @@ Improvements: * Add `r0::keys` endpoints (introduced in r0.3.0) * Add `r0::session::get_login_types` (introduced in r0.4.0) * Add `r0::account::get_username_availability` (introduced in r0.4.0) +* Add endpoints to request management tokens (introduced upstream in r0.4.0): + * `r0::account::request_3pid_management_token_via_msisdn` + * `r0::account::request_password_change_token_via_msisdn` + * `r0::account::request_registration_token_via_msisdn` + * `r0::acount::request_3pid_management_token_via_email` # 0.5.0 @@ -42,4 +51,4 @@ Improvements: * Add `r0::appservice::set_room_visibility` (part of application service extensions for the client-server API) * Add `contains_url` to `r0::filter::RoomEventFilter` (introduced upstream in r0.3.0) * Update `r0::account::change_password` from r0.3.0 to r0.6.0 - * Add optional `auth` field + * Add optional `auth` field \ No newline at end of file diff --git a/src/r0/account.rs b/src/r0/account.rs index 6dee7f72..66460b05 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -4,8 +4,13 @@ pub mod change_password; pub mod deactivate; pub mod get_username_availability; pub mod register; -pub mod request_password_change_token; -pub mod request_register_token; +pub mod request_3pid_management_token_via_email; +pub mod request_3pid_management_token_via_msisdn; +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 whoami; use serde::{Deserialize, Serialize}; @@ -19,3 +24,14 @@ pub struct AuthenticationData { /// The value of the session key given by the homeserver. session: Option, } + +/// Additional authentication information for requestToken endpoints. +#[derive(Clone, Debug, Deserialize, Serialize)] +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, +} diff --git a/src/r0/account/request_3pid_management_token_via_email.rs b/src/r0/account/request_3pid_management_token_via_email.rs new file mode 100644 index 00000000..5485c1fa --- /dev/null +++ b/src/r0/account/request_3pid_management_token_via_email.rs @@ -0,0 +1,41 @@ +//! [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-email-requesttoken) + +use js_int::UInt; +use ruma_api::ruma_api; + +use super::IdentityServerInfo; + +ruma_api! { + metadata { + description: "Request a 3PID management token with a 3rd party email.", + method: POST, + name: "request_3pid_association_token_via_email", + path: "/_matrix/client/r0/account/3pid/email/requestToken", + rate_limited: false, + requires_authentication: false, + } + + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// The email address. + pub email: String, + /// Used to distinguish protocol level retries from requests to re-send the email. + pub send_attempt: UInt, + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option, + /// Optional identity server hostname and access token. Deprecated since r0.6.0. + #[serde(flatten)] + #[serde(skip_serializing_if = "Option::is_none")] + pub identity_server_info: Option, + } + + response { + /// The session identifier given by the identity server. + pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. + #[serde(skip_serializing_if = "Option::is_none")] + pub submit_url: Option + } +} diff --git a/src/r0/account/request_3pid_management_token_via_msisdn.rs b/src/r0/account/request_3pid_management_token_via_msisdn.rs new file mode 100644 index 00000000..0d0ef810 --- /dev/null +++ b/src/r0/account/request_3pid_management_token_via_msisdn.rs @@ -0,0 +1,43 @@ +//! [POST /_matrix/client/r0/account/3pid/msisdn/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-msisdn-requesttoken) + +use js_int::UInt; +use ruma_api::ruma_api; + +use super::IdentityServerInfo; + +ruma_api! { + metadata { + description: "Request a 3PID management token with a phone number.", + method: POST, + name: "request_3pid_association_token_via_msisdn", + path: "/_matrix/client/r0/account/3pid/msisdn/requestToken", + rate_limited: false, + requires_authentication: false, + } + + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// Two-letter ISO 3166 country code for the phone number. + pub country: String, + /// Phone number to validate. + pub phone_number: String, + /// Used to distinguish protocol level retries from requests to re-send the SMS. + pub send_attempt: UInt, + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option, + /// Optional identity server hostname and access token. Deprecated since r0.6.0. + #[serde(flatten)] + #[serde(skip_serializing_if = "Option::is_none")] + pub identity_server_info: Option, + } + + response { + /// The session identifier given by the identity server. + pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. + #[serde(skip_serializing_if = "Option::is_none")] + pub submit_url: Option + } +} diff --git a/src/r0/account/request_password_change_token.rs b/src/r0/account/request_password_change_token.rs deleted file mode 100644 index 976ba5fd..00000000 --- a/src/r0/account/request_password_change_token.rs +++ /dev/null @@ -1,29 +0,0 @@ -//! [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-password-email-requesttoken) - -use js_int::UInt; -use ruma_api::ruma_api; - -ruma_api! { - metadata { - description: "Request that a password change token is sent to the given email address.", - method: POST, - name: "request_password_change_token", - path: "/_matrix/client/r0/account/password/email/requestToken", - rate_limited: false, - requires_authentication: false, - } - - request { - /// TODO: This parameter is not documented in the spec. - pub client_secret: String, - /// TODO: This parameter is not documented in the spec. - pub email: String, - /// TODO: This parameter is not documented in the spec. - #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option, - /// TODO: This parameter is not documented in the spec. - pub send_attempt: UInt, - } - - response {} -} diff --git a/src/r0/account/request_password_change_token_via_email.rs b/src/r0/account/request_password_change_token_via_email.rs new file mode 100644 index 00000000..0ddbbf77 --- /dev/null +++ b/src/r0/account/request_password_change_token_via_email.rs @@ -0,0 +1,41 @@ +//! [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-account-password-email-requesttoken) + +use js_int::UInt; +use ruma_api::ruma_api; + +use super::IdentityServerInfo; + +ruma_api! { + metadata { + description: "Request that a password change token is sent to the given email address.", + method: POST, + name: "request_password_change_token_via_email", + path: "/_matrix/client/r0/account/password/email/requestToken", + rate_limited: false, + requires_authentication: false, + } + + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// The email address. + pub email: String, + /// Used to distinguish protocol level retries from requests to re-send the email. + pub send_attempt: UInt, + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option, + /// Optional identity server hostname and access token. Deprecated since r0.6.0. + #[serde(flatten)] + #[serde(skip_serializing_if = "Option::is_none")] + pub identity_server_info: Option, + } + + response { + /// The session identifier given by the identity server. + pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. + #[serde(skip_serializing_if = "Option::is_none")] + pub submit_url: Option + } +} diff --git a/src/r0/account/request_password_change_token_via_msisdn.rs b/src/r0/account/request_password_change_token_via_msisdn.rs new file mode 100644 index 00000000..35eaf27f --- /dev/null +++ b/src/r0/account/request_password_change_token_via_msisdn.rs @@ -0,0 +1,37 @@ +//! [POST /_matrix/client/r0/account/password/msisdn/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-account-password-msisdn-requesttoken) + +use js_int::UInt; +use ruma_api::ruma_api; + +ruma_api! { + metadata { + description: "Request that a password change token is sent to the given phone number.", + method: POST, + name: "request_password_change_token_via_msisdn", + path: "/_matrix/client/r0/account/password/msisdn/requestToken", + rate_limited: false, + requires_authentication: false, + } + + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// Two-letter ISO 3166 country code for the phone number. + pub country: String, + /// Phone number to validate. + pub phone_number: String, + /// Used to distinguish protocol level retries from requests to re-send the SMS. + pub send_attempt: UInt, + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option, + } + + response { + /// The session identifier given by the identity server. + pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. + #[serde(skip_serializing_if = "Option::is_none")] + pub submit_url: Option + } +} diff --git a/src/r0/account/request_register_token.rs b/src/r0/account/request_register_token.rs deleted file mode 100644 index d06321cc..00000000 --- a/src/r0/account/request_register_token.rs +++ /dev/null @@ -1,29 +0,0 @@ -//! [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-register-email-requesttoken) - -use js_int::UInt; -use ruma_api::ruma_api; - -ruma_api! { - metadata { - description: "Request a register token with a 3rd party email.", - method: POST, - name: "request_register_token", - path: "/_matrix/client/r0/register/email/requestToken", - rate_limited: true, - requires_authentication: true, - } - - request { - /// Client-generated secret string used to protect this session. - pub client_secret: String, - /// The email address. - pub email: 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(skip_serializing_if = "Option::is_none")] - pub id_server: Option, - /// Used to distinguish protocol level retries from requests to re-send the email. - pub send_attempt: UInt, - } - - response {} -} diff --git a/src/r0/account/request_registration_token_via_email.rs b/src/r0/account/request_registration_token_via_email.rs new file mode 100644 index 00000000..2b10eafc --- /dev/null +++ b/src/r0/account/request_registration_token_via_email.rs @@ -0,0 +1,41 @@ +//! [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-register-email-requesttoken) + +use js_int::UInt; +use ruma_api::ruma_api; + +use super::IdentityServerInfo; + +ruma_api! { + metadata { + description: "Request a registration token with a 3rd party email.", + method: POST, + name: "request_registration_token_via_email", + path: "/_matrix/client/r0/register/email/requestToken", + rate_limited: false, + requires_authentication: false, + } + + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// The email address. + pub email: String, + /// Used to distinguish protocol level retries from requests to re-send the email. + pub send_attempt: UInt, + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option, + /// Optional identity server hostname and access token. Deprecated since r0.6.0. + #[serde(flatten)] + #[serde(skip_serializing_if = "Option::is_none")] + pub identity_server_info: Option, + } + + response { + /// The session identifier given by the identity server. + pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. + #[serde(skip_serializing_if = "Option::is_none")] + pub submit_url: Option + } +} diff --git a/src/r0/account/request_registration_token_via_msisdn.rs b/src/r0/account/request_registration_token_via_msisdn.rs new file mode 100644 index 00000000..dc8dfa6d --- /dev/null +++ b/src/r0/account/request_registration_token_via_msisdn.rs @@ -0,0 +1,43 @@ +//! [POST /_matrix/client/r0/register/msisdn/requestToken](https://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-register-msisdn-requesttoken) + +use js_int::UInt; +use ruma_api::ruma_api; + +use super::IdentityServerInfo; + +ruma_api! { + metadata { + description: "Request a registration token with a phone number.", + method: POST, + name: "request_registration_token_via_msisdn", + path: "/_matrix/client/r0/register/msisdn/requestToken", + rate_limited: false, + requires_authentication: false, + } + + request { + /// Client-generated secret string used to protect this session. + pub client_secret: String, + /// Two-letter ISO 3166 country code for the phone number. + pub country: String, + /// Phone number to validate. + pub phone_number: String, + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option, + /// Used to distinguish protocol level retries from requests to re-send the SMS. + pub send_attempt: UInt, + /// Optional identity server hostname and access token. Deprecated since r0.6.0. + #[serde(flatten)] + #[serde(skip_serializing_if = "Option::is_none")] + pub identity_server_info: Option, + } + + response { + /// The session identifier given by the identity server. + pub sid: String, + /// URL to submit validation token to. If omitted, verification happens without client. + #[serde(skip_serializing_if = "Option::is_none")] + pub submit_url: Option + } +}