Skip to content
Draft
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
85 changes: 83 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ reqwest = { version = ">=0.12.5, <0.13", features = [
"multipart",
"http2",
], default-features = false }
reqwest-middleware = { version = ">=0.4.2, <0.5", features = [
"json",
"multipart",
] }
schemars = { version = ">=1.0.0, <2.0", features = ["uuid1", "chrono04"] }
serde = { version = ">=1.0, <2.0", features = ["derive"] }
serde_bytes = { version = ">=0.11.17, <0.12.0" }
Expand Down
1 change: 1 addition & 0 deletions crates/bitwarden-api-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mockall = ["dep:mockall"]
async-trait = { workspace = true }
mockall = { version = ">=0.13.1, <0.14", optional = true }
reqwest = { workspace = true }
reqwest-middleware = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_repr = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/bitwarden-api-api/src/apis/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
pub struct Configuration {
pub base_path: String,
pub user_agent: Option<String>,
pub client: reqwest::Client,
pub client: reqwest_middleware::ClientWithMiddleware,
pub basic_auth: Option<BasicAuth>,
pub oauth_access_token: Option<String>,
pub bearer_access_token: Option<String>,
Expand All @@ -38,7 +38,7 @@ impl Default for Configuration {
Configuration {
base_path: "https://api.bitwarden.com".to_owned(),
user_agent: Some("OpenAPI-Generator/latest/rust".to_owned()),
client: reqwest::Client::new(),
client: reqwest_middleware::ClientBuilder::new(reqwest::Client::new()).build(),
basic_auth: None,
oauth_access_token: None,
bearer_access_token: None,
Expand Down
9 changes: 9 additions & 0 deletions crates/bitwarden-api-api/src/apis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct ResponseContent<T> {
#[derive(Debug)]
pub enum Error<T> {
Reqwest(reqwest::Error),
ReqwestMiddleware(reqwest_middleware::Error),
Serde(serde_json::Error),
Io(std::io::Error),
ResponseError(ResponseContent<T>),
Expand All @@ -19,6 +20,7 @@ impl<T> fmt::Display for Error<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (module, e) = match self {
Error::Reqwest(e) => ("reqwest", e.to_string()),
Error::ReqwestMiddleware(e) => ("reqwest-middleware", e.to_string()),
Error::Serde(e) => ("serde", e.to_string()),
Error::Io(e) => ("IO", e.to_string()),
Error::ResponseError(e) => ("response", format!("status code {}", e.status)),
Expand All @@ -31,6 +33,7 @@ impl<T: fmt::Debug> error::Error for Error<T> {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
Some(match self {
Error::Reqwest(e) => e,
Error::ReqwestMiddleware(e) => e,
Error::Serde(e) => e,
Error::Io(e) => e,
Error::ResponseError(_) => return None,
Expand All @@ -44,6 +47,12 @@ impl<T> From<reqwest::Error> for Error<T> {
}
}

impl<T> From<reqwest_middleware::Error> for Error<T> {
fn from(e: reqwest_middleware::Error) -> Self {
Error::ReqwestMiddleware(e)
}
}

impl<T> From<serde_json::Error> for Error<T> {
fn from(e: serde_json::Error) -> Self {
Error::Serde(e)
Expand Down
1 change: 1 addition & 0 deletions crates/bitwarden-api-identity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mockall = ["dep:mockall"]
async-trait = { workspace = true }
mockall = { version = ">=0.13.1, <0.14", optional = true }
reqwest = { workspace = true }
reqwest-middleware = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_repr = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/bitwarden-api-identity/src/apis/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
pub struct Configuration {
pub base_path: String,
pub user_agent: Option<String>,
pub client: reqwest::Client,
pub client: reqwest_middleware::ClientWithMiddleware,
pub basic_auth: Option<BasicAuth>,
pub oauth_access_token: Option<String>,
pub bearer_access_token: Option<String>,
Expand All @@ -38,7 +38,7 @@ impl Default for Configuration {
Configuration {
base_path: "https://identity.bitwarden.com".to_owned(),
user_agent: Some("OpenAPI-Generator/v1/rust".to_owned()),
client: reqwest::Client::new(),
client: reqwest_middleware::ClientBuilder::new(reqwest::Client::new()).build(),
basic_auth: None,
oauth_access_token: None,
bearer_access_token: None,
Expand Down
9 changes: 9 additions & 0 deletions crates/bitwarden-api-identity/src/apis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct ResponseContent<T> {
#[derive(Debug)]
pub enum Error<T> {
Reqwest(reqwest::Error),
ReqwestMiddleware(reqwest_middleware::Error),
Serde(serde_json::Error),
Io(std::io::Error),
ResponseError(ResponseContent<T>),
Expand All @@ -19,6 +20,7 @@ impl<T> fmt::Display for Error<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (module, e) = match self {
Error::Reqwest(e) => ("reqwest", e.to_string()),
Error::ReqwestMiddleware(e) => ("reqwest-middleware", e.to_string()),
Error::Serde(e) => ("serde", e.to_string()),
Error::Io(e) => ("IO", e.to_string()),
Error::ResponseError(e) => ("response", format!("status code {}", e.status)),
Expand All @@ -31,6 +33,7 @@ impl<T: fmt::Debug> error::Error for Error<T> {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
Some(match self {
Error::Reqwest(e) => e,
Error::ReqwestMiddleware(e) => e,
Error::Serde(e) => e,
Error::Io(e) => e,
Error::ResponseError(_) => return None,
Expand All @@ -44,6 +47,12 @@ impl<T> From<reqwest::Error> for Error<T> {
}
}

impl<T> From<reqwest_middleware::Error> for Error<T> {
fn from(e: reqwest_middleware::Error) -> Self {
Error::ReqwestMiddleware(e)
}
}

impl<T> From<serde_json::Error> for Error<T> {
fn from(e: serde_json::Error) -> Self {
Error::Serde(e)
Expand Down
1 change: 1 addition & 0 deletions crates/bitwarden-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ bitwarden-core = { workspace = true, features = ["internal"] }
bitwarden-error = { workspace = true }
chrono = { workspace = true }
reqwest = { workspace = true }
reqwest-middleware = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
tsify = { workspace = true, optional = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ pub enum SendAccessTokenError {
}

// This is just a utility function so that the ? operator works correctly without manual mapping
impl From<reqwest_middleware::Error> for SendAccessTokenError {
fn from(value: reqwest_middleware::Error) -> Self {
Self::Unexpected(UnexpectedIdentityError(format!("{value:?}")))
}
}

impl From<reqwest::Error> for SendAccessTokenError {
fn from(value: reqwest::Error) -> Self {
Self::Unexpected(UnexpectedIdentityError(format!("{value:?}")))
Expand Down
4 changes: 2 additions & 2 deletions crates/bitwarden-auth/src/send_access/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl SendAccessClient {
&configurations.identity_config.base_path
);

let request: reqwest::RequestBuilder = configurations
let request = configurations
.identity_config
.client
.post(&url)
Expand All @@ -60,7 +60,7 @@ impl SendAccessClient {
// wrapped in SendAccessTokenError::Unexpected as an UnexpectedIdentityError::Reqwest
// variant and returned.
// note: we had to manually built a trait to map reqwest::Error to SendAccessTokenError.
let response: reqwest::Response = request.send().await?;
let response = request.send().await?;

let response_status = response.status();

Expand Down
5 changes: 5 additions & 0 deletions crates/bitwarden-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,21 @@ bitwarden-uuid = { workspace = true }
chrono = { workspace = true, features = ["std"] }
# We don't use this directly (it's used by rand), but we need it here to enable WASM support
getrandom = { version = ">=0.2.9, <0.3", features = ["js"] }
http = "1.3.1"
log = { workspace = true }
rand = ">=0.8.5, <0.9"
reqwest = { workspace = true }
reqwest-middleware = { workspace = true }
reqwest-tracing = ">=0.5.8, <0.6"
schemars = { workspace = true }
serde = { workspace = true }
serde_bytes = { workspace = true }
serde_json = { workspace = true }
serde_qs = { workspace = true }
serde_repr = { workspace = true }
thiserror = { workspace = true }
tracing = "0.1.41"
tracing-subscriber = { version = "0.3.20", features = ["fmt"] }
tsify = { workspace = true, optional = true }
uniffi = { workspace = true, optional = true, features = ["tokio"] }
uuid = { workspace = true }
Expand Down
Loading
Loading