Skip to content

Commit a09e691

Browse files
authored
[PM-28748] Add RegistrationClient (#579)
## 🎟️ Tracking https://bitwarden.atlassian.net/browse/PM-28748 ## 📔 Objective <!-- Describe what the purpose of this PR is, for example what bug you're fixing or new feature you're adding. --> Adds a stub for the registration client. This will be used by all 4 setup methods - JIT Password, JIT TDE, JIT Key-Connector and regular master password. The cryptography code will live in a separate client. As described in the tech breakdown, the client will call high level KM APIs, then call HTTP requests, and return the results. It will not set to state in the current work. ## 🚨 Breaking Changes <!-- Does this PR introduce any breaking changes? If so, please describe the impact and migration path for clients. If you're unsure, the automated TypeScript compatibility check will run when you open/update this PR and provide feedback. For breaking changes: 1. Describe what changed in the client interface 2. Explain why the change was necessary 3. Provide migration steps for client developers 4. Link to any paired client PRs if needed Otherwise, you can remove this section. --> ## ⏰ Reminders before review - Contributor guidelines followed - All formatters and local linters executed and passed - Written new unit and / or integration tests where applicable - Protected functional changes with optionality (feature flags) - Used internationalization (i18n) for all UI strings - CI builds passed - Communicated to DevOps any deployment requirements - Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team ## 🦮 Reviewer guidelines <!-- Suggested interactions but feel free to use (or not) as you desire! --> - 👍 (`:+1:`) or similar for great changes - 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info - ❓ (`:question:`) for questions - 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion - 🎨 (`:art:`) for suggestions / improvements - ❌ (`:x:`) or ⚠️ (`:warning:`) for more significant problems or concerns needing attention - 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or indications of technical debt - ⛏ (`:pick:`) for minor or nitpick changes
1 parent 7f09fd2 commit a09e691

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

crates/bitwarden-auth/src/auth_client.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use bitwarden_core::Client;
22
#[cfg(feature = "wasm")]
33
use wasm_bindgen::prelude::*;
44

5-
use crate::{identity::IdentityClient, send_access::SendAccessClient};
5+
use crate::{
6+
identity::IdentityClient, registration::RegistrationClient, send_access::SendAccessClient,
7+
};
68

79
/// Subclient containing auth functionality.
810
#[derive(Clone)]
@@ -32,6 +34,11 @@ impl AuthClient {
3234
pub fn send_access(&self) -> SendAccessClient {
3335
SendAccessClient::new(self.client.clone())
3436
}
37+
38+
/// Client for initializing user account cryptography and unlock methods after JIT provisioning
39+
pub fn registration(&self) -> RegistrationClient {
40+
RegistrationClient::new(self.client.clone())
41+
}
3542
}
3643

3744
/// Extension trait for `Client` to provide access to the `AuthClient`.

crates/bitwarden-auth/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
mod auth_client;
44

55
pub mod identity;
6+
pub mod registration;
67
pub mod send_access;
78

89
pub(crate) mod api; // keep internal to crate
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//! Client for account registration and cryptography initialization related API methods.
2+
//! It is used both for the initial registration request in the case of password registrations,
3+
//! and for cryptography initialization for a jit provisioned user. After a method
4+
//! on this client is called, the user account should have initialized account keys, an
5+
//! authentication method such as SSO or master password, and a decryption method such as
6+
//! key-connector, TDE, or master password.
7+
8+
use bitwarden_core::Client;
9+
#[cfg(feature = "wasm")]
10+
use wasm_bindgen::prelude::*;
11+
12+
/// Client for initializing a user account.
13+
#[derive(Clone)]
14+
#[cfg_attr(feature = "wasm", wasm_bindgen)]
15+
pub struct RegistrationClient {
16+
#[allow(dead_code)]
17+
pub(crate) client: Client,
18+
}
19+
20+
impl RegistrationClient {
21+
pub(crate) fn new(client: Client) -> Self {
22+
Self { client }
23+
}
24+
}
25+
#[cfg_attr(feature = "wasm", wasm_bindgen)]
26+
impl RegistrationClient {
27+
/// Example method to demonstrate usage of the client.
28+
/// Note: This will be removed once real methods are implemented.
29+
#[allow(unused)]
30+
async fn example(&self) {
31+
let client = &self.client.internal;
32+
#[allow(unused_variables)]
33+
let api_client = &client.get_api_configurations().await.api_client;
34+
// Do API request here. It will be authenticated using the client's tokens.
35+
}
36+
}

0 commit comments

Comments
 (0)