client-api: Move token registration to new unstable-spec feature

This commit is contained in:
Jonathan de Jong 2022-01-31 19:39:00 +01:00 committed by Jonas Platte
parent 21ef0a3c63
commit f631685389
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
8 changed files with 44 additions and 37 deletions

View File

@ -38,10 +38,15 @@ them. Check out the documentation [on docs.rs][docs] (or on
## Status ## Status
As of 2021-02-10, we support all events and REST endpoints the latest released As of 2022-01-31, we support all events and REST endpoints of the v1 version of
versions of the various Matrix APIs. Various changes from the unstable version the Matrix specification, with v1.1 coverage in progress.
of the specifications and some MSCs are also implemented, gated behind the
`unstable-pre-spec` Cargo feature. Various changes from the unreleased version of the specification are also
implemented, gated behind the `unstable-spec` Cargo feature.
Various changes from in-progress MSCs, finished MSCs,
and (often) unreleased versions of the specification are also implemented,
gated behind the `unstable-pre-spec` Cargo feature.
## Contributing ## Contributing

View File

@ -24,6 +24,7 @@ compat = []
unstable-exhaustive-types = [] unstable-exhaustive-types = []
# feature dependency required for r0::room::create_room::CreationContent::into_event_content # feature dependency required for r0::room::create_room::CreationContent::into_event_content
unstable-pre-spec = ["ruma-events/unstable-pre-spec"] unstable-pre-spec = ["ruma-events/unstable-pre-spec"]
unstable-spec = []
client = [] client = []
server = [] server = []

View File

@ -3,7 +3,7 @@
pub mod add_3pid; pub mod add_3pid;
pub mod bind_3pid; pub mod bind_3pid;
pub mod change_password; pub mod change_password;
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-spec")] // todo: v1.2
pub mod check_registration_token_validity; pub mod check_registration_token_validity;
pub mod deactivate; pub mod deactivate;
pub mod delete_3pid; pub mod delete_3pid;

View File

@ -1,4 +1,4 @@
//! [GET /_matrix/client/unstable/org.matrix.msc3231/register/org.matrix.msc3231.login.registration_token/validity](https://github.com/matrix-org/matrix-doc/blob/main/proposals/3231-token-authenticated-registration.md#checking-the-validity-of-a-token) //! [GET /_matrix/client/v1/register/m.login.registration_token/validity](https://spec.matrix.org/unstable/client-server-api/#get_matrixclientv1registermloginregistration_tokenvalidity)
use ruma_api::ruma_api; use ruma_api::ruma_api;
@ -7,7 +7,7 @@ ruma_api! {
description: "Checks to see if the given registration token is valid.", description: "Checks to see if the given registration token is valid.",
method: GET, method: GET,
name: "check_registration_token_validity", name: "check_registration_token_validity",
path: "/_matrix/client/unstable/org.matrix.msc3231/register/org.matrix.msc3231.login.registration_token/validity", path: "/_matrix/client/v1/register/m.login.registration_token/validity",
rate_limited: true, rate_limited: true,
authentication: None, authentication: None,
} }

View File

