dfns-sdk-rust 0.2.0

Dfns API SDK for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
// Code generated by rust-sdk-generator. DO NOT EDIT.

pub mod delegated;
pub mod types;

#[allow(unused_imports)]
use types::*;

/// Client for auth operations.
#[derive(Clone)]
pub struct AuthClient {
    client: crate::client::Client,
}

impl AuthClient {
    pub fn new(client: crate::client::Client) -> Self {
        AuthClient { client }
    }

    /// Completes the user action signing process and provides a signing token that can be used to verify the user intended to perform the action.
    ///
    /// This is the first step of the [User Action Signing flow](https://docs.dfns.co/api-reference/auth/signing-flows).
    ///
    pub async fn create_user_action_signature(
        &self,
        body: CreateUserActionSignatureRequest,
    ) -> Result<CreateUserActionSignatureResponse, crate::error::Error> {
        let path = String::from("/auth/action");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateUserActionSignatureResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                false,
            )
            .await
    }

    /// Starts a user action signing session, returning a challenge that will be used to verify the user's intent to perform an action.
    ///   
    ///   This is the first step of the [User Action Signing flow](https://docs.dfns.co/api-reference/auth/signing-flows).
    pub async fn create_user_action_challenge(
        &self,
        body: CreateUserActionChallengeRequest,
    ) -> Result<CreateUserActionChallengeResponse, crate::error::Error> {
        let path = String::from("/auth/action/init");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateUserActionChallengeResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                false,
            )
            .await
    }

    /// Gets all signature events which have occurred in the over the timeframe. The time range is unbounded, but the export is capped at 100,000 rows. When the result is truncated, the `X-Dfns-Result-Truncated: true` response header is set and a trailing `# TRUNCATED ...` line is appended to the CSV; narrow the time range to retrieve all data.
    ///
    /// StartTime and EndTime are URL-encoded UTC ISO timestamps:
    /// `startTime=2025-08-29T02%3A46%3A40Z`   
    pub async fn list_audit_logs(
        &self,
        query: Option<ListAuditLogsQuery>,
    ) -> Result<(), crate::error::Error> {
        let mut path = String::from("/auth/action/logs");
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            q.push(format!(
                "startTime={}",
                urlencoding::encode(&query.start_time.to_string())
            ));
            q.push(format!(
                "endTime={}",
                urlencoding::encode(&query.end_time.to_string())
            ));
            if let Some(v) = &query.user_id {
                q.push(format!("userId={}", urlencoding::encode(&v.to_string())));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request_no_content(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Gets detailed information for a particular audit log. Specifically, the API returns the action performed, as well as the `firstFactorCredential` in which you will find the signature information required to validate it.
    ///
    /// Dfns maintains a script which can be used for audit log signature validation: [WebAuthn Signature Verifier](https://github.com/dfns/example-scripts/tree/m/python/utils)
    pub async fn get_audit_log(
        &self,
        id: String,
    ) -> Result<GetAuditLogResponse, crate::error::Error> {
        let path = format!("/auth/action/logs/{}", urlencoding::encode(&id));
        self.client
            .request::<GetAuditLogResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// <Warning>
    ///   Applications are deprecated and will be removed in a future release. See details [here](https://docs.dfns.co/deprecation/applications-deprecation).
    ///   </Warning>
    #[deprecated(note = "This endpoint is deprecated.")]
    pub async fn list_applications(&self) -> Result<ListApplicationsResponse, crate::error::Error> {
        let path = String::from("/auth/apps");
        self.client
            .request::<ListApplicationsResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// <Warning>
    ///   Applications are deprecated and will be removed in a future release. See details [here](https://docs.dfns.co/deprecation/applications-deprecation).
    ///   </Warning>
    #[deprecated(note = "This endpoint is deprecated.")]
    pub async fn get_application(
        &self,
        app_id: String,
    ) -> Result<GetApplicationResponse, crate::error::Error> {
        let path = format!("/auth/apps/{}", urlencoding::encode(&app_id));
        self.client
            .request::<GetApplicationResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// List all credentials for a user.
    pub async fn list_credentials(&self) -> Result<ListCredentialsResponse, crate::error::Error> {
        let path = String::from("/auth/credentials");
        self.client
            .request::<ListCredentialsResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Part of the flow [Create Credential Regular flow](https://docs.dfns.co/api-reference/auth/credentials#regular-flow).
    ///
    /// Adds a new credential to a user's account. See [Credential Kinds](https://docs.dfns.co/api-reference/auth/credentials#credential-kinds) for all supported credential types.
    pub async fn create_credential(
        &self,
        body: CreateCredentialRequest,
    ) -> Result<CreateCredentialResponse, crate::error::Error> {
        let path = String::from("/auth/credentials");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateCredentialResponse>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }

    /// Part of the flow [Create Credential Regular flow](https://docs.dfns.co/api-reference/auth/credentials#regular-flow).
    ///   
    ///   Starts a create user credential session, returning a challenge that will be used to verify the user's identity.
    pub async fn create_credential_challenge(
        &self,
        body: CreateCredentialChallengeRequest,
    ) -> Result<serde_json::Value, crate::error::Error> {
        let path = String::from("/auth/credentials/init");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<serde_json::Value>(reqwest::Method::POST, &path, Some(&body), false)
            .await
    }

    /// Activates a credential that was previously deactivated. If the credential is already activated no action is taken.
    pub async fn activate_credential(
        &self,
        body: ActivateCredentialRequest,
    ) -> Result<ActivateCredentialResponse, crate::error::Error> {
        let path = String::from("/auth/credentials/activate");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<ActivateCredentialResponse>(reqwest::Method::PUT, &path, Some(&body), true)
            .await
    }

    /// Delete a specific credential.
    pub async fn delete_credential(
        &self,
        credential_uuid: String,
    ) -> Result<DeleteCredentialResponse, crate::error::Error> {
        let path = format!(
            "/auth/credentials/{}",
            urlencoding::encode(&credential_uuid)
        );
        self.client
            .request::<DeleteCredentialResponse>(reqwest::Method::DELETE, &path, None, true)
            .await
    }

    /// Deactivates a credential that was previously active. If the credential is already deactivated no action is taken.
    pub async fn deactivate_credential(
        &self,
        body: DeactivateCredentialRequest,
    ) -> Result<DeactivateCredentialResponse, crate::error::Error> {
        let path = String::from("/auth/credentials/deactivate");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<DeactivateCredentialResponse>(reqwest::Method::PUT, &path, Some(&body), true)
            .await
    }

    /// Part of the [Create Credential With Code flow](https://docs.dfns.co/api-reference/auth/credentials#create-credential-with-code-flow).
    ///
    /// Creates a one-time-code that can then be used to create a new credential from a place you don't have access to one of your existing credential.
    pub async fn create_credential_code(
        &self,
        body: CreateCredentialCodeRequest,
    ) -> Result<CreateCredentialCodeResponse, crate::error::Error> {
        let path = String::from("/auth/credentials/code");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateCredentialCodeResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                true,
            )
            .await
    }

    /// Part of the flow [Create Credential With Code](https://docs.dfns.co/api-reference/auth/credentials#create-credential-with-code-flow).
    ///
    /// Creates a credential challenge using a one time code-time-code. This challenge must then be signed by the new credential, before finalizing the flow.
    pub async fn create_credential_challenge_with_code(
        &self,
        body: CreateCredentialChallengeWithCodeRequest,
    ) -> Result<serde_json::Value, crate::error::Error> {
        let path = String::from("/auth/credentials/code/init");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<serde_json::Value>(reqwest::Method::POST, &path, Some(&body), false)
            .await
    }

    /// Finalizes the flow [Create Credential With Code](https://docs.dfns.co/api-reference/auth/credentials#create-credential-with-code-flow).
    ///   
    /// Adds a new credential to a user's account. This endpoint is similar to the [Create Credential](https://docs.dfns.co/api-reference/auth/create-credential) endpoint, except:
    /// * it does not need the user to be authenticated
    pub async fn create_credential_with_code(
        &self,
        body: CreateCredentialWithCodeRequest,
    ) -> Result<CreateCredentialWithCodeResponse, crate::error::Error> {
        let path = String::from("/auth/credentials/code/verify");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateCredentialWithCodeResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                false,
            )
            .await
    }

    /// Start a user login session, returning a challenge that will be used to verify the user's identity.
    ///
    /// If the user has a credential of kind `PasswordProtectedKey` a temporary one time code needs to be passed in the `loginCode` field.
    ///
    pub async fn create_login_challenge(
        &self,
        body: CreateLoginChallengeRequest,
    ) -> Result<CreateLoginChallengeResponse, crate::error::Error> {
        let path = String::from("/auth/login/init");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateLoginChallengeResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                false,
            )
            .await
    }

    /// <Warning>
    /// Only a [Service Account](https://docs.dfns.co/api-reference/auth/service-accounts) can use this endpoint.
    /// </Warning>
    ///
    pub async fn delegated_login(
        &self,
        body: DelegatedLoginRequest,
    ) -> Result<DelegatedLoginResponse, crate::error::Error> {
        let path = String::from("/auth/login/delegated");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<DelegatedLoginResponse>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }

    /// Completes the login process and provides the authenticated user with their authentication token.
    ///
    /// The type of credentials used to login is determined by the `kind` field in the nested objects (`firstFactor` and `secondFactor`). Supported credential kinds are:
    /// * `Fido2`: Login challenge is signed by a user's signing device using `WebAuthn`.
    pub async fn complete_user_login(
        &self,
        body: CompleteUserLoginRequest,
    ) -> Result<serde_json::Value, crate::error::Error> {
        let path = String::from("/auth/login");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<serde_json::Value>(reqwest::Method::POST, &path, Some(&body), false)
            .await
    }

    /// Completes the user logout process.
    pub async fn logout(&self, body: LogoutRequest) -> Result<LogoutResponse, crate::error::Error> {
        let path = String::from("/auth/logout");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<LogoutResponse>(reqwest::Method::PUT, &path, Some(&body), false)
            .await
    }

    /// Completes the OIDC login process by exchanging the authorization code obtained from the identity provider. If the verified user has no active first-factor credential yet, it returns a registration challenge to complete via [Complete User Registration](/api-reference/auth/complete-user-registration); otherwise it returns the user's authentication token.
    pub async fn complete_oidc_login(
        &self,
        body: CompleteOidcLoginRequest,
    ) -> Result<serde_json::Value, crate::error::Error> {
        let path = String::from("/auth/login/oidc");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<serde_json::Value>(reqwest::Method::POST, &path, Some(&body), false)
            .await
    }

    /// Initialize the OIDC login process by returning the identity provider authorization URL to redirect the user to.
    pub async fn initiate_oidc_login(
        &self,
        body: InitiateOidcLoginRequest,
    ) -> Result<InitiateOidcLoginResponse, crate::error::Error> {
        let path = String::from("/auth/login/oidc/init");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<InitiateOidcLoginResponse>(reqwest::Method::POST, &path, Some(&body), false)
            .await
    }

    /// Sends a temporary one time code to the user that can be used during login flow.
    ///
    /// If the user has a credential of kind `PasswordProtectedKey` a temporary one time code needs to be passed in the `loginCode` field. That's because the [Create Login Challenge](https://docs.dfns.co/api-reference/auth/create-login-challenge) is unauthenticated and returns the encrypted private key of the user. So we need a first step to verify the identity of the user to prevent anybody from fetching the encrypted private key and trying to brute force it offline.
    pub async fn send_login_code(
        &self,
        body: SendLoginCodeRequest,
    ) -> Result<SendLoginCodeResponse, crate::error::Error> {
        let path = String::from("/auth/login/code");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<SendLoginCodeResponse>(reqwest::Method::POST, &path, Some(&body), false)
            .await
    }

    /// Logs a user in with a JWT id token issued by a social login provider and provides the authenticated user with their authentication token.
    pub async fn social_login(
        &self,
        body: SocialLoginRequest,
    ) -> Result<SocialLoginResponse, crate::error::Error> {
        let path = String::from("/auth/login/social");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<SocialLoginResponse>(reqwest::Method::POST, &path, Some(&body), false)
            .await
    }

    /// Completes the SSO login process by exchanging the authorization code obtained from the identity provider for the user's authentication token.
    pub async fn complete_sso_login(
        &self,
        body: CompleteSsoLoginRequest,
    ) -> Result<CompleteSsoLoginResponse, crate::error::Error> {
        let path = String::from("/auth/login/sso");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CompleteSsoLoginResponse>(reqwest::Method::POST, &path, Some(&body), false)
            .await
    }

    /// Initialize the login process with SSO by returning the IdP URL to call.
    pub async fn initiate_sso_login(
        &self,
        body: InitiateSsoLoginRequest,
    ) -> Result<InitiateSsoLoginResponse, crate::error::Error> {
        let path = String::from("/auth/login/sso/init");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<InitiateSsoLoginResponse>(reqwest::Method::POST, &path, Some(&body), false)
            .await
    }

    /// Only for TenantUsers - Exchanges the current user access token, for an org-bound or tenant-bound token. The user must have access to the target org / tenant. The new access token expiration won't exceed the current token's one.
    pub async fn exchange_access_token(
        &self,
        body: ExchangeAccessTokenRequest,
    ) -> Result<ExchangeAccessTokenResponse, crate::error::Error> {
        let path = String::from("/auth/tokens");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<ExchangeAccessTokenResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                false,
            )
            .await
    }

    /// Retrieve the list of your Personal Access Tokens.
    pub async fn list_personal_access_tokens(
        &self,
    ) -> Result<ListPersonalAccessTokensResponse, crate::error::Error> {
        let path = String::from("/auth/pats");
        self.client
            .request::<ListPersonalAccessTokensResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Create a new Personal Access Token for the caller.
    pub async fn create_personal_access_token(
        &self,
        body: CreatePersonalAccessTokenRequest,
    ) -> Result<CreatePersonalAccessTokenResponse, crate::error::Error> {
        let path = String::from("/auth/pats");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreatePersonalAccessTokenResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                true,
            )
            .await
    }

    /// Retrieve a specific Personal Access Token.
    pub async fn get_personal_access_token(
        &self,
        token_id: String,
    ) -> Result<GetPersonalAccessTokenResponse, crate::error::Error> {
        let path = format!("/auth/pats/{}", urlencoding::encode(&token_id));
        self.client
            .request::<GetPersonalAccessTokenResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Update a specific Personal Access Token.
    pub async fn update_personal_access_token(
        &self,
        token_id: String,
        body: UpdatePersonalAccessTokenRequest,
    ) -> Result<UpdatePersonalAccessTokenResponse, crate::error::Error> {
        let path = format!("/auth/pats/{}", urlencoding::encode(&token_id));
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<UpdatePersonalAccessTokenResponse>(
                reqwest::Method::PUT,
                &path,
                Some(&body),
                true,
            )
            .await
    }

    /// Delete a specific Personal Access Token.
    pub async fn delete_personal_access_token(
        &self,
        token_id: String,
    ) -> Result<DeletePersonalAccessTokenResponse, crate::error::Error> {
        let path = format!("/auth/pats/{}", urlencoding::encode(&token_id));
        self.client
            .request::<DeletePersonalAccessTokenResponse>(
                reqwest::Method::DELETE,
                &path,
                None,
                true,
            )
            .await
    }

    /// Activate a specific Personal Access Token.
    pub async fn activate_personal_access_token(
        &self,
        token_id: String,
    ) -> Result<ActivatePersonalAccessTokenResponse, crate::error::Error> {
        let path = format!("/auth/pats/{}/activate", urlencoding::encode(&token_id));
        self.client
            .request::<ActivatePersonalAccessTokenResponse>(reqwest::Method::PUT, &path, None, true)
            .await
    }

    /// Deactivates a personal access token that was previously active. If the token is already deactivated no action is taken.
    pub async fn deactivate_personal_access_token(
        &self,
        token_id: String,
    ) -> Result<DeactivatePersonalAccessTokenResponse, crate::error::Error> {
        let path = format!("/auth/pats/{}/deactivate", urlencoding::encode(&token_id));
        self.client
            .request::<DeactivatePersonalAccessTokenResponse>(
                reqwest::Method::PUT,
                &path,
                None,
                true,
            )
            .await
    }

    /// <Warning>
    /// Only a [Service Account](https://docs.dfns.co/api-reference/auth/service-accounts) can use this endpoint.
    /// </Warning>
    ///
    pub async fn create_delegated_recovery_challenge(
        &self,
        body: CreateDelegatedRecoveryChallengeRequest,
    ) -> Result<CreateDelegatedRecoveryChallengeResponse, crate::error::Error> {
        let path = String::from("/auth/recover/user/delegated");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateDelegatedRecoveryChallengeResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                true,
            )
            .await
    }

    /// Recovers a user, using a recovery credential. After successfully recovering the user, all of the user's previous credentials and personal access tokens will be invalidated.
    ///
    /// This flow requires cryptographic validation of newly created credential(s) using a recovery credential. The `recovery.credentialAssertion.clientData` field's challenge must be the _base64url-encoded_ representation of the `newCredential` object.
    ///
    pub async fn recover_user(
        &self,
        body: RecoverUserRequest,
    ) -> Result<RecoverUserResponse, crate::error::Error> {
        let path = String::from("/auth/recover/user");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<RecoverUserResponse>(reqwest::Method::POST, &path, Some(&body), false)
            .await
    }

    /// Starts a user recovery session, returning a challenge that will be used to verify the user's identity.
    pub async fn create_recovery_challenge(
        &self,
        body: CreateRecoveryChallengeRequest,
    ) -> Result<CreateRecoveryChallengeResponse, crate::error::Error> {
        let path = String::from("/auth/recover/user/init");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateRecoveryChallengeResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                false,
            )
            .await
    }

    /// Send the user a recovery verification code. This code is used as a second factor to verify the user initiated the recovery request.
    pub async fn send_recovery_code_email(
        &self,
        body: SendRecoveryCodeEmailRequest,
    ) -> Result<SendRecoveryCodeEmailResponse, crate::error::Error> {
        let path = String::from("/auth/recover/user/code");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<SendRecoveryCodeEmailResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                false,
            )
            .await
    }

    /// <Warning>
    /// Only a [Service Account](https://docs.dfns.co/api-reference/auth/service-accounts) can use this endpoint.
    /// </Warning>
    ///
    pub async fn create_delegated_registration_challenge(
        &self,
        body: CreateDelegatedRegistrationChallengeRequest,
    ) -> Result<CreateDelegatedRegistrationChallengeResponse, crate::error::Error> {
        let path = String::from("/auth/registration/delegated");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateDelegatedRegistrationChallengeResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                true,
            )
            .await
    }

    /// Starts a user registration session. It returns a challenge that will need to be signed by a passkey and used to perform the step [Complete User Registration](/api-reference/auth/complete-user-registration)
    pub async fn create_registration_challenge(
        &self,
        body: CreateRegistrationChallengeRequest,
    ) -> Result<CreateRegistrationChallengeResponse, crate::error::Error> {
        let path = String::from("/auth/registration/init");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateRegistrationChallengeResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                false,
            )
            .await
    }

    /// Starts an end-user registration session by passing a JWT obtained by an IdP. It returns a challenge that will need to be signed by a passkey and used to perform [Complete End User Registration with Wallets](/api-reference/auth/complete-end-user-registration-with-wallets).
    pub async fn create_social_registration_challenge(
        &self,
        body: CreateSocialRegistrationChallengeRequest,
    ) -> Result<CreateSocialRegistrationChallengeResponse, crate::error::Error> {
        let path = String::from("/auth/registration/social");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateSocialRegistrationChallengeResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                false,
            )
            .await
    }

    /// Completes the user registration process and creates the user's initial credentials.
    ///
    /// All credentials submitted in this call (`firstFactorCredential`, `secondFactorCredential`, `recoveryCredential`) sign the same challenge returned by the registration init endpoint ([Create Registration Challenge](https://docs.dfns.co/api-reference/auth/create-registration-challenge), [Create Delegated Registration Challenge](https://docs.dfns.co/api-reference/auth/create-delegated-registration-challenge), or [Create Social Registration Challenge](https://docs.dfns.co/api-reference/auth/create-social-registration-challenge)).
    ///
    pub async fn complete_user_registration(
        &self,
        body: CompleteUserRegistrationRequest,
    ) -> Result<CompleteUserRegistrationResponse, crate::error::Error> {
        let path = String::from("/auth/registration");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CompleteUserRegistrationResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                false,
            )
            .await
    }

    /// Completes the end user registration process and creates the user's initial credentials along with delegated wallets for the new end user.
    ///
    /// All credentials submitted in this call (`firstFactorCredential`, `secondFactorCredential`, `recoveryCredential`) sign the same challenge returned by the registration init endpoint ([Create Delegated Registration Challenge](https://docs.dfns.co/api-reference/auth/create-delegated-registration-challenge) or [Create Social Registration Challenge](https://docs.dfns.co/api-reference/auth/create-social-registration-challenge)).
    ///
    pub async fn complete_end_user_registration_with_wallets(
        &self,
        body: CompleteEndUserRegistrationWithWalletsRequest,
    ) -> Result<CompleteEndUserRegistrationWithWalletsResponse, crate::error::Error> {
        let path = String::from("/auth/registration/enduser");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CompleteEndUserRegistrationWithWalletsResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                false,
            )
            .await
    }

    /// Sends the user a new registration code. The previous registration code will be marked invalid. If the user has already completed their registration no action will be taken.
    pub async fn resend_registration_code(
        &self,
        body: ResendRegistrationCodeRequest,
    ) -> Result<ResendRegistrationCodeResponse, crate::error::Error> {
        let path = String::from("/auth/registration/code");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<ResendRegistrationCodeResponse>(
                reqwest::Method::PUT,
                &path,
                Some(&body),
                false,
            )
            .await
    }

    /// List all Service Accounts in your organization.
    pub async fn list_service_accounts(
        &self,
    ) -> Result<ListServiceAccountsResponse, crate::error::Error> {
        let path = String::from("/auth/service-accounts");
        self.client
            .request::<ListServiceAccountsResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Create a new Service Account for your organization.
    pub async fn create_service_account(
        &self,
        body: CreateServiceAccountRequest,
    ) -> Result<CreateServiceAccountResponse, crate::error::Error> {
        let path = String::from("/auth/service-accounts");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateServiceAccountResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                true,
            )
            .await
    }

    /// Get information about a specific Service Account.
    pub async fn get_service_account(
        &self,
        service_account_id: String,
    ) -> Result<GetServiceAccountResponse, crate::error::Error> {
        let path = format!(
            "/auth/service-accounts/{}",
            urlencoding::encode(&service_account_id)
        );
        self.client
            .request::<GetServiceAccountResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Update a specific Service Account.
    pub async fn update_service_account(
        &self,
        service_account_id: String,
        body: UpdateServiceAccountRequest,
    ) -> Result<UpdateServiceAccountResponse, crate::error::Error> {
        let path = format!(
            "/auth/service-accounts/{}",
            urlencoding::encode(&service_account_id)
        );
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<UpdateServiceAccountResponse>(reqwest::Method::PUT, &path, Some(&body), true)
            .await
    }

    /// Delete a specific Service Account.
    pub async fn delete_service_account(
        &self,
        service_account_id: String,
        query: Option<DeleteServiceAccountQuery>,
    ) -> Result<DeleteServiceAccountResponse, crate::error::Error> {
        let mut path = format!(
            "/auth/service-accounts/{}",
            urlencoding::encode(&service_account_id)
        );
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            if let Some(v) = &query.force {
                q.push(format!("force={}", urlencoding::encode(&v.to_string())));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<DeleteServiceAccountResponse>(reqwest::Method::DELETE, &path, None, true)
            .await
    }

    /// Activate a specific Service Account.
    pub async fn activate_service_account(
        &self,
        service_account_id: String,
    ) -> Result<ActivateServiceAccountResponse, crate::error::Error> {
        let path = format!(
            "/auth/service-accounts/{}/activate",
            urlencoding::encode(&service_account_id)
        );
        self.client
            .request::<ActivateServiceAccountResponse>(reqwest::Method::PUT, &path, None, true)
            .await
    }

    /// Deactivate a specific Service Account.
    pub async fn deactivate_service_account(
        &self,
        service_account_id: String,
        body: DeactivateServiceAccountRequest,
    ) -> Result<DeactivateServiceAccountResponse, crate::error::Error> {
        let path = format!(
            "/auth/service-accounts/{}/deactivate",
            urlencoding::encode(&service_account_id)
        );
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<DeactivateServiceAccountResponse>(
                reqwest::Method::PUT,
                &path,
                Some(&body),
                true,
            )
            .await
    }

    /// Activate a specific User.
    pub async fn activate_user(
        &self,
        user_id: String,
    ) -> Result<ActivateUserResponse, crate::error::Error> {
        let path = format!("/auth/users/{}/activate", urlencoding::encode(&user_id));
        self.client
            .request::<ActivateUserResponse>(reqwest::Method::PUT, &path, None, true)
            .await
    }

    /// Deactivate a specific User.
    pub async fn deactivate_user(
        &self,
        user_id: String,
    ) -> Result<DeactivateUserResponse, crate::error::Error> {
        let path = format!("/auth/users/{}/deactivate", urlencoding::encode(&user_id));
        self.client
            .request::<DeactivateUserResponse>(reqwest::Method::PUT, &path, None, true)
            .await
    }

    /// Retrieve information about a specific User.
    pub async fn get_user(&self, user_id: String) -> Result<GetUserResponse, crate::error::Error> {
        let path = format!("/auth/users/{}", urlencoding::encode(&user_id));
        self.client
            .request::<GetUserResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Update a specific User.
    pub async fn update_user(
        &self,
        user_id: String,
        body: UpdateUserRequest,
    ) -> Result<UpdateUserResponse, crate::error::Error> {
        let path = format!("/auth/users/{}", urlencoding::encode(&user_id));
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<UpdateUserResponse>(reqwest::Method::PUT, &path, Some(&body), true)
            .await
    }

    /// Delete a specific User.
    pub async fn delete_user(
        &self,
        user_id: String,
    ) -> Result<DeleteUserResponse, crate::error::Error> {
        let path = format!("/auth/users/{}", urlencoding::encode(&user_id));
        self.client
            .request::<DeleteUserResponse>(reqwest::Method::DELETE, &path, None, true)
            .await
    }

    /// List all Users in your organization.
    pub async fn list_users(
        &self,
        query: Option<ListUsersQuery>,
    ) -> Result<ListUsersResponse, crate::error::Error> {
        let mut path = String::from("/auth/users");
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            if let Some(v) = &query.limit {
                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.pagination_token {
                q.push(format!(
                    "paginationToken={}",
                    urlencoding::encode(&v.to_string())
                ));
            }
            if let Some(v) = &query.kind {
                q.push(format!("kind={}", urlencoding::encode(&v.to_string())));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<ListUsersResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Invite a new user in the caller's org. This will create the user and send a registration email to the created User's email, with a registration code, and pointing him to complete his registration on Dfns Dashboard. The user is created without any permissions.
    ///   
    ///   <Note>If you want the created User to not know about about Dfns, and don't want him to
    ///   receive the registration email from Dfns, you should rather use the Delegated Registration
    pub async fn create_user(
        &self,
        body: CreateUserRequest,
    ) -> Result<CreateUserResponse, crate::error::Error> {
        let path = String::from("/auth/users");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateUserResponse>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }

    /// Invite an existing Tenant User in the caller's org. The invited Tenant User starts without any permissions within the org.
    pub async fn invite_tenant_user(
        &self,
        body: InviteTenantUserRequest,
    ) -> Result<InviteTenantUserResponse, crate::error::Error> {
        let path = String::from("/auth/users/invite");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<InviteTenantUserResponse>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }
}