Skip to main content

dfns_sdk_rust/auth/
mod.rs

1// Code generated by rust-sdk-generator. DO NOT EDIT.
2
3pub mod delegated;
4pub mod types;
5
6#[allow(unused_imports)]
7use types::*;
8
9/// Client for auth operations.
10#[derive(Clone)]
11pub struct AuthClient {
12    client: crate::client::Client,
13}
14
15impl AuthClient {
16    pub fn new(client: crate::client::Client) -> Self {
17        AuthClient { client }
18    }
19
20    /// Completes the user action signing process and provides a signing token that can be used to verify the user intended to perform the action.
21    ///
22    /// This is the first step of the [User Action Signing flow](https://docs.dfns.co/api-reference/auth/signing-flows).
23    ///
24    pub async fn create_user_action_signature(
25        &self,
26        body: CreateUserActionSignatureRequest,
27    ) -> Result<CreateUserActionSignatureResponse, crate::error::Error> {
28        let path = String::from("/auth/action");
29        let body = serde_json::to_value(&body)?;
30        self.client
31            .request::<CreateUserActionSignatureResponse>(
32                reqwest::Method::POST,
33                &path,
34                Some(&body),
35                false,
36            )
37            .await
38    }
39
40    /// Starts a user action signing session, returning a challenge that will be used to verify the user's intent to perform an action.
41    ///   
42    ///   This is the first step of the [User Action Signing flow](https://docs.dfns.co/api-reference/auth/signing-flows).
43    pub async fn create_user_action_challenge(
44        &self,
45        body: CreateUserActionChallengeRequest,
46    ) -> Result<CreateUserActionChallengeResponse, crate::error::Error> {
47        let path = String::from("/auth/action/init");
48        let body = serde_json::to_value(&body)?;
49        self.client
50            .request::<CreateUserActionChallengeResponse>(
51                reqwest::Method::POST,
52                &path,
53                Some(&body),
54                false,
55            )
56            .await
57    }
58
59    /// 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.
60    ///
61    /// StartTime and EndTime are URL-encoded UTC ISO timestamps:
62    /// `startTime=2025-08-29T02%3A46%3A40Z`   
63    pub async fn list_audit_logs(
64        &self,
65        query: Option<ListAuditLogsQuery>,
66    ) -> Result<(), crate::error::Error> {
67        let mut path = String::from("/auth/action/logs");
68        if let Some(query) = &query {
69            let mut q: Vec<String> = Vec::new();
70            q.push(format!(
71                "startTime={}",
72                urlencoding::encode(&query.start_time.to_string())
73            ));
74            q.push(format!(
75                "endTime={}",
76                urlencoding::encode(&query.end_time.to_string())
77            ));
78            if let Some(v) = &query.user_id {
79                q.push(format!("userId={}", urlencoding::encode(&v.to_string())));
80            }
81            if !q.is_empty() {
82                path.push('?');
83                path.push_str(&q.join("&"));
84            }
85        }
86        self.client
87            .request_no_content(reqwest::Method::GET, &path, None, false)
88            .await
89    }
90
91    /// 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.
92    ///
93    /// 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)
94    pub async fn get_audit_log(
95        &self,
96        id: String,
97    ) -> Result<GetAuditLogResponse, crate::error::Error> {
98        let path = format!("/auth/action/logs/{}", urlencoding::encode(&id));
99        self.client
100            .request::<GetAuditLogResponse>(reqwest::Method::GET, &path, None, false)
101            .await
102    }
103
104    /// <Warning>
105    ///   Applications are deprecated and will be removed in a future release. See details [here](https://docs.dfns.co/deprecation/applications-deprecation).
106    ///   </Warning>
107    #[deprecated(note = "This endpoint is deprecated.")]
108    pub async fn list_applications(&self) -> Result<ListApplicationsResponse, crate::error::Error> {
109        let path = String::from("/auth/apps");
110        self.client
111            .request::<ListApplicationsResponse>(reqwest::Method::GET, &path, None, false)
112            .await
113    }
114
115    /// <Warning>
116    ///   Applications are deprecated and will be removed in a future release. See details [here](https://docs.dfns.co/deprecation/applications-deprecation).
117    ///   </Warning>
118    #[deprecated(note = "This endpoint is deprecated.")]
119    pub async fn get_application(
120        &self,
121        app_id: String,
122    ) -> Result<GetApplicationResponse, crate::error::Error> {
123        let path = format!("/auth/apps/{}", urlencoding::encode(&app_id));
124        self.client
125            .request::<GetApplicationResponse>(reqwest::Method::GET, &path, None, false)
126            .await
127    }
128
129    /// List all credentials for a user.
130    pub async fn list_credentials(&self) -> Result<ListCredentialsResponse, crate::error::Error> {
131        let path = String::from("/auth/credentials");
132        self.client
133            .request::<ListCredentialsResponse>(reqwest::Method::GET, &path, None, false)
134            .await
135    }
136
137    /// Part of the flow [Create Credential Regular flow](https://docs.dfns.co/api-reference/auth/credentials#regular-flow).
138    ///
139    /// 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.
140    pub async fn create_credential(
141        &self,
142        body: CreateCredentialRequest,
143    ) -> Result<CreateCredentialResponse, crate::error::Error> {
144        let path = String::from("/auth/credentials");
145        let body = serde_json::to_value(&body)?;
146        self.client
147            .request::<CreateCredentialResponse>(reqwest::Method::POST, &path, Some(&body), true)
148            .await
149    }
150
151    /// Part of the flow [Create Credential Regular flow](https://docs.dfns.co/api-reference/auth/credentials#regular-flow).
152    ///   
153    ///   Starts a create user credential session, returning a challenge that will be used to verify the user's identity.
154    pub async fn create_credential_challenge(
155        &self,
156        body: CreateCredentialChallengeRequest,
157    ) -> Result<serde_json::Value, crate::error::Error> {
158        let path = String::from("/auth/credentials/init");
159        let body = serde_json::to_value(&body)?;
160        self.client
161            .request::<serde_json::Value>(reqwest::Method::POST, &path, Some(&body), false)
162            .await
163    }
164
165    /// Activates a credential that was previously deactivated. If the credential is already activated no action is taken.
166    pub async fn activate_credential(
167        &self,
168        body: ActivateCredentialRequest,
169    ) -> Result<ActivateCredentialResponse, crate::error::Error> {
170        let path = String::from("/auth/credentials/activate");
171        let body = serde_json::to_value(&body)?;
172        self.client
173            .request::<ActivateCredentialResponse>(reqwest::Method::PUT, &path, Some(&body), true)
174            .await
175    }
176
177    /// Delete a specific credential.
178    pub async fn delete_credential(
179        &self,
180        credential_uuid: String,
181    ) -> Result<DeleteCredentialResponse, crate::error::Error> {
182        let path = format!(
183            "/auth/credentials/{}",
184            urlencoding::encode(&credential_uuid)
185        );
186        self.client
187            .request::<DeleteCredentialResponse>(reqwest::Method::DELETE, &path, None, true)
188            .await
189    }
190
191    /// Deactivates a credential that was previously active. If the credential is already deactivated no action is taken.
192    pub async fn deactivate_credential(
193        &self,
194        body: DeactivateCredentialRequest,
195    ) -> Result<DeactivateCredentialResponse, crate::error::Error> {
196        let path = String::from("/auth/credentials/deactivate");
197        let body = serde_json::to_value(&body)?;
198        self.client
199            .request::<DeactivateCredentialResponse>(reqwest::Method::PUT, &path, Some(&body), true)
200            .await
201    }
202
203    /// Part of the [Create Credential With Code flow](https://docs.dfns.co/api-reference/auth/credentials#create-credential-with-code-flow).
204    ///
205    /// 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.
206    pub async fn create_credential_code(
207        &self,
208        body: CreateCredentialCodeRequest,
209    ) -> Result<CreateCredentialCodeResponse, crate::error::Error> {
210        let path = String::from("/auth/credentials/code");
211        let body = serde_json::to_value(&body)?;
212        self.client
213            .request::<CreateCredentialCodeResponse>(
214                reqwest::Method::POST,
215                &path,
216                Some(&body),
217                true,
218            )
219            .await
220    }
221
222    /// Part of the flow [Create Credential With Code](https://docs.dfns.co/api-reference/auth/credentials#create-credential-with-code-flow).
223    ///
224    /// 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.
225    pub async fn create_credential_challenge_with_code(
226        &self,
227        body: CreateCredentialChallengeWithCodeRequest,
228    ) -> Result<serde_json::Value, crate::error::Error> {
229        let path = String::from("/auth/credentials/code/init");
230        let body = serde_json::to_value(&body)?;
231        self.client
232            .request::<serde_json::Value>(reqwest::Method::POST, &path, Some(&body), false)
233            .await
234    }
235
236    /// Finalizes the flow [Create Credential With Code](https://docs.dfns.co/api-reference/auth/credentials#create-credential-with-code-flow).
237    ///   
238    /// 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:
239    /// * it does not need the user to be authenticated
240    pub async fn create_credential_with_code(
241        &self,
242        body: CreateCredentialWithCodeRequest,
243    ) -> Result<CreateCredentialWithCodeResponse, crate::error::Error> {
244        let path = String::from("/auth/credentials/code/verify");
245        let body = serde_json::to_value(&body)?;
246        self.client
247            .request::<CreateCredentialWithCodeResponse>(
248                reqwest::Method::POST,
249                &path,
250                Some(&body),
251                false,
252            )
253            .await
254    }
255
256    /// Start a user login session, returning a challenge that will be used to verify the user's identity.
257    ///
258    /// If the user has a credential of kind `PasswordProtectedKey` a temporary one time code needs to be passed in the `loginCode` field.
259    ///
260    pub async fn create_login_challenge(
261        &self,
262        body: CreateLoginChallengeRequest,
263    ) -> Result<CreateLoginChallengeResponse, crate::error::Error> {
264        let path = String::from("/auth/login/init");
265        let body = serde_json::to_value(&body)?;
266        self.client
267            .request::<CreateLoginChallengeResponse>(
268                reqwest::Method::POST,
269                &path,
270                Some(&body),
271                false,
272            )
273            .await
274    }
275
276    /// <Warning>
277    /// Only a [Service Account](https://docs.dfns.co/api-reference/auth/service-accounts) can use this endpoint.
278    /// </Warning>
279    ///
280    pub async fn delegated_login(
281        &self,
282        body: DelegatedLoginRequest,
283    ) -> Result<DelegatedLoginResponse, crate::error::Error> {
284        let path = String::from("/auth/login/delegated");
285        let body = serde_json::to_value(&body)?;
286        self.client
287            .request::<DelegatedLoginResponse>(reqwest::Method::POST, &path, Some(&body), true)
288            .await
289    }
290
291    /// Completes the login process and provides the authenticated user with their authentication token.
292    ///
293    /// The type of credentials used to login is determined by the `kind` field in the nested objects (`firstFactor` and `secondFactor`). Supported credential kinds are:
294    /// * `Fido2`: Login challenge is signed by a user's signing device using `WebAuthn`.
295    pub async fn complete_user_login(
296        &self,
297        body: CompleteUserLoginRequest,
298    ) -> Result<serde_json::Value, crate::error::Error> {
299        let path = String::from("/auth/login");
300        let body = serde_json::to_value(&body)?;
301        self.client
302            .request::<serde_json::Value>(reqwest::Method::POST, &path, Some(&body), false)
303            .await
304    }
305
306    /// Completes the user logout process.
307    pub async fn logout(&self, body: LogoutRequest) -> Result<LogoutResponse, crate::error::Error> {
308        let path = String::from("/auth/logout");
309        let body = serde_json::to_value(&body)?;
310        self.client
311            .request::<LogoutResponse>(reqwest::Method::PUT, &path, Some(&body), false)
312            .await
313    }
314
315    /// 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.
316    pub async fn complete_oidc_login(
317        &self,
318        body: CompleteOidcLoginRequest,
319    ) -> Result<serde_json::Value, crate::error::Error> {
320        let path = String::from("/auth/login/oidc");
321        let body = serde_json::to_value(&body)?;
322        self.client
323            .request::<serde_json::Value>(reqwest::Method::POST, &path, Some(&body), false)
324            .await
325    }
326
327    /// Initialize the OIDC login process by returning the identity provider authorization URL to redirect the user to.
328    pub async fn initiate_oidc_login(
329        &self,
330        body: InitiateOidcLoginRequest,
331    ) -> Result<InitiateOidcLoginResponse, crate::error::Error> {
332        let path = String::from("/auth/login/oidc/init");
333        let body = serde_json::to_value(&body)?;
334        self.client
335            .request::<InitiateOidcLoginResponse>(reqwest::Method::POST, &path, Some(&body), false)
336            .await
337    }
338
339    /// Sends a temporary one time code to the user that can be used during login flow.
340    ///
341    /// 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.
342    pub async fn send_login_code(
343        &self,
344        body: SendLoginCodeRequest,
345    ) -> Result<SendLoginCodeResponse, crate::error::Error> {
346        let path = String::from("/auth/login/code");
347        let body = serde_json::to_value(&body)?;
348        self.client
349            .request::<SendLoginCodeResponse>(reqwest::Method::POST, &path, Some(&body), false)
350            .await
351    }
352
353    /// Logs a user in with a JWT id token issued by a social login provider and provides the authenticated user with their authentication token.
354    pub async fn social_login(
355        &self,
356        body: SocialLoginRequest,
357    ) -> Result<SocialLoginResponse, crate::error::Error> {
358        let path = String::from("/auth/login/social");
359        let body = serde_json::to_value(&body)?;
360        self.client
361            .request::<SocialLoginResponse>(reqwest::Method::POST, &path, Some(&body), false)
362            .await
363    }
364
365    /// Completes the SSO login process by exchanging the authorization code obtained from the identity provider for the user's authentication token.
366    pub async fn complete_sso_login(
367        &self,
368        body: CompleteSsoLoginRequest,
369    ) -> Result<CompleteSsoLoginResponse, crate::error::Error> {
370        let path = String::from("/auth/login/sso");
371        let body = serde_json::to_value(&body)?;
372        self.client
373            .request::<CompleteSsoLoginResponse>(reqwest::Method::POST, &path, Some(&body), false)
374            .await
375    }
376
377    /// Initialize the login process with SSO by returning the IdP URL to call.
378    pub async fn initiate_sso_login(
379        &self,
380        body: InitiateSsoLoginRequest,
381    ) -> Result<InitiateSsoLoginResponse, crate::error::Error> {
382        let path = String::from("/auth/login/sso/init");
383        let body = serde_json::to_value(&body)?;
384        self.client
385            .request::<InitiateSsoLoginResponse>(reqwest::Method::POST, &path, Some(&body), false)
386            .await
387    }
388
389    /// 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.
390    pub async fn exchange_access_token(
391        &self,
392        body: ExchangeAccessTokenRequest,
393    ) -> Result<ExchangeAccessTokenResponse, crate::error::Error> {
394        let path = String::from("/auth/tokens");
395        let body = serde_json::to_value(&body)?;
396        self.client
397            .request::<ExchangeAccessTokenResponse>(
398                reqwest::Method::POST,
399                &path,
400                Some(&body),
401                false,
402            )
403            .await
404    }
405
406    /// Retrieve the list of your Personal Access Tokens.
407    pub async fn list_personal_access_tokens(
408        &self,
409    ) -> Result<ListPersonalAccessTokensResponse, crate::error::Error> {
410        let path = String::from("/auth/pats");
411        self.client
412            .request::<ListPersonalAccessTokensResponse>(reqwest::Method::GET, &path, None, false)
413            .await
414    }
415
416    /// Create a new Personal Access Token for the caller.
417    pub async fn create_personal_access_token(
418        &self,
419        body: CreatePersonalAccessTokenRequest,
420    ) -> Result<CreatePersonalAccessTokenResponse, crate::error::Error> {
421        let path = String::from("/auth/pats");
422        let body = serde_json::to_value(&body)?;
423        self.client
424            .request::<CreatePersonalAccessTokenResponse>(
425                reqwest::Method::POST,
426                &path,
427                Some(&body),
428                true,
429            )
430            .await
431    }
432
433    /// Retrieve a specific Personal Access Token.
434    pub async fn get_personal_access_token(
435        &self,
436        token_id: String,
437    ) -> Result<GetPersonalAccessTokenResponse, crate::error::Error> {
438        let path = format!("/auth/pats/{}", urlencoding::encode(&token_id));
439        self.client
440            .request::<GetPersonalAccessTokenResponse>(reqwest::Method::GET, &path, None, false)
441            .await
442    }
443
444    /// Update a specific Personal Access Token.
445    pub async fn update_personal_access_token(
446        &self,
447        token_id: String,
448        body: UpdatePersonalAccessTokenRequest,
449    ) -> Result<UpdatePersonalAccessTokenResponse, crate::error::Error> {
450        let path = format!("/auth/pats/{}", urlencoding::encode(&token_id));
451        let body = serde_json::to_value(&body)?;
452        self.client
453            .request::<UpdatePersonalAccessTokenResponse>(
454                reqwest::Method::PUT,
455                &path,
456                Some(&body),
457                true,
458            )
459            .await
460    }
461
462    /// Delete a specific Personal Access Token.
463    pub async fn delete_personal_access_token(
464        &self,
465        token_id: String,
466    ) -> Result<DeletePersonalAccessTokenResponse, crate::error::Error> {
467        let path = format!("/auth/pats/{}", urlencoding::encode(&token_id));
468        self.client
469            .request::<DeletePersonalAccessTokenResponse>(
470                reqwest::Method::DELETE,
471                &path,
472                None,
473                true,
474            )
475            .await
476    }
477
478    /// Activate a specific Personal Access Token.
479    pub async fn activate_personal_access_token(
480        &self,
481        token_id: String,
482    ) -> Result<ActivatePersonalAccessTokenResponse, crate::error::Error> {
483        let path = format!("/auth/pats/{}/activate", urlencoding::encode(&token_id));
484        self.client
485            .request::<ActivatePersonalAccessTokenResponse>(reqwest::Method::PUT, &path, None, true)
486            .await
487    }
488
489    /// Deactivates a personal access token that was previously active. If the token is already deactivated no action is taken.
490    pub async fn deactivate_personal_access_token(
491        &self,
492        token_id: String,
493    ) -> Result<DeactivatePersonalAccessTokenResponse, crate::error::Error> {
494        let path = format!("/auth/pats/{}/deactivate", urlencoding::encode(&token_id));
495        self.client
496            .request::<DeactivatePersonalAccessTokenResponse>(
497                reqwest::Method::PUT,
498                &path,
499                None,
500                true,
501            )
502            .await
503    }
504
505    /// <Warning>
506    /// Only a [Service Account](https://docs.dfns.co/api-reference/auth/service-accounts) can use this endpoint.
507    /// </Warning>
508    ///
509    pub async fn create_delegated_recovery_challenge(
510        &self,
511        body: CreateDelegatedRecoveryChallengeRequest,
512    ) -> Result<CreateDelegatedRecoveryChallengeResponse, crate::error::Error> {
513        let path = String::from("/auth/recover/user/delegated");
514        let body = serde_json::to_value(&body)?;
515        self.client
516            .request::<CreateDelegatedRecoveryChallengeResponse>(
517                reqwest::Method::POST,
518                &path,
519                Some(&body),
520                true,
521            )
522            .await
523    }
524
525    /// 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.
526    ///
527    /// 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.
528    ///
529    pub async fn recover_user(
530        &self,
531        body: RecoverUserRequest,
532    ) -> Result<RecoverUserResponse, crate::error::Error> {
533        let path = String::from("/auth/recover/user");
534        let body = serde_json::to_value(&body)?;
535        self.client
536            .request::<RecoverUserResponse>(reqwest::Method::POST, &path, Some(&body), false)
537            .await
538    }
539
540    /// Starts a user recovery session, returning a challenge that will be used to verify the user's identity.
541    pub async fn create_recovery_challenge(
542        &self,
543        body: CreateRecoveryChallengeRequest,
544    ) -> Result<CreateRecoveryChallengeResponse, crate::error::Error> {
545        let path = String::from("/auth/recover/user/init");
546        let body = serde_json::to_value(&body)?;
547        self.client
548            .request::<CreateRecoveryChallengeResponse>(
549                reqwest::Method::POST,
550                &path,
551                Some(&body),
552                false,
553            )
554            .await
555    }
556
557    /// Send the user a recovery verification code. This code is used as a second factor to verify the user initiated the recovery request.
558    pub async fn send_recovery_code_email(
559        &self,
560        body: SendRecoveryCodeEmailRequest,
561    ) -> Result<SendRecoveryCodeEmailResponse, crate::error::Error> {
562        let path = String::from("/auth/recover/user/code");
563        let body = serde_json::to_value(&body)?;
564        self.client
565            .request::<SendRecoveryCodeEmailResponse>(
566                reqwest::Method::POST,
567                &path,
568                Some(&body),
569                false,
570            )
571            .await
572    }
573
574    /// <Warning>
575    /// Only a [Service Account](https://docs.dfns.co/api-reference/auth/service-accounts) can use this endpoint.
576    /// </Warning>
577    ///
578    pub async fn create_delegated_registration_challenge(
579        &self,
580        body: CreateDelegatedRegistrationChallengeRequest,
581    ) -> Result<CreateDelegatedRegistrationChallengeResponse, crate::error::Error> {
582        let path = String::from("/auth/registration/delegated");
583        let body = serde_json::to_value(&body)?;
584        self.client
585            .request::<CreateDelegatedRegistrationChallengeResponse>(
586                reqwest::Method::POST,
587                &path,
588                Some(&body),
589                true,
590            )
591            .await
592    }
593
594    /// 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)
595    pub async fn create_registration_challenge(
596        &self,
597        body: CreateRegistrationChallengeRequest,
598    ) -> Result<CreateRegistrationChallengeResponse, crate::error::Error> {
599        let path = String::from("/auth/registration/init");
600        let body = serde_json::to_value(&body)?;
601        self.client
602            .request::<CreateRegistrationChallengeResponse>(
603                reqwest::Method::POST,
604                &path,
605                Some(&body),
606                false,
607            )
608            .await
609    }
610
611    /// 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).
612    pub async fn create_social_registration_challenge(
613        &self,
614        body: CreateSocialRegistrationChallengeRequest,
615    ) -> Result<CreateSocialRegistrationChallengeResponse, crate::error::Error> {
616        let path = String::from("/auth/registration/social");
617        let body = serde_json::to_value(&body)?;
618        self.client
619            .request::<CreateSocialRegistrationChallengeResponse>(
620                reqwest::Method::POST,
621                &path,
622                Some(&body),
623                false,
624            )
625            .await
626    }
627
628    /// Completes the user registration process and creates the user's initial credentials.
629    ///
630    /// 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)).
631    ///
632    pub async fn complete_user_registration(
633        &self,
634        body: CompleteUserRegistrationRequest,
635    ) -> Result<CompleteUserRegistrationResponse, crate::error::Error> {
636        let path = String::from("/auth/registration");
637        let body = serde_json::to_value(&body)?;
638        self.client
639            .request::<CompleteUserRegistrationResponse>(
640                reqwest::Method::POST,
641                &path,
642                Some(&body),
643                false,
644            )
645            .await
646    }
647
648    /// Completes the end user registration process and creates the user's initial credentials along with delegated wallets for the new end user.
649    ///
650    /// 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)).
651    ///
652    pub async fn complete_end_user_registration_with_wallets(
653        &self,
654        body: CompleteEndUserRegistrationWithWalletsRequest,
655    ) -> Result<CompleteEndUserRegistrationWithWalletsResponse, crate::error::Error> {
656        let path = String::from("/auth/registration/enduser");
657        let body = serde_json::to_value(&body)?;
658        self.client
659            .request::<CompleteEndUserRegistrationWithWalletsResponse>(
660                reqwest::Method::POST,
661                &path,
662                Some(&body),
663                false,
664            )
665            .await
666    }
667
668    /// 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.
669    pub async fn resend_registration_code(
670        &self,
671        body: ResendRegistrationCodeRequest,
672    ) -> Result<ResendRegistrationCodeResponse, crate::error::Error> {
673        let path = String::from("/auth/registration/code");
674        let body = serde_json::to_value(&body)?;
675        self.client
676            .request::<ResendRegistrationCodeResponse>(
677                reqwest::Method::PUT,
678                &path,
679                Some(&body),
680                false,
681            )
682            .await
683    }
684
685    /// List all Service Accounts in your organization.
686    pub async fn list_service_accounts(
687        &self,
688    ) -> Result<ListServiceAccountsResponse, crate::error::Error> {
689        let path = String::from("/auth/service-accounts");
690        self.client
691            .request::<ListServiceAccountsResponse>(reqwest::Method::GET, &path, None, false)
692            .await
693    }
694
695    /// Create a new Service Account for your organization.
696    pub async fn create_service_account(
697        &self,
698        body: CreateServiceAccountRequest,
699    ) -> Result<CreateServiceAccountResponse, crate::error::Error> {
700        let path = String::from("/auth/service-accounts");
701        let body = serde_json::to_value(&body)?;
702        self.client
703            .request::<CreateServiceAccountResponse>(
704                reqwest::Method::POST,
705                &path,
706                Some(&body),
707                true,
708            )
709            .await
710    }
711
712    /// Get information about a specific Service Account.
713    pub async fn get_service_account(
714        &self,
715        service_account_id: String,
716    ) -> Result<GetServiceAccountResponse, crate::error::Error> {
717        let path = format!(
718            "/auth/service-accounts/{}",
719            urlencoding::encode(&service_account_id)
720        );
721        self.client
722            .request::<GetServiceAccountResponse>(reqwest::Method::GET, &path, None, false)
723            .await
724    }
725
726    /// Update a specific Service Account.
727    pub async fn update_service_account(
728        &self,
729        service_account_id: String,
730        body: UpdateServiceAccountRequest,
731    ) -> Result<UpdateServiceAccountResponse, crate::error::Error> {
732        let path = format!(
733            "/auth/service-accounts/{}",
734            urlencoding::encode(&service_account_id)
735        );
736        let body = serde_json::to_value(&body)?;
737        self.client
738            .request::<UpdateServiceAccountResponse>(reqwest::Method::PUT, &path, Some(&body), true)
739            .await
740    }
741
742    /// Delete a specific Service Account.
743    pub async fn delete_service_account(
744        &self,
745        service_account_id: String,
746        query: Option<DeleteServiceAccountQuery>,
747    ) -> Result<DeleteServiceAccountResponse, crate::error::Error> {
748        let mut path = format!(
749            "/auth/service-accounts/{}",
750            urlencoding::encode(&service_account_id)
751        );
752        if let Some(query) = &query {
753            let mut q: Vec<String> = Vec::new();
754            if let Some(v) = &query.force {
755                q.push(format!("force={}", urlencoding::encode(&v.to_string())));
756            }
757            if !q.is_empty() {
758                path.push('?');
759                path.push_str(&q.join("&"));
760            }
761        }
762        self.client
763            .request::<DeleteServiceAccountResponse>(reqwest::Method::DELETE, &path, None, true)
764            .await
765    }
766
767    /// Activate a specific Service Account.
768    pub async fn activate_service_account(
769        &self,
770        service_account_id: String,
771    ) -> Result<ActivateServiceAccountResponse, crate::error::Error> {
772        let path = format!(
773            "/auth/service-accounts/{}/activate",
774            urlencoding::encode(&service_account_id)
775        );
776        self.client
777            .request::<ActivateServiceAccountResponse>(reqwest::Method::PUT, &path, None, true)
778            .await
779    }
780
781    /// Deactivate a specific Service Account.
782    pub async fn deactivate_service_account(
783        &self,
784        service_account_id: String,
785        body: DeactivateServiceAccountRequest,
786    ) -> Result<DeactivateServiceAccountResponse, crate::error::Error> {
787        let path = format!(
788            "/auth/service-accounts/{}/deactivate",
789            urlencoding::encode(&service_account_id)
790        );
791        let body = serde_json::to_value(&body)?;
792        self.client
793            .request::<DeactivateServiceAccountResponse>(
794                reqwest::Method::PUT,
795                &path,
796                Some(&body),
797                true,
798            )
799            .await
800    }
801
802    /// Activate a specific User.
803    pub async fn activate_user(
804        &self,
805        user_id: String,
806    ) -> Result<ActivateUserResponse, crate::error::Error> {
807        let path = format!("/auth/users/{}/activate", urlencoding::encode(&user_id));
808        self.client
809            .request::<ActivateUserResponse>(reqwest::Method::PUT, &path, None, true)
810            .await
811    }
812
813    /// Deactivate a specific User.
814    pub async fn deactivate_user(
815        &self,
816        user_id: String,
817    ) -> Result<DeactivateUserResponse, crate::error::Error> {
818        let path = format!("/auth/users/{}/deactivate", urlencoding::encode(&user_id));
819        self.client
820            .request::<DeactivateUserResponse>(reqwest::Method::PUT, &path, None, true)
821            .await
822    }
823
824    /// Retrieve information about a specific User.
825    pub async fn get_user(&self, user_id: String) -> Result<GetUserResponse, crate::error::Error> {
826        let path = format!("/auth/users/{}", urlencoding::encode(&user_id));
827        self.client
828            .request::<GetUserResponse>(reqwest::Method::GET, &path, None, false)
829            .await
830    }
831
832    /// Update a specific User.
833    pub async fn update_user(
834        &self,
835        user_id: String,
836        body: UpdateUserRequest,
837    ) -> Result<UpdateUserResponse, crate::error::Error> {
838        let path = format!("/auth/users/{}", urlencoding::encode(&user_id));
839        let body = serde_json::to_value(&body)?;
840        self.client
841            .request::<UpdateUserResponse>(reqwest::Method::PUT, &path, Some(&body), true)
842            .await
843    }
844
845    /// Delete a specific User.
846    pub async fn delete_user(
847        &self,
848        user_id: String,
849    ) -> Result<DeleteUserResponse, crate::error::Error> {
850        let path = format!("/auth/users/{}", urlencoding::encode(&user_id));
851        self.client
852            .request::<DeleteUserResponse>(reqwest::Method::DELETE, &path, None, true)
853            .await
854    }
855
856    /// List all Users in your organization.
857    pub async fn list_users(
858        &self,
859        query: Option<ListUsersQuery>,
860    ) -> Result<ListUsersResponse, crate::error::Error> {
861        let mut path = String::from("/auth/users");
862        if let Some(query) = &query {
863            let mut q: Vec<String> = Vec::new();
864            if let Some(v) = &query.limit {
865                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
866            }
867            if let Some(v) = &query.pagination_token {
868                q.push(format!(
869                    "paginationToken={}",
870                    urlencoding::encode(&v.to_string())
871                ));
872            }
873            if let Some(v) = &query.kind {
874                q.push(format!("kind={}", urlencoding::encode(&v.to_string())));
875            }
876            if !q.is_empty() {
877                path.push('?');
878                path.push_str(&q.join("&"));
879            }
880        }
881        self.client
882            .request::<ListUsersResponse>(reqwest::Method::GET, &path, None, false)
883            .await
884    }
885
886    /// 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.
887    ///   
888    ///   <Note>If you want the created User to not know about about Dfns, and don't want him to
889    ///   receive the registration email from Dfns, you should rather use the Delegated Registration
890    pub async fn create_user(
891        &self,
892        body: CreateUserRequest,
893    ) -> Result<CreateUserResponse, crate::error::Error> {
894        let path = String::from("/auth/users");
895        let body = serde_json::to_value(&body)?;
896        self.client
897            .request::<CreateUserResponse>(reqwest::Method::POST, &path, Some(&body), true)
898            .await
899    }
900
901    /// Invite an existing Tenant User in the caller's org. The invited Tenant User starts without any permissions within the org.
902    pub async fn invite_tenant_user(
903        &self,
904        body: InviteTenantUserRequest,
905    ) -> Result<InviteTenantUserResponse, crate::error::Error> {
906        let path = String::from("/auth/users/invite");
907        let body = serde_json::to_value(&body)?;
908        self.client
909            .request::<InviteTenantUserResponse>(reqwest::Method::POST, &path, Some(&body), true)
910            .await
911    }
912}