@ -58,8 +58,8 @@ pub enum AuthData<'a> {
/// Dummy authentication (`m.login.dummy`). /// Dummy authentication (`m.login.dummy`).
Dummy(Dummy<'a>), Dummy(Dummy<'a>),
/// Registration token-based authentication (`org.matrix.msc3231.login.registration_token`). /// Registration token-based authentication (`m.login.registration_token`).
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-spec")] // todo: v1.2
RegistrationToken(RegistrationToken<'a>), RegistrationToken(RegistrationToken<'a>),
/// Fallback acknowledgement. /// Fallback acknowledgement.
@ -85,7 +85,7 @@ impl<'a> AuthData<'a> {
Self::EmailIdentity(_) => Some(AuthType::EmailIdentity), Self::EmailIdentity(_) => Some(AuthType::EmailIdentity),
Self::Msisdn(_) => Some(AuthType::Msisdn), Self::Msisdn(_) => Some(AuthType::Msisdn),
Self::Dummy(_) => Some(AuthType::Dummy), Self::Dummy(_) => Some(AuthType::Dummy),
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-spec")] // todo: v1.2
Self::RegistrationToken(_) => Some(AuthType::RegistrationToken), Self::RegistrationToken(_) => Some(AuthType::RegistrationToken),
Self::FallbackAcknowledgement(_) => None, Self::FallbackAcknowledgement(_) => None,
Self::_Custom(c) => Some(AuthType::_Custom(PrivOwnedStr(c.auth_type.into()))), Self::_Custom(c) => Some(AuthType::_Custom(PrivOwnedStr(c.auth_type.into()))),
@ -102,7 +102,7 @@ impl<'a> AuthData<'a> {
Self::EmailIdentity(x) => x.session, Self::EmailIdentity(x) => x.session,
Self::Msisdn(x) => x.session, Self::Msisdn(x) => x.session,
Self::Dummy(x) => x.session, Self::Dummy(x) => x.session,
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-spec")] // todo: v1.2
Self::RegistrationToken(x) => x.session, Self::RegistrationToken(x) => x.session,
Self::FallbackAcknowledgement(x) => Some(x.session), Self::FallbackAcknowledgement(x) => Some(x.session),
Self::_Custom(x) => x.session, Self::_Custom(x) => x.session,
@ -145,7 +145,7 @@ impl<'a> AuthData<'a> {
thirdparty_id_creds: x.thirdparty_id_creds, thirdparty_id_creds: x.thirdparty_id_creds,
session: None, session: None,
})), })),
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-spec")] // todo: v1.2
Self::RegistrationToken(x) => { Self::RegistrationToken(x) => {
Cow::Owned(serialize(RegistrationToken { token: x.token, session: None })) Cow::Owned(serialize(RegistrationToken { token: x.token, session: None }))
} }
@ -190,10 +190,8 @@ impl IncomingAuthData {
"m.login.email.identity" => Self::EmailIdentity(deserialize_variant(session, data)?), "m.login.email.identity" => Self::EmailIdentity(deserialize_variant(session, data)?),
"m.login.msisdn" => Self::Msisdn(deserialize_variant(session, data)?), "m.login.msisdn" => Self::Msisdn(deserialize_variant(session, data)?),
"m.login.dummy" => Self::Dummy(deserialize_variant(session, data)?), "m.login.dummy" => Self::Dummy(deserialize_variant(session, data)?),
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-spec")] // todo: v1.2
"org.matrix.msc3231.login.registration_token" => { "m.registration_token" => Self::RegistrationToken(deserialize_variant(session, data)?),
Self::RegistrationToken(deserialize_variant(session, data)?)
}
_ => Self::_Custom(IncomingCustomAuthData { _ => Self::_Custom(IncomingCustomAuthData {
auth_type: auth_type.into(), auth_type: auth_type.into(),
session, session,
@ -212,7 +210,7 @@ impl IncomingAuthData {
Self::EmailIdentity(_) => Some(AuthType::EmailIdentity), Self::EmailIdentity(_) => Some(AuthType::EmailIdentity),
Self::Msisdn(_) => Some(AuthType::Msisdn), Self::Msisdn(_) => Some(AuthType::Msisdn),
Self::Dummy(_) => Some(AuthType::Dummy), Self::Dummy(_) => Some(AuthType::Dummy),
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-spec")] // todo: v1.2
Self::RegistrationToken(_) => Some(AuthType::RegistrationToken), Self::RegistrationToken(_) => Some(AuthType::RegistrationToken),
Self::FallbackAcknowledgement(_) => None, Self::FallbackAcknowledgement(_) => None,
Self::_Custom(c) => Some(AuthType::_Custom(PrivOwnedStr(c.auth_type.as_str().into()))), Self::_Custom(c) => Some(AuthType::_Custom(PrivOwnedStr(c.auth_type.as_str().into()))),
@ -229,7 +227,7 @@ impl IncomingAuthData {
Self::EmailIdentity(x) => x.session.as_deref(), Self::EmailIdentity(x) => x.session.as_deref(),
Self::Msisdn(x) => x.session.as_deref(), Self::Msisdn(x) => x.session.as_deref(),
Self::Dummy(x) => x.session.as_deref(), Self::Dummy(x) => x.session.as_deref(),
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-spec")] // todo: v1.2
Self::RegistrationToken(x) => x.session.as_deref(), Self::RegistrationToken(x) => x.session.as_deref(),
Self::FallbackAcknowledgement(x) => Some(&x.session), Self::FallbackAcknowledgement(x) => Some(&x.session),
Self::_Custom(x) => x.session.as_deref(), Self::_Custom(x) => x.session.as_deref(),
@ -272,7 +270,7 @@ impl IncomingAuthData {
thirdparty_id_creds: &x.thirdparty_id_creds, thirdparty_id_creds: &x.thirdparty_id_creds,
session: None, session: None,
})), })),
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-spec")] // todo: v1.2
Self::RegistrationToken(x) => { Self::RegistrationToken(x) => {
Cow::Owned(serialize(RegistrationToken { token: &x.token, session: None })) Cow::Owned(serialize(RegistrationToken { token: &x.token, session: None }))
} }
@ -292,7 +290,7 @@ impl IncomingAuthData {
Self::EmailIdentity(a) => AuthData::EmailIdentity(a.to_outgoing()), Self::EmailIdentity(a) => AuthData::EmailIdentity(a.to_outgoing()),
Self::Msisdn(a) => AuthData::Msisdn(a.to_outgoing()), Self::Msisdn(a) => AuthData::Msisdn(a.to_outgoing()),
Self::Dummy(a) => AuthData::Dummy(a.to_outgoing()), Self::Dummy(a) => AuthData::Dummy(a.to_outgoing()),
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-spec")] // todo: v1.2
Self::RegistrationToken(a) => AuthData::RegistrationToken(a.to_outgoing()), Self::RegistrationToken(a) => AuthData::RegistrationToken(a.to_outgoing()),
Self::FallbackAcknowledgement(a) => AuthData::FallbackAcknowledgement(a.to_outgoing()), Self::FallbackAcknowledgement(a) => AuthData::FallbackAcknowledgement(a.to_outgoing()),
Self::_Custom(a) => AuthData::_Custom(CustomAuthData { Self::_Custom(a) => AuthData::_Custom(CustomAuthData {
@ -335,8 +333,8 @@ impl<'de> Deserialize<'de> for IncomingAuthData {
Some("m.login.email.identity") => from_raw_json_value(&json).map(Self::EmailIdentity), Some("m.login.email.identity") => from_raw_json_value(&json).map(Self::EmailIdentity),
Some("m.login.msisdn") => from_raw_json_value(&json).map(Self::Msisdn), Some("m.login.msisdn") => from_raw_json_value(&json).map(Self::Msisdn),
Some("m.login.dummy") => from_raw_json_value(&json).map(Self::Dummy), Some("m.login.dummy") => from_raw_json_value(&json).map(Self::Dummy),
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-spec")] // todo: v1.2
Some("org.matrix.msc3231.login.registration_token") => { Some("m.login.registration_token") => {
from_raw_json_value(&json).map(Self::RegistrationToken) from_raw_json_value(&json).map(Self::RegistrationToken)
} }
None => from_raw_json_value(&json).map(Self::FallbackAcknowledgement), None => from_raw_json_value(&json).map(Self::FallbackAcknowledgement),
@ -381,9 +379,9 @@ pub enum AuthType {
#[ruma_enum(rename = "m.login.dummy")] #[ruma_enum(rename = "m.login.dummy")]
Dummy, Dummy,
/// Registration token-based authentication (`org.matrix.msc3231.login.registration_token`). /// Registration token-based authentication (`m.login.registration_token`).
#[cfg(feature = "unstable-pre-spec")] #[ruma_enum(rename = "m.login.registration_token")]
#[ruma_enum(rename = "org.matrix.msc3231.login.registration_token")] #[cfg(feature = "unstable-spec")] // todo: v1.2
RegistrationToken, RegistrationToken,
#[doc(hidden)] #[doc(hidden)]
@ -608,13 +606,13 @@ impl IncomingDummy {
/// Data for registration token-based UIAA flow. /// Data for registration token-based UIAA flow.
/// ///
/// See [MSC3231] for how to use this. /// See [the spec] for how to use this.
/// ///
/// [MSC3231]: https://github.com/matrix-org/matrix-doc/pull/3231 /// [the spec]: https://spec.matrix.org/unstable/client-server-api/#token-authenticated-registration
#[derive(Clone, Debug, Outgoing, Serialize)] #[derive(Clone, Debug, Outgoing, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[cfg(feature = "unstable-pre-spec")] #[serde(tag = "type", rename = "m.login.registration_token")]
#[serde(tag = "type", rename = "org.matrix.msc3231.login.registration_token")] #[cfg(feature = "unstable-spec")] // todo: v1.2
pub struct RegistrationToken<'a> { pub struct RegistrationToken<'a> {
/// The registration token. /// The registration token.
pub token: &'a str, pub token: &'a str,
@ -623,7 +621,7 @@ pub struct RegistrationToken<'a> {
pub session: Option<&'a str>, pub session: Option<&'a str>,
} }
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-spec")] // todo: v1.2
impl<'a> RegistrationToken<'a> { impl<'a> RegistrationToken<'a> {
/// Creates a new `RegistrationToken` with the given token. /// Creates a new `RegistrationToken` with the given token.
pub fn new(token: &'a str) -> Self { pub fn new(token: &'a str) -> Self {
@ -631,7 +629,7 @@ impl<'a> RegistrationToken<'a> {
} }
} }
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-spec")] // todo: v1.2
impl IncomingRegistrationToken { impl IncomingRegistrationToken {
/// Convert from `IncomingRegistrationToken` to `RegistrationToken`. /// Convert from `IncomingRegistrationToken` to `RegistrationToken`.
fn to_outgoing(&self) -> RegistrationToken<'_> { fn to_outgoing(&self) -> RegistrationToken<'_> {

View File

@ -65,7 +65,7 @@ fn deserialize_auth_data_direct_request() {
} }
#[test] #[test]
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-spec")] // todo: v1.2
fn serialize_auth_data_registration_token() { fn serialize_auth_data_registration_token() {
let auth_data = AuthData::RegistrationToken( let auth_data = AuthData::RegistrationToken(
assign!(uiaa::RegistrationToken::new("mytoken"), { session: Some("session") }), assign!(uiaa::RegistrationToken::new("mytoken"), { session: Some("session") }),
@ -74,7 +74,7 @@ fn serialize_auth_data_registration_token() {
assert_matches!( assert_matches!(
to_json_value(auth_data), to_json_value(auth_data),
Ok(val) if val == json!({ Ok(val) if val == json!({
"type": "org.matrix.msc3231.login.registration_token", "type": "m.login.registration_token",
"token": "mytoken", "token": "mytoken",
"session": "session", "session": "session",
}) })
@ -82,10 +82,10 @@ fn serialize_auth_data_registration_token() {
} }
#[test] #[test]
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-spec")] // todo: v1.2
fn deserialize_auth_data_registration_token() { fn deserialize_auth_data_registration_token() {
let json = json!({ let json = json!({
"type": "org.matrix.msc3231.login.registration_token", "type": "m.login.registration_token",
"token": "mytoken", "token": "mytoken",
"session": "session", "session": "session",
}); });

View File

@ -119,6 +119,9 @@ unstable-pre-spec = [
#"ruma-identity-service-api/unstable-pre-spec", #"ruma-identity-service-api/unstable-pre-spec",
#"ruma-push-gateway-api/unstable-pre-spec", #"ruma-push-gateway-api/unstable-pre-spec",
] ]
unstable-spec = [
"ruma-client-api/unstable-spec"
]
[dependencies] [dependencies]
assign = "1.1.1" assign = "1.1.1"

View File

@ -72,7 +72,7 @@ impl CiTask {
// 2. Run tests // 2. Run tests
let workspace_res = let workspace_res =
cmd!("rustup run stable cargo test --workspace --features full,unstable-pre-spec") cmd!("rustup run stable cargo test --workspace --features full,unstable-pre-spec,unstable-spec")
.run(); .run();
let events_compat_res = let events_compat_res =
cmd!("rustup run stable cargo test -p ruma-events --features compat compat").run(); cmd!("rustup run stable cargo test -p ruma-events --features compat compat").run();
@ -98,7 +98,7 @@ impl CiTask {
let clippy_all_res = cmd!( let clippy_all_res = cmd!(
" "
rustup run nightly cargo clippy rustup run nightly cargo clippy
--workspace --all-targets --features=full,compat,unstable-pre-spec -- -D warnings --workspace --all-targets --features=full,compat,unstable-pre-spec,unstable-spec -- -D warnings
" "
) )
.run(); .run();