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/latest/client-server-api/#post_matrixclientv3logoutall
9
10    use ruma_common::{
11        api::{auth_scheme::AccessToken, response, Metadata},
12        metadata,
13    };
14
15    metadata! {
16        method: POST,
17        rate_limited: false,
18        authentication: AccessToken,
19        history: {
20            1.0 => "/_matrix/client/r0/logout/all",
21            1.1 => "/_matrix/client/v3/logout/all",
22        }
23    }
24
25    /// Request type for the `logout_all` endpoint.
26    #[derive(Debug, Clone, Default)]
27    #[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
28    pub struct Request {}
29
30    impl Request {
31        /// Creates an empty `Request`.
32        pub fn new() -> Self {
33            Self {}
34        }
35    }
36
37    #[cfg(feature = "client")]
38    impl ruma_common::api::OutgoingRequest for Request {
39        type EndpointError = crate::Error;
40        type IncomingResponse = Response;
41
42        fn try_into_http_request<T: Default + bytes::BufMut + AsRef<[u8]>>(
43            self,
44            base_url: &str,
45            access_token: ruma_common::api::auth_scheme::SendAccessToken<'_>,
46            considering: std::borrow::Cow<'_, ruma_common::api::SupportedVersions>,
47        ) -> Result<http::Request<T>, ruma_common::api::error::IntoHttpError> {
48            use ruma_common::api::auth_scheme::AuthScheme;
49
50            let url = Self::make_endpoint_url(considering, base_url, &[], "")?;
51
52            let mut http_request =
53                http::Request::builder().method(Self::METHOD).uri(url).body(T::default())?;
54
55            Self::Authentication::add_authentication(&mut http_request, access_token).map_err(
56                |error| ruma_common::api::error::IntoHttpError::Authentication(error.into()),
57            )?;
58
59            Ok(http_request)
60        }
61    }
62
63    #[cfg(feature = "server")]
64    impl ruma_common::api::IncomingRequest for Request {
65        type EndpointError = crate::Error;
66        type OutgoingResponse = Response;
67
68        fn try_from_http_request<B, S>(
69            request: http::Request<B>,
70            _path_args: &[S],
71        ) -> Result<Self, ruma_common::api::error::FromHttpRequestError>
72        where
73            B: AsRef<[u8]>,
74            S: AsRef<str>,
75        {
76            Self::check_request_method(request.method())?;
77
78            Ok(Self {})
79        }
80    }
81
82    /// Response type for the `logout_all` endpoint.
83    #[response(error = crate::Error)]
84    #[derive(Default)]
85    pub struct Response {}
86
87    impl Response {
88        /// Creates an empty `Response`.
89        pub fn new() -> Self {
90            Self {}
91        }
92    }
93}