Skip to main content

bitwarden_uniffi/auth/
registration.rs

1use bitwarden_auth::{
2    AuthClientExt,
3    registration::{
4        JitMasterPasswordRegistrationRequest, JitMasterPasswordRegistrationResponse,
5        KeyConnectorRegistrationResult, TdeRegistrationRequest, TdeRegistrationResponse,
6        UserMasterPasswordRegistrationRequest, UserMasterPasswordRegistrationResponse,
7    },
8};
9
10use crate::error::BitwardenError;
11
12#[derive(uniffi::Object)]
13pub struct RegistrationClient(pub(crate) bitwarden_core::Client);
14
15#[uniffi::export(async_runtime = "tokio")]
16impl RegistrationClient {
17    /// Initializes a new cryptographic state for a user and posts it to the server; enrolls in
18    /// admin password reset and finally enrolls the user to TDE unlock.
19    pub async fn post_keys_for_tde_registration(
20        &self,
21        request: TdeRegistrationRequest,
22    ) -> Result<TdeRegistrationResponse, BitwardenError> {
23        Ok(self
24            .0
25            .auth_new()
26            .registration()
27            .post_keys_for_tde_registration(request)
28            .await?)
29    }
30
31    /// Initializes a new cryptographic state for a user and posts it to the server; enrolls the
32    /// user to key connector unlock.
33    pub async fn post_keys_for_key_connector_registration(
34        &self,
35        key_connector_url: String,
36        sso_org_identifier: String,
37    ) -> Result<KeyConnectorRegistrationResult, BitwardenError> {
38        Ok(self
39            .0
40            .auth_new()
41            .registration()
42            .post_keys_for_key_connector_registration(key_connector_url, sso_org_identifier)
43            .await?)
44    }
45
46    /// Initializes a new cryptographic state for a user and posts it to the server;
47    /// enrolls the user to master password unlock.
48    pub async fn post_keys_for_jit_password_registration(
49        &self,
50        request: JitMasterPasswordRegistrationRequest,
51    ) -> Result<JitMasterPasswordRegistrationResponse, BitwardenError> {
52        Ok(self
53            .0
54            .auth_new()
55            .registration()
56            .post_keys_for_jit_password_registration(request)
57            .await?)
58    }
59
60    /// Initializes new password-based cryptographic state for a user
61    /// and posts the state to the server
62    pub async fn post_keys_for_user_password_registration(
63        &self,
64        request: UserMasterPasswordRegistrationRequest,
65    ) -> Result<UserMasterPasswordRegistrationResponse, BitwardenError> {
66        Ok(self
67            .0
68            .auth_new()
69            .registration()
70            .post_keys_for_user_password_registration(request)
71            .await?)
72    }
73}