// 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
}
}