client-api: Move token registration to new unstable-spec feature
This commit is contained in:
parent
21ef0a3c63
commit
f631685389
13
README.md
13
README.md
@ -38,10 +38,15 @@ them. Check out the documentation [on docs.rs][docs] (or on
|
||||
|
||||
## Status
|
||||
|
||||
As of 2021-02-10, we support all events and REST endpoints the latest released
|
||||
versions of the various Matrix APIs. Various changes from the unstable version
|
||||
of the specifications and some MSCs are also implemented, gated behind the
|
||||
`unstable-pre-spec` Cargo feature.
|
||||
As of 2022-01-31, we support all events and REST endpoints of the v1 version of
|
||||
the Matrix specification, with v1.1 coverage in progress.
|
||||
|
||||
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
|
||||
|
||||
|
@ -24,6 +24,7 @@ compat = []
|
||||
unstable-exhaustive-types = []
|
||||
# feature dependency required for r0::room::create_room::CreationContent::into_event_content
|
||||
unstable-pre-spec = ["ruma-events/unstable-pre-spec"]
|
||||
unstable-spec = []
|
||||
client = []
|
||||
server = []
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
pub mod add_3pid;
|
||||
pub mod bind_3pid;
|
||||
pub mod change_password;
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[cfg(feature = "unstable-spec")] // todo: v1.2
|
||||
pub mod check_registration_token_validity;
|
||||
pub mod deactivate;
|
||||
pub mod delete_3pid;
|
||||
|
@ -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;
|
||||
|
||||
@ -7,7 +7,7 @@ ruma_api! {
|
||||
description: "Checks to see if the given registration token is valid.",
|
||||
method: GET,
|
||||
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,
|
||||
authentication: None,
|
||||
}
|
||||
|
@ -58,8 +58,8 @@ pub enum AuthData<'a> {
|
||||
/// Dummy authentication (`m.login.dummy`).
|
||||
Dummy(Dummy<'a>),
|
||||
|
||||
/// Registration token-based authentication (`org.matrix.msc3231.login.registration_token`).
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
/// Registration token-based authentication (`m.login.registration_token`).
|
||||
#[cfg(feature = "unstable-spec")] // todo: v1.2
|
||||
RegistrationToken(RegistrationToken<'a>),
|
||||
|
||||
/// Fallback acknowledgement.
|
||||
@ -85,7 +85,7 @@ impl<'a> AuthData<'a> {
|
||||
Self::EmailIdentity(_) => Some(AuthType::EmailIdentity),
|
||||
Self::Msisdn(_) => Some(AuthType::Msisdn),
|
||||
Self::Dummy(_) => Some(AuthType::Dummy),
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[cfg(feature = "unstable-spec")] // todo: v1.2
|
||||
Self::RegistrationToken(_) => Some(AuthType::RegistrationToken),
|
||||
Self::FallbackAcknowledgement(_) => None,
|
||||
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::Msisdn(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::FallbackAcknowledgement(x) => Some(x.session),
|
||||
Self::_Custom(x) => x.session,
|
||||
@ -145,7 +145,7 @@ impl<'a> AuthData<'a> {
|
||||
thirdparty_id_creds: x.thirdparty_id_creds,
|
||||
session: None,
|
||||
})),
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[cfg(feature = "unstable-spec")] // todo: v1.2
|
||||
Self::RegistrationToken(x) => {
|
||||
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.msisdn" => Self::Msisdn(deserialize_variant(session, data)?),
|
||||
"m.login.dummy" => Self::Dummy(deserialize_variant(session, data)?),
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
"org.matrix.msc3231.login.registration_token" => {
|
||||
Self::RegistrationToken(deserialize_variant(session, data)?)
|
||||
}
|
||||
#[cfg(feature = "unstable-spec")] // todo: v1.2
|
||||
"m.registration_token" => Self::RegistrationToken(deserialize_variant(session, data)?),
|
||||
_ => Self::_Custom(IncomingCustomAuthData {
|
||||
auth_type: auth_type.into(),
|
||||
session,
|
||||
@ -212,7 +210,7 @@ impl IncomingAuthData {
|
||||
Self::EmailIdentity(_) => Some(AuthType::EmailIdentity),
|
||||
Self::Msisdn(_) => Some(AuthType::Msisdn),
|
||||
Self::Dummy(_) => Some(AuthType::Dummy),
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[cfg(feature = "unstable-spec")] // todo: v1.2
|
||||
Self::RegistrationToken(_) => Some(AuthType::RegistrationToken),
|
||||
Self::FallbackAcknowledgement(_) => None,
|
||||
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::Msisdn(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::FallbackAcknowledgement(x) => Some(&x.session),
|
||||
Self::_Custom(x) => x.session.as_deref(),
|
||||
@ -272,7 +270,7 @@ impl IncomingAuthData {
|
||||
thirdparty_id_creds: &x.thirdparty_id_creds,
|
||||
session: None,
|
||||
})),
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[cfg(feature = "unstable-spec")] // todo: v1.2
|
||||
Self::RegistrationToken(x) => {
|
||||
Cow::Owned(serialize(RegistrationToken { token: &x.token, session: None }))
|
||||
}
|
||||
@ -292,7 +290,7 @@ impl IncomingAuthData {
|
||||
Self::EmailIdentity(a) => AuthData::EmailIdentity(a.to_outgoing()),
|
||||
Self::Msisdn(a) => AuthData::Msisdn(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::FallbackAcknowledgement(a) => AuthData::FallbackAcknowledgement(a.to_outgoing()),
|
||||
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.msisdn") => from_raw_json_value(&json).map(Self::Msisdn),
|
||||
Some("m.login.dummy") => from_raw_json_value(&json).map(Self::Dummy),
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
Some("org.matrix.msc3231.login.registration_token") => {
|
||||
#[cfg(feature = "unstable-spec")] // todo: v1.2
|
||||
Some("m.login.registration_token") => {
|
||||
from_raw_json_value(&json).map(Self::RegistrationToken)
|
||||
}
|
||||
None => from_raw_json_value(&json).map(Self::FallbackAcknowledgement),
|
||||
@ -381,9 +379,9 @@ pub enum AuthType {
|
||||
#[ruma_enum(rename = "m.login.dummy")]
|
||||
Dummy,
|
||||
|
||||
/// Registration token-based authentication (`org.matrix.msc3231.login.registration_token`).
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[ruma_enum(rename = "org.matrix.msc3231.login.registration_token")]
|
||||
/// Registration token-based authentication (`m.login.registration_token`).
|
||||
#[ruma_enum(rename = "m.login.registration_token")]
|
||||
#[cfg(feature = "unstable-spec")] // todo: v1.2
|
||||
RegistrationToken,
|
||||
|
||||
#[doc(hidden)]
|
||||
@ -608,13 +606,13 @@ impl IncomingDummy {
|
||||
|
||||
/// 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)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[serde(tag = "type", rename = "org.matrix.msc3231.login.registration_token")]
|
||||
#[serde(tag = "type", rename = "m.login.registration_token")]
|
||||
#[cfg(feature = "unstable-spec")] // todo: v1.2
|
||||
pub struct RegistrationToken<'a> {
|
||||
/// The registration token.
|
||||
pub token: &'a str,
|
||||
@ -623,7 +621,7 @@ pub struct RegistrationToken<'a> {
|
||||
pub session: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[cfg(feature = "unstable-spec")] // todo: v1.2
|
||||
impl<'a> RegistrationToken<'a> {
|
||||
/// Creates a new `RegistrationToken` with the given token.
|
||||
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 {
|
||||
/// Convert from `IncomingRegistrationToken` to `RegistrationToken`.
|
||||
fn to_outgoing(&self) -> RegistrationToken<'_> {
|
||||
|
@ -65,7 +65,7 @@ fn deserialize_auth_data_direct_request() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[cfg(feature = "unstable-spec")] // todo: v1.2
|
||||
fn serialize_auth_data_registration_token() {
|
||||
let auth_data = AuthData::RegistrationToken(
|
||||
assign!(uiaa::RegistrationToken::new("mytoken"), { session: Some("session") }),
|
||||
@ -74,7 +74,7 @@ fn serialize_auth_data_registration_token() {
|
||||
assert_matches!(
|
||||
to_json_value(auth_data),
|
||||
Ok(val) if val == json!({
|
||||
"type": "org.matrix.msc3231.login.registration_token",
|
||||
"type": "m.login.registration_token",
|
||||
"token": "mytoken",
|
||||
"session": "session",
|
||||
})
|
||||
@ -82,10 +82,10 @@ fn serialize_auth_data_registration_token() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "unstable-pre-spec")]
|
||||
#[cfg(feature = "unstable-spec")] // todo: v1.2
|
||||
fn deserialize_auth_data_registration_token() {
|
||||
let json = json!({
|
||||
"type": "org.matrix.msc3231.login.registration_token",
|
||||
"type": "m.login.registration_token",
|
||||
"token": "mytoken",
|
||||
"session": "session",
|
||||
});
|
||||
|
@ -119,6 +119,9 @@ unstable-pre-spec = [
|
||||
#"ruma-identity-service-api/unstable-pre-spec",
|
||||
#"ruma-push-gateway-api/unstable-pre-spec",
|
||||
]
|
||||
unstable-spec = [
|
||||
"ruma-client-api/unstable-spec"
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
assign = "1.1.1"
|
||||
|
@ -72,7 +72,7 @@ impl CiTask {
|
||||
|
||||
// 2. Run tests
|
||||
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();
|
||||
let events_compat_res =
|
||||
cmd!("rustup run stable cargo test -p ruma-events --features compat compat").run();
|
||||
@ -98,7 +98,7 @@ impl CiTask {
|
||||
let clippy_all_res = cmd!(
|
||||
"
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user