rp_supabase_auth/auth_client/
requests.rs

1use reqwest::Method;
2use serde::{Deserialize, Serialize};
3use url::Url;
4
5use crate::error::AuthError;
6use crate::types;
7
8pub trait AuthModuleRequest {
9    /// The successful result type to be returned
10    type Res: serde::de::DeserializeOwned + core::fmt::Debug;
11    /// The error type to be returned on invalid data
12    type Error: serde::de::DeserializeOwned;
13    /// The payload that we will send as JSON during the request body
14    type Payload: serde::Serialize;
15
16    /// The HTTP method to use
17    const METHOD: reqwest::Method;
18
19    /// Returns the path for the request.
20    ///
21    /// # Errors
22    ///
23    /// Returns an error if the URL cannot be joined or is invalid.
24    fn path(&self, base_url: &Url) -> Result<Url, AuthError>;
25    /// The payload to send in the request body
26    fn payload(&self) -> &Self::Payload;
27}
28
29/// Health Check Request
30#[derive(Debug, Clone)]
31pub struct HealthCheckRequest;
32
33impl AuthModuleRequest for HealthCheckRequest {
34    type Res = String;
35    type Error = types::ErrorSchema;
36    type Payload = ();
37
38    const METHOD: Method = Method::GET;
39
40    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
41        base_url.join("health").map_err(AuthError::from)
42    }
43
44    fn payload(&self) -> &Self::Payload {
45        &()
46    }
47}
48
49#[derive(Debug, Serialize, Deserialize, Clone)]
50#[serde(rename_all = "snake_case")]
51pub enum GrantType {
52    Password,
53    RefreshToken,
54    IdToken,
55    Pkce,
56}
57
58/// Token Request
59#[derive(Debug, Clone, typed_builder::TypedBuilder)]
60pub struct TokenRequest {
61    pub grant_type: GrantType,
62    pub payload: types::TokenRequestBody,
63}
64
65impl AuthModuleRequest for TokenRequest {
66    type Res = types::AccessTokenResponseSchema;
67    type Error = types::ErrorSchema;
68    type Payload = types::TokenRequestBody;
69
70    const METHOD: Method = Method::POST;
71
72    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
73        let mut url = base_url.join("token").map_err(AuthError::from)?;
74        let grant_type = match self.grant_type {
75            GrantType::Password => "password",
76            GrantType::RefreshToken => "refresh_token",
77            GrantType::IdToken => "id_token",
78            GrantType::Pkce => "pkce",
79        };
80        url.query_pairs_mut().append_pair("grant_type", grant_type);
81        Ok(url)
82    }
83
84    fn payload(&self) -> &Self::Payload {
85        &self.payload
86    }
87}
88
89/// Logout Request
90#[derive(Debug, Clone, typed_builder::TypedBuilder)]
91pub struct LogoutRequest {
92    pub scope: Option<String>,
93}
94
95impl AuthModuleRequest for LogoutRequest {
96    type Res = ();
97    type Error = types::ErrorSchema;
98    type Payload = ();
99
100    const METHOD: Method = Method::POST;
101
102    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
103        let mut url = base_url.join("logout").map_err(AuthError::from)?;
104        if let Some(ref scope) = self.scope {
105            url.query_pairs_mut().append_pair("scope", scope);
106        }
107        Ok(url)
108    }
109
110    fn payload(&self) -> &Self::Payload {
111        &()
112    }
113}
114
115/// Verify GET Request
116#[derive(Debug, Clone, typed_builder::TypedBuilder)]
117pub struct VerifyGetRequest {
118    pub token: String,
119    pub verification_type: String,
120    pub redirect_to: Option<String>,
121}
122
123impl AuthModuleRequest for VerifyGetRequest {
124    type Res = ();
125    type Error = types::ErrorSchema;
126    type Payload = ();
127
128    const METHOD: Method = Method::GET;
129
130    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
131        let mut url = base_url.join("verify").map_err(AuthError::from)?;
132        url.query_pairs_mut()
133            .append_pair("token", &self.token)
134            .append_pair("type", &self.verification_type);
135        if let Some(ref redirect_to) = self.redirect_to {
136            url.query_pairs_mut()
137                .append_pair("redirect_to", redirect_to);
138        }
139        Ok(url)
140    }
141
142    fn payload(&self) -> &Self::Payload {
143        &()
144    }
145}
146
147/// Verify POST Request
148#[derive(Debug, Clone, Serialize, typed_builder::TypedBuilder)]
149pub struct VerifyPostRequest {
150    #[serde(rename = "type")]
151    pub verification_type: String,
152    pub token: Option<String>,
153    pub token_hash: Option<String>,
154    pub email: Option<String>,
155    pub phone: Option<String>,
156    pub redirect_to: Option<String>,
157    pub gotrue_meta_security: Option<types::GoTrueMetaSecurity>,
158}
159
160impl AuthModuleRequest for VerifyPostRequest {
161    type Res = types::AccessTokenResponseSchema;
162    type Error = types::ErrorSchema;
163    type Payload = Self;
164
165    const METHOD: Method = Method::POST;
166
167    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
168        base_url.join("verify").map_err(AuthError::from)
169    }
170
171    fn payload(&self) -> &Self::Payload {
172        self
173    }
174}
175
176/// Authorize Request
177#[derive(Debug, Clone, typed_builder::TypedBuilder)]
178pub struct AuthorizeRequest {
179    pub provider: String,
180    pub scopes: String,
181    pub invite_token: Option<String>,
182    pub redirect_to: Option<String>,
183    pub code_challenge_method: Option<String>,
184}
185
186impl AuthModuleRequest for AuthorizeRequest {
187    type Res = ();
188    type Error = types::ErrorSchema;
189    type Payload = ();
190
191    const METHOD: Method = Method::GET;
192
193    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
194        let mut url = base_url.join("authorize").map_err(AuthError::from)?;
195        url.query_pairs_mut()
196            .append_pair("provider", &self.provider)
197            .append_pair("scopes", &self.scopes);
198        if let Some(ref invite_token) = self.invite_token {
199            url.query_pairs_mut()
200                .append_pair("invite_token", invite_token);
201        }
202        if let Some(ref redirect_to) = self.redirect_to {
203            url.query_pairs_mut()
204                .append_pair("redirect_to", redirect_to);
205        }
206        if let Some(ref code_challenge_method) = self.code_challenge_method {
207            url.query_pairs_mut()
208                .append_pair("code_challenge_method", code_challenge_method);
209        }
210        Ok(url)
211    }
212
213    fn payload(&self) -> &Self::Payload {
214        &()
215    }
216}
217
218/// Signup Request
219#[derive(Debug, Clone, Serialize, typed_builder::TypedBuilder)]
220pub struct SignupRequest {
221    pub payload: types::SignupPayload,
222}
223
224impl AuthModuleRequest for SignupRequest {
225    type Res = types::SignupResponse; // Could be AccessTokenResponseSchema or UserSchema
226    type Error = types::ErrorSchema;
227    type Payload = types::SignupPayload;
228
229    const METHOD: Method = Method::POST;
230
231    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
232        base_url.join("signup").map_err(AuthError::from)
233    }
234
235    fn payload(&self) -> &Self::Payload {
236        &self.payload
237    }
238}
239
240/// Recover Request
241#[derive(Debug, Clone, Serialize, typed_builder::TypedBuilder)]
242pub struct RecoverRequest {
243    pub email: String,
244    pub code_challenge: Option<String>,
245    pub code_challenge_method: Option<String>,
246    pub gotrue_meta_security: Option<types::GoTrueMetaSecurity>,
247}
248
249impl AuthModuleRequest for RecoverRequest {
250    type Res = ();
251    type Error = types::ErrorSchema;
252    type Payload = Self;
253
254    const METHOD: Method = Method::POST;
255
256    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
257        base_url.join("recover").map_err(AuthError::from)
258    }
259
260    fn payload(&self) -> &Self::Payload {
261        self
262    }
263}
264
265/// Resend Request
266#[derive(Debug, Clone, Serialize, typed_builder::TypedBuilder)]
267pub struct ResendRequest {
268    pub email: Option<String>,
269    pub phone: Option<String>,
270    #[serde(rename = "type")]
271    pub resend_type: String,
272    pub gotrue_meta_security: Option<types::GoTrueMetaSecurity>,
273}
274
275impl AuthModuleRequest for ResendRequest {
276    type Res = types::ResendResponse;
277    type Error = types::ErrorSchema;
278    type Payload = Self;
279
280    const METHOD: Method = Method::POST;
281
282    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
283        base_url.join("resend").map_err(AuthError::from)
284    }
285
286    fn payload(&self) -> &Self::Payload {
287        self
288    }
289}
290
291/// Magic Link Request
292#[derive(Debug, Clone, Serialize, typed_builder::TypedBuilder)]
293pub struct MagicLinkRequest {
294    pub email: String,
295    pub data: Option<types::UserMetadata>,
296    pub gotrue_meta_security: Option<types::GoTrueMetaSecurity>,
297}
298
299impl AuthModuleRequest for MagicLinkRequest {
300    type Res = ();
301    type Error = types::ErrorSchema;
302    type Payload = Self;
303
304    const METHOD: Method = Method::POST;
305
306    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
307        base_url.join("magiclink").map_err(AuthError::from)
308    }
309
310    fn payload(&self) -> &Self::Payload {
311        self
312    }
313}
314
315/// OTP Request
316#[derive(Debug, Clone, Serialize, typed_builder::TypedBuilder)]
317pub struct OtpRequest {
318    pub email: Option<String>,
319    pub phone: Option<String>,
320    pub channel: Option<String>,
321    pub create_user: Option<bool>,
322    pub data: Option<types::UserMetadata>,
323    pub code_challenge_method: Option<String>,
324    pub code_challenge: Option<String>,
325    pub gotrue_meta_security: Option<types::GoTrueMetaSecurity>,
326}
327
328impl AuthModuleRequest for OtpRequest {
329    type Res = types::OtpResponse;
330    type Error = types::ErrorSchema;
331    type Payload = Self;
332
333    const METHOD: Method = Method::POST;
334
335    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
336        base_url.join("otp").map_err(AuthError::from)
337    }
338
339    fn payload(&self) -> &Self::Payload {
340        self
341    }
342}
343
344/// User GET Request
345#[derive(Debug, Clone)]
346pub struct UserGetRequest;
347
348impl AuthModuleRequest for UserGetRequest {
349    type Res = types::UserSchema;
350    type Error = types::ErrorSchema;
351    type Payload = ();
352
353    const METHOD: Method = Method::GET;
354
355    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
356        base_url.join("user").map_err(AuthError::from)
357    }
358
359    fn payload(&self) -> &Self::Payload {
360        &()
361    }
362}
363
364/// User PUT Request
365#[derive(Debug, Clone, Serialize, typed_builder::TypedBuilder)]
366pub struct UserUpdateRequest {
367    pub email: Option<String>,
368    pub phone: Option<String>,
369    pub password: Option<String>,
370    pub nonce: Option<String>,
371    pub data: Option<types::UserMetadata>,
372    pub app_metadata: Option<types::AppMetadata>,
373    pub channel: Option<String>,
374}
375
376impl AuthModuleRequest for UserUpdateRequest {
377    type Res = types::UserSchema;
378    type Error = types::ErrorSchema;
379    type Payload = Self;
380
381    const METHOD: Method = Method::PUT;
382
383    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
384        base_url.join("user").map_err(AuthError::from)
385    }
386
387    fn payload(&self) -> &Self::Payload {
388        self
389    }
390}
391
392/// Reauthenticate Request
393#[derive(Debug, Clone)]
394pub struct ReauthenticateRequest;
395
396impl AuthModuleRequest for ReauthenticateRequest {
397    type Res = ();
398    type Error = types::ErrorSchema;
399    type Payload = ();
400
401    const METHOD: Method = Method::POST;
402
403    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
404        base_url.join("reauthenticate").map_err(AuthError::from)
405    }
406
407    fn payload(&self) -> &Self::Payload {
408        &()
409    }
410}
411
412/// Factors Request
413#[derive(Debug, Clone, Serialize, typed_builder::TypedBuilder)]
414pub struct FactorsRequest {
415    pub factor_type: String,
416    pub friendly_name: Option<String>,
417    pub issuer: Option<String>,
418    pub phone: Option<String>,
419}
420
421impl AuthModuleRequest for FactorsRequest {
422    type Res = types::FactorsResponse;
423    type Error = types::ErrorSchema;
424    type Payload = Self;
425
426    const METHOD: Method = Method::POST;
427
428    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
429        base_url.join("factors").map_err(AuthError::from)
430    }
431
432    fn payload(&self) -> &Self::Payload {
433        self
434    }
435}
436
437/// Factors Challenge Request
438#[derive(Debug, Clone, Serialize, typed_builder::TypedBuilder)]
439pub struct FactorsChallengeRequest {
440    pub factor_id: String,
441    pub channel: Option<String>,
442}
443
444impl AuthModuleRequest for FactorsChallengeRequest {
445    type Res = types::ChallengeResponse;
446    type Error = types::ErrorSchema;
447    type Payload = Self;
448
449    const METHOD: Method = Method::POST;
450
451    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
452        let endpoint = format!("factors/{}/challenge", self.factor_id);
453        base_url.join(&endpoint).map_err(AuthError::from)
454    }
455
456    fn payload(&self) -> &Self::Payload {
457        self
458    }
459}
460
461/// Factors Verify Request
462#[derive(Debug, Clone, Serialize, typed_builder::TypedBuilder)]
463pub struct FactorsVerifyRequest {
464    pub factor_id: String,
465    pub challenge_id: String,
466    pub code: String,
467}
468
469impl AuthModuleRequest for FactorsVerifyRequest {
470    type Res = types::AccessTokenResponseSchema;
471    type Error = types::ErrorSchema;
472    type Payload = Self;
473
474    const METHOD: Method = Method::POST;
475
476    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
477        let endpoint = format!("factors/{}/verify", self.factor_id);
478        base_url.join(&endpoint).map_err(AuthError::from)
479    }
480
481    fn payload(&self) -> &Self::Payload {
482        self
483    }
484}
485
486/// Factors Delete Request
487#[derive(Debug, Clone, typed_builder::TypedBuilder)]
488pub struct FactorsDeleteRequest {
489    pub factor_id: String,
490}
491
492impl AuthModuleRequest for FactorsDeleteRequest {
493    type Res = types::FactorDeleteResponse;
494    type Error = types::ErrorSchema;
495    type Payload = ();
496
497    const METHOD: Method = Method::DELETE;
498
499    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
500        let endpoint = format!("factors/{}", self.factor_id);
501        base_url.join(&endpoint).map_err(AuthError::from)
502    }
503
504    fn payload(&self) -> &Self::Payload {
505        &()
506    }
507}
508
509/// Callback GET Request
510#[derive(Debug, Clone)]
511pub struct CallbackGetRequest;
512
513impl AuthModuleRequest for CallbackGetRequest {
514    type Res = ();
515    type Error = types::ErrorSchema;
516    type Payload = ();
517
518    const METHOD: Method = Method::GET;
519
520    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
521        base_url.join("callback").map_err(AuthError::from)
522    }
523
524    fn payload(&self) -> &Self::Payload {
525        &()
526    }
527}
528
529/// Callback POST Request
530#[derive(Debug, Clone)]
531pub struct CallbackPostRequest;
532
533impl AuthModuleRequest for CallbackPostRequest {
534    type Res = ();
535    type Error = types::ErrorSchema;
536    type Payload = ();
537
538    const METHOD: Method = Method::POST;
539
540    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
541        base_url.join("callback").map_err(AuthError::from)
542    }
543
544    fn payload(&self) -> &Self::Payload {
545        &()
546    }
547}
548
549/// SSO Request
550#[derive(Debug, Clone, Serialize, typed_builder::TypedBuilder)]
551pub struct SsoRequest {
552    pub domain: Option<String>,
553    pub provider_id: Option<String>,
554    pub redirect_to: Option<String>,
555    pub skip_http_redirect: Option<bool>,
556    pub code_challenge: Option<String>,
557    pub code_challenge_method: Option<String>,
558    pub gotrue_meta_security: Option<types::GoTrueMetaSecurity>,
559}
560
561impl AuthModuleRequest for SsoRequest {
562    type Res = types::SsoResponse;
563    type Error = types::ErrorSchema;
564    type Payload = Self;
565
566    const METHOD: Method = Method::POST;
567
568    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
569        base_url.join("sso").map_err(AuthError::from)
570    }
571
572    fn payload(&self) -> &Self::Payload {
573        self
574    }
575}
576
577// Additional requests for other endpoints can be created following the same pattern.
578
579/// SAML Metadata Request
580#[derive(Debug, Clone, typed_builder::TypedBuilder)]
581pub struct SamlMetadataRequest {
582    pub download: Option<bool>,
583}
584
585impl AuthModuleRequest for SamlMetadataRequest {
586    type Res = String; // The response is XML content as a string
587    type Error = types::ErrorSchema;
588    type Payload = ();
589
590    const METHOD: Method = Method::GET;
591
592    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
593        let mut url = base_url.join("saml/metadata").map_err(AuthError::from)?;
594        if let Some(download) = self.download {
595            url.query_pairs_mut()
596                .append_pair("download", &download.to_string());
597        }
598        Ok(url)
599    }
600
601    fn payload(&self) -> &Self::Payload {
602        &()
603    }
604}
605
606/// SAML ACS Request
607#[derive(Debug, Clone, typed_builder::TypedBuilder)]
608pub struct SamlAcsRequest {
609    pub relay_state: Option<String>,
610    pub saml_response: Option<String>,
611    pub saml_art: Option<String>,
612}
613
614impl AuthModuleRequest for SamlAcsRequest {
615    type Res = (); // The response is a redirect
616    type Error = types::ErrorSchema;
617    type Payload = ();
618
619    const METHOD: Method = Method::POST;
620
621    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
622        let mut url = base_url.join("saml/acs").map_err(AuthError::from)?;
623        if let Some(ref relay_state) = self.relay_state {
624            url.query_pairs_mut().append_pair("RelayState", relay_state);
625        }
626        if let Some(ref saml_response) = self.saml_response {
627            url.query_pairs_mut()
628                .append_pair("SAMLResponse", saml_response);
629        }
630        if let Some(ref saml_art) = self.saml_art {
631            url.query_pairs_mut().append_pair("SAMLArt", saml_art);
632        }
633        Ok(url)
634    }
635
636    fn payload(&self) -> &Self::Payload {
637        &()
638    }
639}
640
641/// Invite Request
642#[derive(Debug, Clone, Serialize, typed_builder::TypedBuilder)]
643pub struct InviteRequest {
644    pub email: String,
645    pub data: Option<types::UserMetadata>,
646}
647
648impl AuthModuleRequest for InviteRequest {
649    type Res = types::UserSchema;
650    type Error = types::ErrorSchema;
651    type Payload = Self;
652
653    const METHOD: Method = Method::POST;
654
655    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
656        base_url.join("invite").map_err(AuthError::from)
657    }
658
659    fn payload(&self) -> &Self::Payload {
660        self
661    }
662}
663
664/// Admin Generate Link Request
665#[derive(Debug, Clone, Serialize, typed_builder::TypedBuilder)]
666pub struct AdminGenerateLinkRequest {
667    #[serde(rename = "type")]
668    pub link_type: String,
669    pub email: String,
670    pub new_email: Option<String>,
671    pub password: Option<String>,
672    pub data: Option<types::UserMetadata>,
673    pub redirect_to: Option<String>,
674}
675
676impl AuthModuleRequest for AdminGenerateLinkRequest {
677    type Res = types::AdminGenerateLinkResponse;
678    type Error = types::ErrorSchema;
679    type Payload = Self;
680
681    const METHOD: Method = Method::POST;
682
683    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
684        base_url
685            .join("admin/generate_link")
686            .map_err(AuthError::from)
687    }
688
689    fn payload(&self) -> &Self::Payload {
690        self
691    }
692}
693
694/// Admin Audit Request
695#[derive(Debug, Clone, typed_builder::TypedBuilder)]
696pub struct AdminAuditRequest {
697    pub page: Option<u32>,
698    pub per_page: Option<u32>,
699}
700
701impl AuthModuleRequest for AdminAuditRequest {
702    type Res = Vec<types::AuditLogEntry>;
703    type Error = types::ErrorSchema;
704    type Payload = ();
705
706    const METHOD: Method = Method::GET;
707
708    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
709        let mut url = base_url.join("admin/audit").map_err(AuthError::from)?;
710        if let Some(page) = self.page {
711            url.query_pairs_mut().append_pair("page", &page.to_string());
712        }
713        if let Some(per_page) = self.per_page {
714            url.query_pairs_mut()
715                .append_pair("per_page", &per_page.to_string());
716        }
717        Ok(url)
718    }
719
720    fn payload(&self) -> &Self::Payload {
721        &()
722    }
723}
724
725/// Admin Users Request
726#[derive(Debug, Clone, typed_builder::TypedBuilder)]
727pub struct AdminUsersRequest {
728    pub page: Option<u32>,
729    pub per_page: Option<u32>,
730}
731
732impl AuthModuleRequest for AdminUsersRequest {
733    type Res = types::AdminUsersResponse;
734    type Error = types::ErrorSchema;
735    type Payload = ();
736
737    const METHOD: Method = Method::GET;
738
739    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
740        let mut url = base_url.join("admin/users").map_err(AuthError::from)?;
741        if let Some(page) = self.page {
742            url.query_pairs_mut().append_pair("page", &page.to_string());
743        }
744        if let Some(per_page) = self.per_page {
745            url.query_pairs_mut()
746                .append_pair("per_page", &per_page.to_string());
747        }
748        Ok(url)
749    }
750
751    fn payload(&self) -> &Self::Payload {
752        &()
753    }
754}
755
756/// Admin User Get Request
757#[derive(Debug, Clone, typed_builder::TypedBuilder)]
758pub struct AdminUserGetRequest {
759    pub user_id: String,
760}
761
762impl AuthModuleRequest for AdminUserGetRequest {
763    type Res = types::UserSchema;
764    type Error = types::ErrorSchema;
765    type Payload = ();
766
767    const METHOD: Method = Method::GET;
768
769    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
770        let endpoint = format!("admin/users/{}", self.user_id);
771        base_url.join(&endpoint).map_err(AuthError::from)
772    }
773
774    fn payload(&self) -> &Self::Payload {
775        &()
776    }
777}
778
779/// Admin User Update Request
780#[derive(Debug, Clone, Serialize, typed_builder::TypedBuilder)]
781pub struct AdminUserUpdateRequest {
782    pub user_id: String,
783    pub user: types::UserSchema,
784}
785
786impl AuthModuleRequest for AdminUserUpdateRequest {
787    type Res = types::UserSchema;
788    type Error = types::ErrorSchema;
789    type Payload = types::UserSchema;
790
791    const METHOD: Method = Method::PUT;
792
793    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
794        let endpoint = format!("admin/users/{}", self.user_id);
795        base_url.join(&endpoint).map_err(AuthError::from)
796    }
797
798    fn payload(&self) -> &Self::Payload {
799        &self.user
800    }
801}
802
803/// Admin User Delete Request
804#[derive(Debug, Clone, typed_builder::TypedBuilder)]
805pub struct AdminUserDeleteRequest {
806    pub user_id: String,
807}
808
809impl AuthModuleRequest for AdminUserDeleteRequest {
810    type Res = types::UserSchema;
811    type Error = types::ErrorSchema;
812    type Payload = ();
813
814    const METHOD: Method = Method::DELETE;
815
816    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
817        let endpoint = format!("admin/users/{}", self.user_id);
818        base_url.join(&endpoint).map_err(AuthError::from)
819    }
820
821    fn payload(&self) -> &Self::Payload {
822        &()
823    }
824}
825
826/// Admin User Factors Request
827#[derive(Debug, Clone, typed_builder::TypedBuilder)]
828pub struct AdminUserFactorsRequest {
829    pub user_id: String,
830}
831
832impl AuthModuleRequest for AdminUserFactorsRequest {
833    type Res = Vec<types::MFAFactorSchema>;
834    type Error = types::ErrorSchema;
835    type Payload = ();
836
837    const METHOD: Method = Method::GET;
838
839    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
840        let endpoint = format!("admin/users/{}/factors", self.user_id);
841        base_url.join(&endpoint).map_err(AuthError::from)
842    }
843
844    fn payload(&self) -> &Self::Payload {
845        &()
846    }
847}
848
849/// Admin User Factor Update Request
850#[derive(Debug, Clone, Serialize, typed_builder::TypedBuilder)]
851pub struct AdminUserFactorUpdateRequest {
852    pub user_id: String,
853    pub factor_id: String,
854    pub data: types::MFAFactorUpdateData,
855}
856
857impl AuthModuleRequest for AdminUserFactorUpdateRequest {
858    type Res = types::MFAFactorSchema;
859    type Error = types::ErrorSchema;
860    type Payload = types::MFAFactorUpdateData;
861
862    const METHOD: Method = Method::PUT;
863
864    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
865        let endpoint = format!("admin/users/{}/factors/{}", self.user_id, self.factor_id);
866        base_url.join(&endpoint).map_err(AuthError::from)
867    }
868
869    fn payload(&self) -> &Self::Payload {
870        &self.data
871    }
872}
873
874/// Admin User Factor Delete Request
875#[derive(Debug, Clone, typed_builder::TypedBuilder)]
876pub struct AdminUserFactorDeleteRequest {
877    pub user_id: String,
878    pub factor_id: String,
879}
880
881impl AuthModuleRequest for AdminUserFactorDeleteRequest {
882    type Res = types::MFAFactorSchema;
883    type Error = types::ErrorSchema;
884    type Payload = ();
885
886    const METHOD: Method = Method::DELETE;
887
888    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
889        let endpoint = format!("admin/users/{}/factors/{}", self.user_id, self.factor_id);
890        base_url.join(&endpoint).map_err(AuthError::from)
891    }
892
893    fn payload(&self) -> &Self::Payload {
894        &()
895    }
896}
897
898/// Admin SSO Providers Get Request
899#[derive(Debug, Clone)]
900pub struct AdminSsoProvidersGetRequest;
901
902impl AuthModuleRequest for AdminSsoProvidersGetRequest {
903    type Res = types::SsoProvidersResponse;
904    type Error = types::ErrorSchema;
905    type Payload = ();
906
907    const METHOD: Method = Method::GET;
908
909    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
910        base_url
911            .join("admin/sso/providers")
912            .map_err(AuthError::from)
913    }
914
915    fn payload(&self) -> &Self::Payload {
916        &()
917    }
918}
919
920/// Admin SSO Provider Create Request
921#[derive(Debug, Clone, Serialize, typed_builder::TypedBuilder)]
922pub struct AdminSsoProviderCreateRequest {
923    #[serde(rename = "type")]
924    pub provider_type: String,
925    pub metadata_url: Option<String>,
926    pub metadata_xml: Option<String>,
927    pub domains: Option<Vec<String>>,
928    pub attribute_mapping: Option<types::SAMLAttributeMappingSchema>,
929}
930
931impl AuthModuleRequest for AdminSsoProviderCreateRequest {
932    type Res = types::SSOProviderSchema;
933    type Error = types::ErrorSchema;
934    type Payload = Self;
935
936    const METHOD: Method = Method::POST;
937
938    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
939        base_url
940            .join("admin/sso/providers")
941            .map_err(AuthError::from)
942    }
943
944    fn payload(&self) -> &Self::Payload {
945        self
946    }
947}
948
949/// Admin SSO Provider Get Request
950#[derive(Debug, Clone, typed_builder::TypedBuilder)]
951pub struct AdminSsoProviderGetRequest {
952    pub sso_provider_id: String,
953}
954
955impl AuthModuleRequest for AdminSsoProviderGetRequest {
956    type Res = types::SSOProviderSchema;
957    type Error = types::ErrorSchema;
958    type Payload = ();
959
960    const METHOD: Method = Method::GET;
961
962    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
963        let endpoint = format!("admin/sso/providers/{}", self.sso_provider_id);
964        base_url.join(&endpoint).map_err(AuthError::from)
965    }
966
967    fn payload(&self) -> &Self::Payload {
968        &()
969    }
970}
971
972/// Admin SSO Provider Update Request
973#[derive(Debug, Clone, Serialize, typed_builder::TypedBuilder)]
974pub struct AdminSsoProviderUpdateRequest {
975    pub sso_provider_id: String,
976    pub metadata_url: Option<String>,
977    pub metadata_xml: Option<String>,
978    pub domains: Option<Vec<String>>,
979    pub attribute_mapping: Option<types::SAMLAttributeMappingSchema>,
980}
981
982impl AuthModuleRequest for AdminSsoProviderUpdateRequest {
983    type Res = types::SSOProviderSchema;
984    type Error = types::ErrorSchema;
985    type Payload = Self;
986
987    const METHOD: Method = Method::PUT;
988
989    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
990        let endpoint = format!("admin/sso/providers/{}", self.sso_provider_id);
991        base_url.join(&endpoint).map_err(AuthError::from)
992    }
993
994    fn payload(&self) -> &Self::Payload {
995        self
996    }
997}
998
999/// Admin SSO Provider Delete Request
1000#[derive(Debug, Clone, typed_builder::TypedBuilder)]
1001pub struct AdminSsoProviderDeleteRequest {
1002    pub sso_provider_id: String,
1003}
1004
1005impl AuthModuleRequest for AdminSsoProviderDeleteRequest {
1006    type Res = types::SSOProviderSchema;
1007    type Error = types::ErrorSchema;
1008    type Payload = ();
1009
1010    const METHOD: Method = Method::DELETE;
1011
1012    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
1013        let endpoint = format!("admin/sso/providers/{}", self.sso_provider_id);
1014        base_url.join(&endpoint).map_err(AuthError::from)
1015    }
1016
1017    fn payload(&self) -> &Self::Payload {
1018        &()
1019    }
1020}
1021
1022/// Settings Request
1023#[derive(Debug, Clone)]
1024pub struct SettingsRequest;
1025
1026impl AuthModuleRequest for SettingsRequest {
1027    type Res = types::SettingsResponse;
1028    type Error = types::ErrorSchema;
1029    type Payload = ();
1030
1031    const METHOD: Method = Method::GET;
1032
1033    fn path(&self, base_url: &Url) -> Result<Url, AuthError> {
1034        base_url.join("settings").map_err(AuthError::from)
1035    }
1036
1037    fn payload(&self) -> &Self::Payload {
1038        &()
1039    }
1040}