mz_frontegg_client/client/
app_password.rs1use mz_frontegg_auth::AppPassword as AuthAppPassword;
13use reqwest::Method;
14use serde::{Deserialize, Serialize};
15use uuid::Uuid;
16
17use crate::client::Client;
18use crate::error::Error;
19
20const APP_PASSWORDS_PATH: [&str; 6] = [
21 "frontegg",
22 "identity",
23 "resources",
24 "users",
25 "api-tokens",
26 "v1",
27];
28const CREATE_APP_PASSWORDS_PATH: [&str; 6] = [
29 "frontegg",
30 "identity",
31 "resources",
32 "users",
33 "api-tokens",
34 "v1",
35];
36
37#[derive(Deserialize)]
39#[serde(rename_all = "camelCase")]
40pub struct AppPassword {
41 pub description: String,
45 pub created_at: String,
49}
50
51#[derive(Serialize)]
53pub struct CreateAppPasswordRequest<'a> {
54 pub description: &'a str,
56}
57
58impl Client {
59 pub async fn list_app_passwords(&self) -> Result<Vec<AppPassword>, Error> {
61 let req = self.build_request(Method::GET, APP_PASSWORDS_PATH);
62 let passwords: Vec<AppPassword> = self.send_request(req).await?;
63 Ok(passwords)
64 }
65
66 pub async fn create_app_password(
68 &self,
69 app_password: CreateAppPasswordRequest<'_>,
70 ) -> Result<AuthAppPassword, Error> {
71 let req = self.build_request(Method::POST, CREATE_APP_PASSWORDS_PATH);
72 let req = req.json(&app_password);
73
74 #[derive(Debug, Deserialize)]
77 struct AppPassword {
78 #[serde(rename = "clientId")]
80 client_id: Uuid,
81 #[serde(rename = "secret")]
83 secret_key: Uuid,
84 }
85
86 let password: AppPassword = self.send_request(req).await?;
87 Ok(AuthAppPassword {
88 client_id: password.client_id,
89 secret_key: password.secret_key,
90 })
91 }
92}