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    ///
34    /// `accept_organization_invite` defaults to `true` when not set.
35    #[uniffi::method(default(accept_organization_invite = None))]
36    pub async fn post_keys_for_key_connector_registration(
37        &self,
38        key_connector_url: String,
39        sso_org_identifier: String,
40        accept_organization_invite: Option<bool>,
41    ) -> Result<KeyConnectorRegistrationResult, BitwardenError> {
42        Ok(self
43            .0
44            .auth_new()
45            .registration()
46            .post_keys_for_key_connector_registration(
47                key_connector_url,
48                sso_org_identifier,
49                accept_organization_invite,
50            )
51            .await?)
52    }
53
54    /// Initializes a new cryptographic state for a user and posts it to the server;
55    /// enrolls the user to master password unlock.
56    pub async fn post_keys_for_jit_password_registration(
57        &self,
58        request: JitMasterPasswordRegistrationRequest,
59    ) -> Result<JitMasterPasswordRegistrationResponse, BitwardenError> {
60        Ok(self
61            .0
62            .auth_new()
63            .registration()
64            .post_keys_for_jit_password_registration(request)
65            .await?)
66    }
67
68    /// Initializes new password-based cryptographic state for a user
69    /// and posts the state to the server
70    pub async fn post_keys_for_user_password_registration(
71        &self,
72        request: UserMasterPasswordRegistrationRequest,
73    ) -> Result<UserMasterPasswordRegistrationResponse, BitwardenError> {
74        Ok(self
75            .0
76            .auth_new()
77            .registration()
78            .post_keys_for_user_password_registration(request)
79            .await?)
80    }
81}