// Code generated by rust-sdk-generator. DO NOT EDIT.
#[allow(unused_imports)]
use super::types::*;
/// Delegated client for auth operations. Signed operations are split into
/// init/complete pairs so the challenge can be signed on the user side.
#[derive(Clone)]
pub struct DelegatedAuthClient {
client: crate::client::Client,
}
impl DelegatedAuthClient {
pub fn new(client: crate::client::Client) -> Self {
DelegatedAuthClient { 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
}
/// Starts delegated signing for createCredential: returns the challenge to sign.
/// Pass the signed assertion to create_credential_complete with the same arguments.
pub async fn create_credential_init(
&self,
body: CreateCredentialRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = String::from("/auth/credentials");
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::POST, &path, Some(&body))
.await
}
/// Finishes delegated signing for createCredential: submits the signed challenge
/// and issues the request.
pub async fn create_credential_complete(
&self,
body: CreateCredentialRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<CreateCredentialResponse, crate::error::Error> {
let path = String::from("/auth/credentials");
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<CreateCredentialResponse>(
reqwest::Method::POST,
&path,
Some(&body),
&user_action,
)
.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
}
/// Starts delegated signing for activateCredential: returns the challenge to sign.
/// Pass the signed assertion to activate_credential_complete with the same arguments.
pub async fn activate_credential_init(
&self,
body: ActivateCredentialRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = String::from("/auth/credentials/activate");
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::PUT, &path, Some(&body))
.await
}
/// Finishes delegated signing for activateCredential: submits the signed challenge
/// and issues the request.
pub async fn activate_credential_complete(
&self,
body: ActivateCredentialRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<ActivateCredentialResponse, crate::error::Error> {
let path = String::from("/auth/credentials/activate");
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<ActivateCredentialResponse>(
reqwest::Method::PUT,
&path,
Some(&body),
&user_action,
)
.await
}
/// Starts delegated signing for deleteCredential: returns the challenge to sign.
/// Pass the signed assertion to delete_credential_complete with the same arguments.
pub async fn delete_credential_init(
&self,
credential_uuid: String,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = format!(
"/auth/credentials/{}",
urlencoding::encode(&credential_uuid)
);
self.client
.create_user_action_challenge(reqwest::Method::DELETE, &path, None)
.await
}
/// Finishes delegated signing for deleteCredential: submits the signed challenge
/// and issues the request.
pub async fn delete_credential_complete(
&self,
credential_uuid: String,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<DeleteCredentialResponse, crate::error::Error> {
let path = format!(
"/auth/credentials/{}",
urlencoding::encode(&credential_uuid)
);
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<DeleteCredentialResponse>(
reqwest::Method::DELETE,
&path,
None,
&user_action,
)
.await
}
/// Starts delegated signing for deactivateCredential: returns the challenge to sign.
/// Pass the signed assertion to deactivate_credential_complete with the same arguments.
pub async fn deactivate_credential_init(
&self,
body: DeactivateCredentialRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = String::from("/auth/credentials/deactivate");
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::PUT, &path, Some(&body))
.await
}
/// Finishes delegated signing for deactivateCredential: submits the signed challenge
/// and issues the request.
pub async fn deactivate_credential_complete(
&self,
body: DeactivateCredentialRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<DeactivateCredentialResponse, crate::error::Error> {
let path = String::from("/auth/credentials/deactivate");
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<DeactivateCredentialResponse>(
reqwest::Method::PUT,
&path,
Some(&body),
&user_action,
)
.await
}
/// Starts delegated signing for createCredentialCode: returns the challenge to sign.
/// Pass the signed assertion to create_credential_code_complete with the same arguments.
pub async fn create_credential_code_init(
&self,
body: CreateCredentialCodeRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = String::from("/auth/credentials/code");
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::POST, &path, Some(&body))
.await
}
/// Finishes delegated signing for createCredentialCode: submits the signed challenge
/// and issues the request.
pub async fn create_credential_code_complete(
&self,
body: CreateCredentialCodeRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<CreateCredentialCodeResponse, crate::error::Error> {
let path = String::from("/auth/credentials/code");
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<CreateCredentialCodeResponse>(
reqwest::Method::POST,
&path,
Some(&body),
&user_action,
)
.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
}
/// Starts delegated signing for delegatedLogin: returns the challenge to sign.
/// Pass the signed assertion to delegated_login_complete with the same arguments.
pub async fn delegated_login_init(
&self,
body: DelegatedLoginRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = String::from("/auth/login/delegated");
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::POST, &path, Some(&body))
.await
}
/// Finishes delegated signing for delegatedLogin: submits the signed challenge
/// and issues the request.
pub async fn delegated_login_complete(
&self,
body: DelegatedLoginRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<DelegatedLoginResponse, crate::error::Error> {
let path = String::from("/auth/login/delegated");
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<DelegatedLoginResponse>(
reqwest::Method::POST,
&path,
Some(&body),
&user_action,
)
.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
}
/// Starts delegated signing for createPersonalAccessToken: returns the challenge to sign.
/// Pass the signed assertion to create_personal_access_token_complete with the same arguments.
pub async fn create_personal_access_token_init(
&self,
body: CreatePersonalAccessTokenRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = String::from("/auth/pats");
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::POST, &path, Some(&body))
.await
}
/// Finishes delegated signing for createPersonalAccessToken: submits the signed challenge
/// and issues the request.
pub async fn create_personal_access_token_complete(
&self,
body: CreatePersonalAccessTokenRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<CreatePersonalAccessTokenResponse, crate::error::Error> {
let path = String::from("/auth/pats");
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<CreatePersonalAccessTokenResponse>(
reqwest::Method::POST,
&path,
Some(&body),
&user_action,
)
.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
}
/// Starts delegated signing for updatePersonalAccessToken: returns the challenge to sign.
/// Pass the signed assertion to update_personal_access_token_complete with the same arguments.
pub async fn update_personal_access_token_init(
&self,
token_id: String,
body: UpdatePersonalAccessTokenRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = format!("/auth/pats/{}", urlencoding::encode(&token_id));
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::PUT, &path, Some(&body))
.await
}
/// Finishes delegated signing for updatePersonalAccessToken: submits the signed challenge
/// and issues the request.
pub async fn update_personal_access_token_complete(
&self,
token_id: String,
body: UpdatePersonalAccessTokenRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<UpdatePersonalAccessTokenResponse, crate::error::Error> {
let path = format!("/auth/pats/{}", urlencoding::encode(&token_id));
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<UpdatePersonalAccessTokenResponse>(
reqwest::Method::PUT,
&path,
Some(&body),
&user_action,
)
.await
}
/// Starts delegated signing for deletePersonalAccessToken: returns the challenge to sign.
/// Pass the signed assertion to delete_personal_access_token_complete with the same arguments.
pub async fn delete_personal_access_token_init(
&self,
token_id: String,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = format!("/auth/pats/{}", urlencoding::encode(&token_id));
self.client
.create_user_action_challenge(reqwest::Method::DELETE, &path, None)
.await
}
/// Finishes delegated signing for deletePersonalAccessToken: submits the signed challenge
/// and issues the request.
pub async fn delete_personal_access_token_complete(
&self,
token_id: String,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<DeletePersonalAccessTokenResponse, crate::error::Error> {
let path = format!("/auth/pats/{}", urlencoding::encode(&token_id));
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<DeletePersonalAccessTokenResponse>(
reqwest::Method::DELETE,
&path,
None,
&user_action,
)
.await
}
/// Starts delegated signing for activatePersonalAccessToken: returns the challenge to sign.
/// Pass the signed assertion to activate_personal_access_token_complete with the same arguments.
pub async fn activate_personal_access_token_init(
&self,
token_id: String,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = format!("/auth/pats/{}/activate", urlencoding::encode(&token_id));
self.client
.create_user_action_challenge(reqwest::Method::PUT, &path, None)
.await
}
/// Finishes delegated signing for activatePersonalAccessToken: submits the signed challenge
/// and issues the request.
pub async fn activate_personal_access_token_complete(
&self,
token_id: String,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<ActivatePersonalAccessTokenResponse, crate::error::Error> {
let path = format!("/auth/pats/{}/activate", urlencoding::encode(&token_id));
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<ActivatePersonalAccessTokenResponse>(
reqwest::Method::PUT,
&path,
None,
&user_action,
)
.await
}
/// Starts delegated signing for deactivatePersonalAccessToken: returns the challenge to sign.
/// Pass the signed assertion to deactivate_personal_access_token_complete with the same arguments.
pub async fn deactivate_personal_access_token_init(
&self,
token_id: String,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = format!("/auth/pats/{}/deactivate", urlencoding::encode(&token_id));
self.client
.create_user_action_challenge(reqwest::Method::PUT, &path, None)
.await
}
/// Finishes delegated signing for deactivatePersonalAccessToken: submits the signed challenge
/// and issues the request.
pub async fn deactivate_personal_access_token_complete(
&self,
token_id: String,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<DeactivatePersonalAccessTokenResponse, crate::error::Error> {
let path = format!("/auth/pats/{}/deactivate", urlencoding::encode(&token_id));
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<DeactivatePersonalAccessTokenResponse>(
reqwest::Method::PUT,
&path,
None,
&user_action,
)
.await
}
/// Starts delegated signing for createDelegatedRecoveryChallenge: returns the challenge to sign.
/// Pass the signed assertion to create_delegated_recovery_challenge_complete with the same arguments.
pub async fn create_delegated_recovery_challenge_init(
&self,
body: CreateDelegatedRecoveryChallengeRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = String::from("/auth/recover/user/delegated");
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::POST, &path, Some(&body))
.await
}
/// Finishes delegated signing for createDelegatedRecoveryChallenge: submits the signed challenge
/// and issues the request.
pub async fn create_delegated_recovery_challenge_complete(
&self,
body: CreateDelegatedRecoveryChallengeRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<CreateDelegatedRecoveryChallengeResponse, crate::error::Error> {
let path = String::from("/auth/recover/user/delegated");
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<CreateDelegatedRecoveryChallengeResponse>(
reqwest::Method::POST,
&path,
Some(&body),
&user_action,
)
.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
}
/// Starts delegated signing for createDelegatedRegistrationChallenge: returns the challenge to sign.
/// Pass the signed assertion to create_delegated_registration_challenge_complete with the same arguments.
pub async fn create_delegated_registration_challenge_init(
&self,
body: CreateDelegatedRegistrationChallengeRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = String::from("/auth/registration/delegated");
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::POST, &path, Some(&body))
.await
}
/// Finishes delegated signing for createDelegatedRegistrationChallenge: submits the signed challenge
/// and issues the request.
pub async fn create_delegated_registration_challenge_complete(
&self,
body: CreateDelegatedRegistrationChallengeRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<CreateDelegatedRegistrationChallengeResponse, crate::error::Error> {
let path = String::from("/auth/registration/delegated");
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<CreateDelegatedRegistrationChallengeResponse>(
reqwest::Method::POST,
&path,
Some(&body),
&user_action,
)
.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
}
/// Starts delegated signing for createServiceAccount: returns the challenge to sign.
/// Pass the signed assertion to create_service_account_complete with the same arguments.
pub async fn create_service_account_init(
&self,
body: CreateServiceAccountRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = String::from("/auth/service-accounts");
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::POST, &path, Some(&body))
.await
}
/// Finishes delegated signing for createServiceAccount: submits the signed challenge
/// and issues the request.
pub async fn create_service_account_complete(
&self,
body: CreateServiceAccountRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<CreateServiceAccountResponse, crate::error::Error> {
let path = String::from("/auth/service-accounts");
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<CreateServiceAccountResponse>(
reqwest::Method::POST,
&path,
Some(&body),
&user_action,
)
.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
}
/// Starts delegated signing for updateServiceAccount: returns the challenge to sign.
/// Pass the signed assertion to update_service_account_complete with the same arguments.
pub async fn update_service_account_init(
&self,
service_account_id: String,
body: UpdateServiceAccountRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = format!(
"/auth/service-accounts/{}",
urlencoding::encode(&service_account_id)
);
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::PUT, &path, Some(&body))
.await
}
/// Finishes delegated signing for updateServiceAccount: submits the signed challenge
/// and issues the request.
pub async fn update_service_account_complete(
&self,
service_account_id: String,
body: UpdateServiceAccountRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<UpdateServiceAccountResponse, crate::error::Error> {
let path = format!(
"/auth/service-accounts/{}",
urlencoding::encode(&service_account_id)
);
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<UpdateServiceAccountResponse>(
reqwest::Method::PUT,
&path,
Some(&body),
&user_action,
)
.await
}
/// Starts delegated signing for deleteServiceAccount: returns the challenge to sign.
/// Pass the signed assertion to delete_service_account_complete with the same arguments.
pub async fn delete_service_account_init(
&self,
service_account_id: String,
query: Option<DeleteServiceAccountQuery>,
) -> Result<crate::signer::UserActionChallenge, 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
.create_user_action_challenge(reqwest::Method::DELETE, &path, None)
.await
}
/// Finishes delegated signing for deleteServiceAccount: submits the signed challenge
/// and issues the request.
pub async fn delete_service_account_complete(
&self,
service_account_id: String,
query: Option<DeleteServiceAccountQuery>,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> 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("&"));
}
}
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<DeleteServiceAccountResponse>(
reqwest::Method::DELETE,
&path,
None,
&user_action,
)
.await
}
/// Starts delegated signing for activateServiceAccount: returns the challenge to sign.
/// Pass the signed assertion to activate_service_account_complete with the same arguments.
pub async fn activate_service_account_init(
&self,
service_account_id: String,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = format!(
"/auth/service-accounts/{}/activate",
urlencoding::encode(&service_account_id)
);
self.client
.create_user_action_challenge(reqwest::Method::PUT, &path, None)
.await
}
/// Finishes delegated signing for activateServiceAccount: submits the signed challenge
/// and issues the request.
pub async fn activate_service_account_complete(
&self,
service_account_id: String,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<ActivateServiceAccountResponse, crate::error::Error> {
let path = format!(
"/auth/service-accounts/{}/activate",
urlencoding::encode(&service_account_id)
);
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<ActivateServiceAccountResponse>(
reqwest::Method::PUT,
&path,
None,
&user_action,
)
.await
}
/// Starts delegated signing for deactivateServiceAccount: returns the challenge to sign.
/// Pass the signed assertion to deactivate_service_account_complete with the same arguments.
pub async fn deactivate_service_account_init(
&self,
service_account_id: String,
body: DeactivateServiceAccountRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = format!(
"/auth/service-accounts/{}/deactivate",
urlencoding::encode(&service_account_id)
);
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::PUT, &path, Some(&body))
.await
}
/// Finishes delegated signing for deactivateServiceAccount: submits the signed challenge
/// and issues the request.
pub async fn deactivate_service_account_complete(
&self,
service_account_id: String,
body: DeactivateServiceAccountRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<DeactivateServiceAccountResponse, crate::error::Error> {
let path = format!(
"/auth/service-accounts/{}/deactivate",
urlencoding::encode(&service_account_id)
);
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<DeactivateServiceAccountResponse>(
reqwest::Method::PUT,
&path,
Some(&body),
&user_action,
)
.await
}
/// Starts delegated signing for activateUser: returns the challenge to sign.
/// Pass the signed assertion to activate_user_complete with the same arguments.
pub async fn activate_user_init(
&self,
user_id: String,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = format!("/auth/users/{}/activate", urlencoding::encode(&user_id));
self.client
.create_user_action_challenge(reqwest::Method::PUT, &path, None)
.await
}
/// Finishes delegated signing for activateUser: submits the signed challenge
/// and issues the request.
pub async fn activate_user_complete(
&self,
user_id: String,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<ActivateUserResponse, crate::error::Error> {
let path = format!("/auth/users/{}/activate", urlencoding::encode(&user_id));
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<ActivateUserResponse>(
reqwest::Method::PUT,
&path,
None,
&user_action,
)
.await
}
/// Starts delegated signing for deactivateUser: returns the challenge to sign.
/// Pass the signed assertion to deactivate_user_complete with the same arguments.
pub async fn deactivate_user_init(
&self,
user_id: String,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = format!("/auth/users/{}/deactivate", urlencoding::encode(&user_id));
self.client
.create_user_action_challenge(reqwest::Method::PUT, &path, None)
.await
}
/// Finishes delegated signing for deactivateUser: submits the signed challenge
/// and issues the request.
pub async fn deactivate_user_complete(
&self,
user_id: String,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<DeactivateUserResponse, crate::error::Error> {
let path = format!("/auth/users/{}/deactivate", urlencoding::encode(&user_id));
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<DeactivateUserResponse>(
reqwest::Method::PUT,
&path,
None,
&user_action,
)
.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
}
/// Starts delegated signing for updateUser: returns the challenge to sign.
/// Pass the signed assertion to update_user_complete with the same arguments.
pub async fn update_user_init(
&self,
user_id: String,
body: UpdateUserRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = format!("/auth/users/{}", urlencoding::encode(&user_id));
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::PUT, &path, Some(&body))
.await
}
/// Finishes delegated signing for updateUser: submits the signed challenge
/// and issues the request.
pub async fn update_user_complete(
&self,
user_id: String,
body: UpdateUserRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<UpdateUserResponse, crate::error::Error> {
let path = format!("/auth/users/{}", urlencoding::encode(&user_id));
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<UpdateUserResponse>(
reqwest::Method::PUT,
&path,
Some(&body),
&user_action,
)
.await
}
/// Starts delegated signing for deleteUser: returns the challenge to sign.
/// Pass the signed assertion to delete_user_complete with the same arguments.
pub async fn delete_user_init(
&self,
user_id: String,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = format!("/auth/users/{}", urlencoding::encode(&user_id));
self.client
.create_user_action_challenge(reqwest::Method::DELETE, &path, None)
.await
}
/// Finishes delegated signing for deleteUser: submits the signed challenge
/// and issues the request.
pub async fn delete_user_complete(
&self,
user_id: String,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<DeleteUserResponse, crate::error::Error> {
let path = format!("/auth/users/{}", urlencoding::encode(&user_id));
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<DeleteUserResponse>(
reqwest::Method::DELETE,
&path,
None,
&user_action,
)
.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
}
/// Starts delegated signing for createUser: returns the challenge to sign.
/// Pass the signed assertion to create_user_complete with the same arguments.
pub async fn create_user_init(
&self,
body: CreateUserRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = String::from("/auth/users");
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::POST, &path, Some(&body))
.await
}
/// Finishes delegated signing for createUser: submits the signed challenge
/// and issues the request.
pub async fn create_user_complete(
&self,
body: CreateUserRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<CreateUserResponse, crate::error::Error> {
let path = String::from("/auth/users");
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<CreateUserResponse>(
reqwest::Method::POST,
&path,
Some(&body),
&user_action,
)
.await
}
/// Starts delegated signing for inviteTenantUser: returns the challenge to sign.
/// Pass the signed assertion to invite_tenant_user_complete with the same arguments.
pub async fn invite_tenant_user_init(
&self,
body: InviteTenantUserRequest,
) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
let path = String::from("/auth/users/invite");
let body = serde_json::to_value(&body)?;
self.client
.create_user_action_challenge(reqwest::Method::POST, &path, Some(&body))
.await
}
/// Finishes delegated signing for inviteTenantUser: submits the signed challenge
/// and issues the request.
pub async fn invite_tenant_user_complete(
&self,
body: InviteTenantUserRequest,
challenge_identifier: String,
assertion: crate::signer::CredentialAssertion,
) -> Result<InviteTenantUserResponse, crate::error::Error> {
let path = String::from("/auth/users/invite");
let body = serde_json::to_value(&body)?;
let user_action = self
.client
.complete_user_action_signing(challenge_identifier, &assertion)
.await?;
self.client
.request_with_user_action::<InviteTenantUserResponse>(
reqwest::Method::POST,
&path,
Some(&body),
&user_action,
)
.await
}
}