Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/bitwarden-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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]
Expand All @@ -31,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 }

Expand Down
4 changes: 4 additions & 0 deletions crates/bitwarden-auth/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -73,3 +74,7 @@ impl From<reqwest::Error> 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);
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions crates/bitwarden-auth/uniffi.toml
Original file line number Diff line number Diff line change
@@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing trailing newline: This file should end with a newline character to match repository conventions. Most editors add this automatically, and it's a common git best practice.

Loading