Skip to content

Commit bd636a4

Browse files
bw-auth - Add uniffi support (#609)
## 🎟️ Tracking <!-- Paste the link to the Jira or GitHub issue or otherwise describe / point to where this change is coming from. --> n/a but blocks #549 and #596 ## 📔 Objective <!-- Describe what the purpose of this PR is, for example what bug you're fixing or new feature you're adding. --> To add UNIFFI support to the bw-auth crate ## ⏰ 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 fd11c49 commit bd636a4

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

crates/bitwarden-auth/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ wasm = [
2121
"dep:wasm-bindgen",
2222
"dep:wasm-bindgen-futures",
2323
] # WASM support
24+
uniffi = ["bitwarden-core/uniffi", "dep:uniffi"] # Uniffi bindings
2425

2526
# Note: dependencies must be alphabetized to pass the cargo sort check in the CI pipeline.
2627
[dependencies]
@@ -31,6 +32,7 @@ reqwest = { workspace = true }
3132
serde = { workspace = true }
3233
thiserror = { workspace = true }
3334
tsify = { workspace = true, optional = true }
35+
uniffi = { workspace = true, optional = true }
3436
wasm-bindgen = { workspace = true, optional = true }
3537
wasm-bindgen-futures = { workspace = true, optional = true }
3638

crates/bitwarden-auth/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#![doc = include_str!("../README.md")]
22

3+
// Enable uniffi scaffolding when the "uniffi" feature is enabled.
4+
#[cfg(feature = "uniffi")]
5+
uniffi::setup_scaffolding!();
6+
37
mod auth_client;
48

59
pub mod identity;

crates/bitwarden-auth/src/send_access/access_token_response.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::send_access::api::{SendAccessTokenApiErrorResponse, SendAccessTokenAp
1010
derive(tsify::Tsify),
1111
tsify(into_wasm_abi, from_wasm_abi)
1212
)]
13+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
1314
#[derive(Debug)]
1415
pub struct SendAccessTokenResponse {
1516
/// The actual token string.
@@ -73,3 +74,7 @@ impl From<reqwest::Error> for SendAccessTokenError {
7374
tsify(into_wasm_abi, from_wasm_abi)
7475
)]
7576
pub struct UnexpectedIdentityError(pub String);
77+
78+
// Newtype wrapper for unexpected identity errors for uniffi compatibility.
79+
#[cfg(feature = "uniffi")] // only compile this when uniffi feature is enabled
80+
uniffi::custom_newtype!(UnexpectedIdentityError, String);

crates/bitwarden-auth/src/send_access/api/token_api_error_response.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use tsify::Tsify;
44

55
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
66
#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
7+
#[cfg_attr(feature = "uniffi", derive(uniffi::Error))]
78
#[serde(rename_all = "snake_case")]
89
/// Invalid request errors - typically due to missing parameters.
910
pub enum SendAccessTokenInvalidRequestError {
@@ -26,6 +27,7 @@ pub enum SendAccessTokenInvalidRequestError {
2627

2728
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
2829
#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
30+
#[cfg_attr(feature = "uniffi", derive(uniffi::Error))]
2931
#[serde(rename_all = "snake_case")]
3032
/// Invalid grant errors - typically due to invalid credentials.
3133
pub enum SendAccessTokenInvalidGrantError {
@@ -51,6 +53,7 @@ pub enum SendAccessTokenInvalidGrantError {
5153

5254
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
5355
#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
56+
#[cfg_attr(feature = "uniffi", derive(uniffi::Error))]
5457
#[serde(rename_all = "snake_case")]
5558
#[serde(tag = "error")]
5659
// ^ "error" becomes the variant discriminator which matches against the rename annotations;

crates/bitwarden-auth/uniffi.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[bindings.kotlin]
2+
package_name = "com.bitwarden.auth"
3+
generate_immutable_records = true
4+
android = true
5+
6+
[bindings.swift]
7+
ffi_module_name = "BitwardenAuthFFI"
8+
module_name = "BitwardenAuth"
9+
generate_immutable_records = true

0 commit comments

Comments
 (0)