Skip to content

Commit 8eb4e7f

Browse files
committed
Allow using an arbitrary value for the Authorization header
1 parent 48a2d84 commit 8eb4e7f

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

elasticsearch/src/auth.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pub enum Credentials {
3535
ApiKey(String, String),
3636
/// An API key as a base64-encoded id and secret
3737
EncodedApiKey(String),
38+
/// An arbitrary value for the Authorization header
39+
AuthorizationHeader(String),
3840
}
3941

4042
#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]

elasticsearch/src/http/transport.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,9 @@ impl Transport {
543543
header_value.set_sensitive(true);
544544
request_builder.header(AUTHORIZATION, header_value)
545545
}
546+
Credentials::AuthorizationHeader(header) => {
547+
request_builder.header(AUTHORIZATION, header.clone())
548+
}
546549
}
547550
}
548551
drop(creds_guard);

elasticsearch/tests/auth.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@ async fn bearer_header() -> anyhow::Result<()> {
116116
Ok(())
117117
}
118118

119+
#[tokio::test]
120+
async fn arbitrary_auth_header() -> anyhow::Result<()> {
121+
let server = server::http(move |req| async move {
122+
assert_eq!(req.headers()["authorization"], "Foo bar baz");
123+
http::Response::default()
124+
});
125+
126+
let builder = client::create_builder(format!("http://{}", server.addr()).as_ref())
127+
.auth(Credentials::AuthorizationHeader("Foo bar baz".into()));
128+
129+
let client = client::create(builder);
130+
let _response = client.ping().send().await?;
131+
132+
Ok(())
133+
}
134+
119135
// TODO: test PKI authentication. Could configure a HttpsConnector, maybe using https://github.com/sfackler/hyper-openssl?, or send to PKI configured Elasticsearch.
120136
//#[tokio::test]
121137
//async fn client_certificate() -> anyhow::Result<()> {

0 commit comments

Comments
 (0)