rive_http/authentication/
session.rs1use crate::prelude::*;
2use rive_models::{
3 data::{DeleteAllSessionsData, EditSessionData, LoginData},
4 session::{LoginResponse, SessionInfo},
5};
6
7impl Client {
8 pub async fn login(&self, data: LoginData) -> Result<LoginResponse> {
10 Ok(self
11 .client
12 .post(ep!(self, "/auth/session/login"))
13 .json(&data)
14 .send()
15 .await?
16 .process_error()
17 .await?
18 .json()
19 .await?)
20 }
21
22 pub async fn logout(&self) -> Result<()> {
24 self.client
25 .post(ep!(self, "/auth/session/logout"))
26 .auth(&self.authentication)
27 .send()
28 .await?
29 .process_error()
30 .await?;
31 Ok(())
32 }
33
34 pub async fn fetch_sessions(&self) -> Result<Vec<SessionInfo>> {
36 Ok(self
37 .client
38 .get(ep!(self, "/auth/session/all"))
39 .auth(&self.authentication)
40 .send()
41 .await?
42 .process_error()
43 .await?
44 .json()
45 .await?)
46 }
47
48 pub async fn delete_all_sessions(&self, data: DeleteAllSessionsData) -> Result<()> {
50 self.client
51 .delete(ep!(self, "/auth/session/all"))
52 .json(&data)
53 .auth(&self.authentication)
54 .send()
55 .await?
56 .process_error()
57 .await?;
58 Ok(())
59 }
60
61 pub async fn revoke_session(&self, id: impl Into<String>) -> Result<()> {
63 self.client
64 .delete(ep!(self, "/auth/session/{}", id.into()))
65 .auth(&self.authentication)
66 .send()
67 .await?
68 .process_error()
69 .await?;
70 Ok(())
71 }
72
73 pub async fn edit_session(
75 &self,
76 id: impl Into<String>,
77 data: EditSessionData,
78 ) -> Result<SessionInfo> {
79 Ok(self
80 .client
81 .patch(ep!(self, "/auth/session/{}", id.into()))
82 .json(&data)
83 .auth(&self.authentication)
84 .send()
85 .await?
86 .process_error()
87 .await?
88 .json()
89 .await?)
90 }
91}