From fb06ee2a10d1f015d2a3d3cf75a42f1ea0c261ee Mon Sep 17 00:00:00 2001 From: Jared Snider Date: Thu, 11 Dec 2025 14:53:06 -0500 Subject: [PATCH 1/2] bw-auth - Add uniffi support --- crates/bitwarden-auth/Cargo.toml | 4 ++++ crates/bitwarden-auth/src/lib.rs | 4 ++++ .../src/send_access/access_token_response.rs | 5 +++++ .../src/send_access/api/token_api_error_response.rs | 3 +++ crates/bitwarden-auth/uniffi.toml | 9 +++++++++ 5 files changed, 25 insertions(+) create mode 100644 crates/bitwarden-auth/uniffi.toml diff --git a/crates/bitwarden-auth/Cargo.toml b/crates/bitwarden-auth/Cargo.toml index 416b18449..41c88f454 100644 --- a/crates/bitwarden-auth/Cargo.toml +++ b/crates/bitwarden-auth/Cargo.toml @@ -21,6 +21,10 @@ wasm = [ "dep:wasm-bindgen", "dep:wasm-bindgen-futures" ] # WASM support +uniffi = [ + "bitwarden-core/uniffi", + "dep:uniffi" +] # Uniffi bindings # Note: dependencies must be alphabetized to pass the cargo sort check in the CI pipeline. [dependencies] diff --git a/crates/bitwarden-auth/src/lib.rs b/crates/bitwarden-auth/src/lib.rs index db5dc561f..2bb79a177 100644 --- a/crates/bitwarden-auth/src/lib.rs +++ b/crates/bitwarden-auth/src/lib.rs @@ -1,5 +1,9 @@ #![doc = include_str!("../README.md")] +// Enable uniffi scaffolding when the "uniffi" feature is enabled. +#[cfg(feature = "uniffi")] +uniffi::setup_scaffolding!(); + mod auth_client; pub mod identity; diff --git a/crates/bitwarden-auth/src/send_access/access_token_response.rs b/crates/bitwarden-auth/src/send_access/access_token_response.rs index 29e7cdbc8..43dd56a8f 100644 --- a/crates/bitwarden-auth/src/send_access/access_token_response.rs +++ b/crates/bitwarden-auth/src/send_access/access_token_response.rs @@ -10,6 +10,7 @@ use crate::send_access::api::{SendAccessTokenApiErrorResponse, SendAccessTokenAp derive(tsify::Tsify), tsify(into_wasm_abi, from_wasm_abi) )] +#[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[derive(Debug)] pub struct SendAccessTokenResponse { /// The actual token string. @@ -73,3 +74,7 @@ impl From for SendAccessTokenError { tsify(into_wasm_abi, from_wasm_abi) )] pub struct UnexpectedIdentityError(pub String); + +// Newtype wrapper for unexpected identity errors for uniffi compatibility. +#[cfg(feature = "uniffi")] // only compile this when uniffi feature is enabled +uniffi::custom_newtype!(UnexpectedIdentityError, String); diff --git a/crates/bitwarden-auth/src/send_access/api/token_api_error_response.rs b/crates/bitwarden-auth/src/send_access/api/token_api_error_response.rs index 1c17cca0c..323bdfada 100644 --- a/crates/bitwarden-auth/src/send_access/api/token_api_error_response.rs +++ b/crates/bitwarden-auth/src/send_access/api/token_api_error_response.rs @@ -4,6 +4,7 @@ use tsify::Tsify; #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] #[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))] +#[cfg_attr(feature = "uniffi", derive(uniffi::Error))] #[serde(rename_all = "snake_case")] /// Invalid request errors - typically due to missing parameters. pub enum SendAccessTokenInvalidRequestError { @@ -26,6 +27,7 @@ pub enum SendAccessTokenInvalidRequestError { #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] #[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))] +#[cfg_attr(feature = "uniffi", derive(uniffi::Error))] #[serde(rename_all = "snake_case")] /// Invalid grant errors - typically due to invalid credentials. pub enum SendAccessTokenInvalidGrantError { @@ -51,6 +53,7 @@ pub enum SendAccessTokenInvalidGrantError { #[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] #[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))] +#[cfg_attr(feature = "uniffi", derive(uniffi::Error))] #[serde(rename_all = "snake_case")] #[serde(tag = "error")] // ^ "error" becomes the variant discriminator which matches against the rename annotations; diff --git a/crates/bitwarden-auth/uniffi.toml b/crates/bitwarden-auth/uniffi.toml new file mode 100644 index 000000000..5ebc54bae --- /dev/null +++ b/crates/bitwarden-auth/uniffi.toml @@ -0,0 +1,9 @@ +[bindings.kotlin] +package_name = "com.bitwarden.auth" +generate_immutable_records = true +android = true + +[bindings.swift] +ffi_module_name = "BitwardenAuthFFI" +module_name = "BitwardenAuth" +generate_immutable_records = true \ No newline at end of file From 410c830a95cb1291a0ece1ad4bff4566e2011dc8 Mon Sep 17 00:00:00 2001 From: Jared Snider Date: Thu, 11 Dec 2025 14:58:23 -0500 Subject: [PATCH 2/2] cargo sort + add uniffi as dep to bw-auth --- crates/bitwarden-auth/Cargo.toml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/bitwarden-auth/Cargo.toml b/crates/bitwarden-auth/Cargo.toml index 41c88f454..82614d4b9 100644 --- a/crates/bitwarden-auth/Cargo.toml +++ b/crates/bitwarden-auth/Cargo.toml @@ -21,10 +21,7 @@ wasm = [ "dep:wasm-bindgen", "dep:wasm-bindgen-futures" ] # WASM support -uniffi = [ - "bitwarden-core/uniffi", - "dep:uniffi" -] # Uniffi bindings +uniffi = ["bitwarden-core/uniffi", "dep:uniffi"] # Uniffi bindings # Note: dependencies must be alphabetized to pass the cargo sort check in the CI pipeline. [dependencies] @@ -35,6 +32,7 @@ reqwest = { workspace = true } serde = { workspace = true } thiserror = { workspace = true } tsify = { workspace = true, optional = true } +uniffi = { workspace = true, optional = true } wasm-bindgen = { workspace = true, optional = true } wasm-bindgen-futures = { workspace = true, optional = true }