Skip to main content

ruma_client_api/session/
logout_all.rs

1//! `POST /_matrix/client/*/logout/all`
2//!
3//! Invalidates all access tokens for a user, so that they can no longer be used for authorization.
4
5pub mod v3 {
6    //! `/v3/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/v1.19/client-server-api/#post_matrixclientv3logoutall
9
10    #[cfg(feature = "client")]
11    use ruma_common::api::EmptyBody;
12    use ruma_common::{
13        api::{auth_scheme::AccessToken, error::Error, response},
14        metadata,
15    };
16
17    metadata! {
18        method: POST,
19        rate_limited: false,
20        authentication: AccessToken,
21        history: {
22            1.0 => "/_matrix/client/r0/logout/all",
23            1.1 => "/_matrix/client/v3/logout/all",
24        }
25    }
26
27    /// Request type for the `logout_all` endpoint.
28    #[derive(Debug, Clone, Default)]
29    #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
30    pub struct Request {}
31
32    impl Request {
33        /// Creates an empty `Request`.
34        pub fn new() -> Self {
35            Self {}
36        }
37    }
38
39    #[cfg(feature = "client")]
40    impl ruma_common::api::OutgoingRequest for Request {
41        type Body = EmptyBody;
42        type EndpointError = Error;
43        type IncomingResponse = Response;
44
45        fn try_into_http_request_inner(
46            self,
47            base_url: &str,
48            considering: std::borrow::Cow<'_, ruma_common::api::SupportedVersions>,
49        ) -> Result<http::Request<EmptyBody>, ruma_common::api::error::IntoHttpError> {
50            use ruma_common::api::Metadata;
51
52            let url = Self::make_endpoint_url(considering, base_url, &[], "")?;
53
54            let http_request =
55                http::Request::builder().method(Self::METHOD).uri(url).body(EmptyBody)?;
56
57            Ok(http_request)
58        }
59    }
60
61    #[cfg(feature = "server")]
62    impl ruma_common::api::IncomingRequest for Request {
63        type EndpointError = Error;
64        type OutgoingResponse = Response;
65
66        fn try_from_http_request<B, S>(
67            request: http::Request<B>,
68            _path_args: &[S],
69        ) -> Result<Self, ruma_common::api::error::FromHttpRequestError>
70        where
71            B: AsRef<[u8]>,
72            S: AsRef<str>,
73        {
74            Self::check_request_method(request.method())?;
75
76            Ok(Self {})
77        }
78    }
79
80    /// Response type for the `logout_all` endpoint.
81    #[response]
82    #[derive(Default)]
83    pub struct Response {}
84
85    impl Response {
86        /// Creates an empty `Response`.
87        pub fn new() -> Self {
88            Self {}
89        }
90    }
91}