|
|
|
@ -302,7 +302,7 @@ impl Client {
|
|
|
|
|
|
|
|
|
|
// Holds implementation for Section 5.4, Login
|
|
|
|
|
impl Client { |
|
|
|
|
/// Implementation of [Section 5.4.1 **GET** `/_matrix/client/r0/login`](https://matrix.org/docs/spec/client_server/r0.5.0#get-matrix-client-r0-login).
|
|
|
|
|
/// Implementation of [5.4.1 **GET** `/_matrix/client/r0/login`](https://matrix.org/docs/spec/client_server/r0.5.0#get-matrix-client-r0-login).
|
|
|
|
|
///
|
|
|
|
|
/// This request is rate-limited but does not require authentication.
|
|
|
|
|
pub fn login_flows(&self) -> Result<ValidLoginFlows, Box<dyn Error>> { |
|
|
|
@ -409,6 +409,40 @@ impl Client {
|
|
|
|
|
)? |
|
|
|
|
.json()?) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Implementation of [5.4.3 **POST** `/_matrix/client/r0/logout`](https://matrix.org/docs/spec/client_server/r0.5.0#post-matrix-client-r0-logout)
|
|
|
|
|
///
|
|
|
|
|
/// Invalidates an existing access token as well as the associated device.
|
|
|
|
|
/// The associated device keys are also deleted.
|
|
|
|
|
///
|
|
|
|
|
/// This request is rate-limited but does not require authentication.
|
|
|
|
|
pub fn logout(&self) -> Result<(), Box<dyn Error>> { |
|
|
|
|
self.send( |
|
|
|
|
MatrixHTTPMethod::Post, |
|
|
|
|
"/_matrix/client/r0/logout", |
|
|
|
|
None, |
|
|
|
|
None, |
|
|
|
|
None, |
|
|
|
|
) |
|
|
|
|
.map(|_| ()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Implementation of [5.4.4 **POST** `/_matrix/client/r0/logout/all`](https://matrix.org/docs/spec/client_server/r0.5.0#post-matrix-client-r0-logout)
|
|
|
|
|
///
|
|
|
|
|
/// Invalidates all access tokens as well as all associated devices.
|
|
|
|
|
/// The associated device keys are also deleted.
|
|
|
|
|
///
|
|
|
|
|
/// This request is rate-limited but does not require authentication.
|
|
|
|
|
pub fn logout_all(&self) -> Result<(), Box<dyn Error>> { |
|
|
|
|
self.send( |
|
|
|
|
MatrixHTTPMethod::Post, |
|
|
|
|
"/_matrix/client/r0/logout/all", |
|
|
|
|
None, |
|
|
|
|
None, |
|
|
|
|
None, |
|
|
|
|
) |
|
|
|
|
.map(|_| ()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[cfg(test)] |
|
|
|
@ -488,7 +522,7 @@ mod tests {
|
|
|
|
|
.json() |
|
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
|
|
assert_eq!(dbg!(resp)["hello"], "world"); |
|
|
|
|
assert_eq!(resp["hello"], "world"); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Override 429 response with valid response after initial request
|
|
|
|
@ -499,7 +533,43 @@ mod tests {
|
|
|
|
|
.with_body(r#"{"hello": "world"}"#) |
|
|
|
|
.create(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn login_resp_can_be_parsed() { |
|
|
|
|
let _mock_version_check = mock("GET", "/_matrix/client/versions") |
|
|
|
|
.with_body(r#"{"versions": ["r0.5.0"]}"#) |
|
|
|
|
.create(); |
|
|
|
|
|
|
|
|
|
let _m = mock("POST", "/_matrix/client/r0/login") |
|
|
|
|
.with_body( |
|
|
|
|
r#"{ |
|
|
|
|
"access_token": "angery", |
|
|
|
|
"device_id": "HENLOWORLD", |
|
|
|
|
"home_server": "eddie.sh", |
|
|
|
|
"user_id": "@eddie:eddie.sh", |
|
|
|
|
"well_known": { |
|
|
|
|
"m.homeserver": { |
|
|
|
|
"base_url": "https://eddie.sh/" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}"#, |
|
|
|
|
) |
|
|
|
|
.create(); |
|
|
|
|
|
|
|
|
|
Client::new("http://dummy.website", None, None, None) |
|
|
|
|
.unwrap() |
|
|
|
|
.login_password( |
|
|
|
|
IdentifierType::User { |
|
|
|
|
user: "hello".to_string(), |
|
|
|
|
}, |
|
|
|
|
"foo", |
|
|
|
|
Some("ABC"), |
|
|
|
|
Some("DEF"), |
|
|
|
|
) |
|
|
|
|
.unwrap(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[derive(Default)] |
|
|
|
|
pub struct ApiError {} |
|
|
|
|
|
|
|
|
|