Borrow strings and identifiers in uiaa::AuthData and dependent endpoints
This commit is contained in:
parent
a842c5ccdc
commit
f210f91611
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
|
||||||
use crate::r0::uiaa::{AuthData, UiaaResponse};
|
use crate::r0::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -29,7 +29,7 @@ ruma_api! {
|
|||||||
pub logout_devices: bool,
|
pub logout_devices: bool,
|
||||||
|
|
||||||
/// Additional authentication information for the user-interactive authentication API.
|
/// Additional authentication information for the user-interactive authentication API.
|
||||||
pub auth: Option<AuthData>,
|
pub auth: Option<AuthData<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
response: {}
|
response: {}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
|
||||||
use crate::r0::uiaa::{AuthData, UiaaResponse};
|
use crate::r0::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
|
||||||
|
|
||||||
use super::ThirdPartyIdRemovalStatus;
|
use super::ThirdPartyIdRemovalStatus;
|
||||||
|
|
||||||
@ -19,12 +19,12 @@ ruma_api! {
|
|||||||
request: {
|
request: {
|
||||||
/// Additional authentication information for the user-interactive authentication API.
|
/// Additional authentication information for the user-interactive authentication API.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub auth: Option<AuthData>,
|
pub auth: Option<AuthData<'a>>,
|
||||||
|
|
||||||
/// Identity server from which to unbind the user's third party
|
/// Identity server from which to unbind the user's third party
|
||||||
/// identifier.
|
/// identifier.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub id_server: Option<String>,
|
pub id_server: Option<&'a str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
response: {
|
response: {
|
||||||
|
@ -4,7 +4,7 @@ use ruma_api::ruma_api;
|
|||||||
use ruma_identifiers::{DeviceId, UserId};
|
use ruma_identifiers::{DeviceId, UserId};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::r0::uiaa::{AuthData, UiaaResponse};
|
use crate::r0::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -22,26 +22,26 @@ ruma_api! {
|
|||||||
/// May be empty for accounts that should not be able to log in again
|
/// May be empty for accounts that should not be able to log in again
|
||||||
/// with a password, e.g., for guest or application service accounts.
|
/// with a password, e.g., for guest or application service accounts.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub password: Option<String>,
|
pub password: Option<&'a str>,
|
||||||
|
|
||||||
/// local part of the desired Matrix ID.
|
/// local part of the desired Matrix ID.
|
||||||
///
|
///
|
||||||
/// If omitted, the homeserver MUST generate a Matrix ID local part.
|
/// If omitted, the homeserver MUST generate a Matrix ID local part.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub username: Option<String>,
|
pub username: Option<&'a str>,
|
||||||
|
|
||||||
/// ID of the client device.
|
/// ID of the client device.
|
||||||
///
|
///
|
||||||
/// If this does not correspond to a known client device, a new device will be created.
|
/// If this does not correspond to a known client device, a new device will be created.
|
||||||
/// The server will auto-generate a device_id if this is not specified.
|
/// The server will auto-generate a device_id if this is not specified.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub device_id: Option<Box<DeviceId>>,
|
pub device_id: Option<&'a DeviceId>,
|
||||||
|
|
||||||
/// A display name to assign to the newly-created device.
|
/// A display name to assign to the newly-created device.
|
||||||
///
|
///
|
||||||
/// Ignored if `device_id` corresponds to a known device.
|
/// Ignored if `device_id` corresponds to a known device.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub initial_device_display_name: Option<String>,
|
pub initial_device_display_name: Option<&'a str>,
|
||||||
|
|
||||||
/// Additional authentication information for the user-interactive authentication API.
|
/// Additional authentication information for the user-interactive authentication API.
|
||||||
///
|
///
|
||||||
@ -50,7 +50,7 @@ ruma_api! {
|
|||||||
/// It should be left empty, or omitted, unless an earlier call returned an response
|
/// It should be left empty, or omitted, unless an earlier call returned an response
|
||||||
/// with status code 401.
|
/// with status code 401.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub auth: Option<AuthData>,
|
pub auth: Option<AuthData<'a>>,
|
||||||
|
|
||||||
/// Kind of account to register
|
/// Kind of account to register
|
||||||
///
|
///
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_identifiers::DeviceId;
|
use ruma_identifiers::DeviceId;
|
||||||
|
|
||||||
use crate::r0::uiaa::{AuthData, UiaaResponse};
|
use crate::r0::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -18,11 +18,11 @@ ruma_api! {
|
|||||||
request: {
|
request: {
|
||||||
/// The device to delete.
|
/// The device to delete.
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
pub device_id: Box<DeviceId>,
|
pub device_id: &'a DeviceId,
|
||||||
|
|
||||||
/// Additional authentication information for the user-interactive authentication API.
|
/// Additional authentication information for the user-interactive authentication API.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub auth: Option<AuthData>,
|
pub auth: Option<AuthData<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
response: {}
|
response: {}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_identifiers::DeviceId;
|
use ruma_identifiers::DeviceId;
|
||||||
|
|
||||||
use crate::r0::uiaa::{AuthData, UiaaResponse};
|
use crate::r0::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -17,11 +17,11 @@ ruma_api! {
|
|||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// List of devices to delete.
|
/// List of devices to delete.
|
||||||
pub devices: Vec<Box<DeviceId>>,
|
pub devices: &'a [Box<DeviceId>],
|
||||||
|
|
||||||
/// Additional authentication information for the user-interactive authentication API.
|
/// Additional authentication information for the user-interactive authentication API.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub auth: Option<AuthData>,
|
pub auth: Option<AuthData<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
response: {}
|
response: {}
|
||||||
|
@ -5,7 +5,7 @@ use std::{
|
|||||||
fmt::{self, Display, Formatter},
|
fmt::{self, Display, Formatter},
|
||||||
};
|
};
|
||||||
|
|
||||||
use ruma_api::{error::ResponseDeserializationError, EndpointError};
|
use ruma_api::{error::ResponseDeserializationError, EndpointError, Outgoing};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::{
|
use serde_json::{
|
||||||
from_slice as from_json_slice, to_vec as to_json_vec, value::RawValue as RawJsonValue,
|
from_slice as from_json_slice, to_vec as to_json_vec, value::RawValue as RawJsonValue,
|
||||||
@ -15,19 +15,19 @@ use serde_json::{
|
|||||||
use crate::error::{Error as MatrixError, ErrorBody};
|
use crate::error::{Error as MatrixError, ErrorBody};
|
||||||
|
|
||||||
/// Additional authentication information for the user-interactive authentication API.
|
/// Additional authentication information for the user-interactive authentication API.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Outgoing, Serialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum AuthData {
|
pub enum AuthData<'a> {
|
||||||
/// Used for sending UIAA authentication requests to the homeserver directly
|
/// Used for sending UIAA authentication requests to the homeserver directly
|
||||||
/// from the client.
|
/// from the client.
|
||||||
DirectRequest {
|
DirectRequest {
|
||||||
/// The login type that the client is attempting to complete.
|
/// The login type that the client is attempting to complete.
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
kind: String,
|
kind: &'a str,
|
||||||
|
|
||||||
/// The value of the session key given by the homeserver.
|
/// The value of the session key given by the homeserver.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
session: Option<String>,
|
session: Option<&'a str>,
|
||||||
|
|
||||||
/// Parameters submitted for a particular authentication stage.
|
/// Parameters submitted for a particular authentication stage.
|
||||||
// FIXME: RawJsonValue doesn't work here, is that a bug?
|
// FIXME: RawJsonValue doesn't work here, is that a bug?
|
||||||
@ -39,7 +39,7 @@ pub enum AuthData {
|
|||||||
/// stage through the fallback method.
|
/// stage through the fallback method.
|
||||||
FallbackAcknowledgement {
|
FallbackAcknowledgement {
|
||||||
/// The value of the session key given by the homeserver.
|
/// The value of the session key given by the homeserver.
|
||||||
session: String,
|
session: &'a str,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,14 +145,14 @@ mod tests {
|
|||||||
Value as JsonValue,
|
Value as JsonValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{AuthData, AuthFlow, UiaaInfo, UiaaResponse};
|
use super::{AuthData, AuthFlow, IncomingAuthData, UiaaInfo, UiaaResponse};
|
||||||
use crate::error::{ErrorBody, ErrorKind};
|
use crate::error::{ErrorBody, ErrorKind};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serialize_authentication_data_direct_request() {
|
fn test_serialize_authentication_data_direct_request() {
|
||||||
let authentication_data = AuthData::DirectRequest {
|
let authentication_data = AuthData::DirectRequest {
|
||||||
kind: "example.type.foo".into(),
|
kind: "example.type.foo",
|
||||||
session: Some("ZXY000".into()),
|
session: Some("ZXY000"),
|
||||||
auth_parameters: btreemap! {
|
auth_parameters: btreemap! {
|
||||||
"example_credential".to_owned() => json!("verypoorsharedsecret")
|
"example_credential".to_owned() => json!("verypoorsharedsecret")
|
||||||
},
|
},
|
||||||
@ -177,8 +177,8 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AuthData>(json).unwrap(),
|
from_json_value(json).unwrap(),
|
||||||
AuthData::DirectRequest { kind, session: Some(session), auth_parameters }
|
IncomingAuthData::DirectRequest { kind, session: Some(session), auth_parameters }
|
||||||
if kind == "example.type.foo"
|
if kind == "example.type.foo"
|
||||||
&& session == "opaque_session_id"
|
&& session == "opaque_session_id"
|
||||||
&& auth_parameters == btreemap!{
|
&& auth_parameters == btreemap!{
|
||||||
@ -189,7 +189,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serialize_authentication_data_fallback() {
|
fn test_serialize_authentication_data_fallback() {
|
||||||
let authentication_data = AuthData::FallbackAcknowledgement { session: "ZXY000".into() };
|
let authentication_data = AuthData::FallbackAcknowledgement { session: "ZXY000" };
|
||||||
|
|
||||||
assert_eq!(json!({ "session": "ZXY000" }), to_json_value(authentication_data).unwrap());
|
assert_eq!(json!({ "session": "ZXY000" }), to_json_value(authentication_data).unwrap());
|
||||||
}
|
}
|
||||||
@ -199,8 +199,8 @@ mod tests {
|
|||||||
let json = json!({ "session": "opaque_session_id" });
|
let json = json!({ "session": "opaque_session_id" });
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
from_json_value::<AuthData>(json).unwrap(),
|
from_json_value(json).unwrap(),
|
||||||
AuthData::FallbackAcknowledgement { session }
|
IncomingAuthData::FallbackAcknowledgement { session }
|
||||||
if session == "opaque_session_id"
|
if session == "opaque_session_id"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -282,8 +282,8 @@ where
|
|||||||
/// omitted from this request, the server will generate one.
|
/// omitted from this request, the server will generate one.
|
||||||
pub async fn register_user(
|
pub async fn register_user(
|
||||||
&self,
|
&self,
|
||||||
username: Option<String>,
|
username: Option<&str>,
|
||||||
password: String,
|
password: &str,
|
||||||
) -> Result<Session, Error<ruma_client_api::r0::uiaa::UiaaResponse>> {
|
) -> Result<Session, Error<ruma_client_api::r0::uiaa::UiaaResponse>> {
|
||||||
use ruma_client_api::r0::account::register;
|
use ruma_client_api::r0::account::register;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user