bitwarden_auth/
auth_client.rs

1use bitwarden_core::Client;
2#[cfg(feature = "wasm")]
3use wasm_bindgen::prelude::*;
4
5use crate::{identity::IdentityClient, send_access::SendAccessClient};
6
7/// Subclient containing auth functionality.
8#[derive(Clone)]
9#[cfg_attr(feature = "wasm", wasm_bindgen)]
10pub struct AuthClient {
11    // TODO: The AuthClient should probably not contain the whole bitwarden-core client.
12    // Instead, it should contain the ApiConfigurations and Tokens struct to do API requests and
13    // handle token renewals, and those structs should be shared between core and auth.
14    pub(crate) client: Client,
15}
16
17impl AuthClient {
18    /// Constructs a new `AuthClient` with the given `Client`.
19    pub fn new(client: Client) -> Self {
20        Self { client }
21    }
22}
23
24#[cfg_attr(feature = "wasm", wasm_bindgen)]
25impl AuthClient {
26    /// Client for identity functionality
27    pub fn identity(&self) -> IdentityClient {
28        IdentityClient::new(self.client.clone())
29    }
30
31    /// Client for send access functionality
32    pub fn send_access(&self) -> SendAccessClient {
33        SendAccessClient::new(self.client.clone())
34    }
35}
36
37/// Extension trait for `Client` to provide access to the `AuthClient`.
38pub trait AuthClientExt {
39    /// Creates a new `AuthClient` instance.
40    fn auth_new(&self) -> AuthClient;
41}
42
43impl AuthClientExt for Client {
44    fn auth_new(&self) -> AuthClient {
45        AuthClient {
46            client: self.clone(),
47        }
48    }
49}