rive_http/authentication/
mfa.rs1use rive_models::{
2 data::{CreateMFATicketData, EnableTOTP2FAData},
3 mfa::{MFAMethod, MFARecoveryCode, MFAStatus, MFATicket, TOTPSecret},
4};
5
6use crate::prelude::*;
7
8impl Client {
9 pub async fn create_mfa_ticket(&self, data: CreateMFATicketData) -> Result<MFATicket> {
11 Ok(self
12 .client
13 .put(ep!(self, "/auth/mfa/ticket"))
14 .auth(&self.authentication)
15 .json(&data)
16 .send()
17 .await?
18 .process_error()
19 .await?
20 .json()
21 .await?)
22 }
23
24 pub async fn fetch_mfa_status(&self) -> Result<MFAStatus> {
26 Ok(self
27 .client
28 .get(ep!(self, "/auth/mfa/"))
29 .auth(&self.authentication)
30 .send()
31 .await?
32 .process_error()
33 .await?
34 .json()
35 .await?)
36 }
37
38 pub async fn fetch_recovery_codes(&self) -> Result<Vec<MFARecoveryCode>> {
40 Ok(self
41 .client
42 .post(ep!(self, "/auth/mfa/recovery"))
43 .auth(&self.authentication)
44 .send()
45 .await?
46 .process_error()
47 .await?
48 .json()
49 .await?)
50 }
51
52 pub async fn generate_recovery_codes(&self) -> Result<Vec<MFARecoveryCode>> {
54 Ok(self
55 .client
56 .patch(ep!(self, "/auth/mfa/recovery"))
57 .auth(&self.authentication)
58 .send()
59 .await?
60 .process_error()
61 .await?
62 .json()
63 .await?)
64 }
65
66 pub async fn get_mfa_methods(&self) -> Result<Vec<MFAMethod>> {
68 Ok(self
69 .client
70 .get(ep!(self, "/auth/mfa/methods"))
71 .auth(&self.authentication)
72 .send()
73 .await?
74 .process_error()
75 .await?
76 .json()
77 .await?)
78 }
79
80 pub async fn enable_totp_2fa(&self, data: EnableTOTP2FAData) -> Result<()> {
82 self.client
83 .put(ep!(self, "/auth/mfa/totp"))
84 .json(&data)
85 .auth(&self.authentication)
86 .send()
87 .await?
88 .process_error()
89 .await?;
90 Ok(())
91 }
92
93 pub async fn generate_totp_secret(&self) -> Result<TOTPSecret> {
95 Ok(self
96 .client
97 .post(ep!(self, "/auth/mfa/totp"))
98 .auth(&self.authentication)
99 .send()
100 .await?
101 .process_error()
102 .await?
103 .json()
104 .await?)
105 }
106
107 pub async fn disable_totp_2fa(&self) -> Result<()> {
109 self.client
110 .delete(ep!(self, "/auth/mfa/totp"))
111 .auth(&self.authentication)
112 .send()
113 .await?
114 .process_error()
115 .await?;
116 Ok(())
117 }
118}