From fa1379cf3ff5d699b59d1c5c50faf650a1c47958 Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko <12615679+Br1ght0ne@users.noreply.github.com> Date: Fri, 4 Oct 2024 19:20:23 +0100 Subject: [PATCH] [v0.36.0] fix: Manually encode Authorization header for eventsource_client (#2285) ## Linked Issues/PRs Copy of #2284 (targets `master`) ## Description See #2284. --------- Co-authored-by: Green Baneling --- Cargo.lock | 5 +++-- crates/client/Cargo.toml | 5 +++-- crates/client/src/client.rs | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 64bfe865ebf..2a82255adb2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2984,9 +2984,9 @@ dependencies = [ [[package]] name = "eventsource-client" -version = "0.12.2" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c80c6714d1a380314fcb11a22eeff022e1e1c9642f0bb54e15dc9cb29f37b29" +checksum = "43ddc25e1ad2cc0106d5e2d967397b4fb2068a66677ee9b0eea4600e5cfe8fb4" dependencies = [ "futures", "hyper", @@ -3314,6 +3314,7 @@ name = "fuel-core-client" version = "0.36.0" dependencies = [ "anyhow", + "base64 0.22.1", "cynic", "derive_more", "eventsource-client", diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml index 52a45dd62c3..ad8f7d48078 100644 --- a/crates/client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -12,9 +12,10 @@ description = "Tx client and schema specification." [dependencies] anyhow = { workspace = true } +base64 = { version = "0.22.1", optional = true } cynic = { workspace = true } derive_more = { workspace = true } -eventsource-client = { version = "0.12.2", optional = true } +eventsource-client = { version = "0.13.0", optional = true } fuel-core-types = { workspace = true, features = ["alloc", "serde"] } futures = { workspace = true, optional = true } hex = { workspace = true } @@ -46,4 +47,4 @@ serde_json = { version = "1.0", features = ["raw_value"] } std = ["fuel-core-types/std"] default = ["subscriptions", "std"] test-helpers = [] -subscriptions = ["eventsource-client", "futures", "hyper-rustls"] +subscriptions = ["base64", "eventsource-client", "futures", "hyper-rustls"] diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 512bac9e5ce..dfe61d865fe 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -29,6 +29,11 @@ use crate::client::{ }; use anyhow::Context; #[cfg(feature = "subscriptions")] +use base64::prelude::{ + Engine as _, + BASE64_STANDARD, +}; +#[cfg(feature = "subscriptions")] use cynic::StreamingOperation; use cynic::{ http::ReqwestExt, @@ -270,6 +275,19 @@ impl FuelClient { format!("Failed to add header to client {e:?}"), ) })?; + if let Some(password) = url.password() { + let username = url.username(); + let credentials = format!("{}:{}", username, password); + let authorization = format!("Basic {}", BASE64_STANDARD.encode(credentials)); + client_builder = client_builder + .header("Authorization", &authorization) + .map_err(|e| { + io::Error::new( + io::ErrorKind::Other, + format!("Failed to add header to client {e:?}"), + ) + })?; + } if let Some(value) = self.cookie.deref().cookies(&self.url) { let value = value.to_str().map_err(|e| {